npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

magic-react-table

v1.0.1

Published

This is a simple React table component that allows sorting and styling of the header and body.

Readme

This project was bootstrapped with Create React App.

Magic React Table v1.0

Magic React Table is a React Table component that makes tables easy - style it, sort it, search it, and more!

Installing Magic React Table

To install Magic React Table, just use npm install magic-react-table --save in the root of your project.

To use it in your React project, import the Table component into a functional or class React component like so:

import Table from 'magic-react-table'

Using The Table Component

To instantiate a Magic React Table Component, call the Table component like any other React component, including any of the props available (see the Magic React Table Props section below for more on the props available):

<Talbe data={staffData} />

Magic React Table Props

When using the Table component, there are a few props that can be used:

| Prop | Type | Required | Description | | :---: | :---: | :---: | :---: | | data | Array of Objects | Yes |An array of objects pertaining to the data you wish to be displayed in the table. | headers | Array of Strings | No | An array of strings to specify custom column headers for the table. (default column headers are the object keys in the data passed via the data prop). The number of headers in the array must match the number of key/value pairs in the data objects of the array passed to the data prop. | addClasses | Array of Strings | No | An array of strings to specify any classes to be added to the Table wrapper div. | options | Object | No | An object with two nested objects (specified by a header and body key) that specifies various styling options within your table.

All examples in this documentation will use the following staffData array for the data prop:

let staffData = [
    {
        "name": "Kathy",
        "title": "Technician, Int",
        "service date": 2005,
        "salary": "$67,000",
        "phone": "888-555-1297"
    },
    {
        "name": "Robert",
        "title": "Supervisor",
        "service date": 2018,
        "salary": "$78,000",
        "phone": "888-555-9913"
    },
    {
        "name": "William",
        "title": "Technician, Jr",
        "service date": 2007,
        "salary": "$55,000",
        "phone": "888-555-5612"
    },
    {
        "name": "Samantha",
        "title": "Accountant",
        "service date": 2011,
        "salary": "$61,000",
        "phone": "888-555-5612"
    }
];

Using The Props

data

The data prop is required for the Table component which must be passed an array of objects, like the staffData array of objects above. Because the keys in the first object are used as the default headers for the table, the key/value pairs must have the same type of data in the same place in each object. As you can see in the staffData array, each object has a 'name' key as key one, 'title' as key two, 'service date' key as key three, and so on...

Example of a basic Table component:

<Table data={staffData} /> Table without headers prop *Some styling applied to headers for readability

headers

To forgo using the default headers, specified by the keys of the objects provided to the data prop, pass an array (of strings) of new headers to the headers prop. This will replace each respective column header based on its position in the array, like so:

let newHeaders = ['column1', 'column2', 'column3', 'column4', 'column5']

In the example array newHeaders, the string column1 would replace the header in the first column of the table, the string column2 would replace the header in the second column of the table, and so on... Please be aware that if the length of the array passed to the header prop does not equal the number of keys in each object within the array passed to the data prop, the header prop will be ignored and the default headers will be used.

Example of Table component with headers:
const customHeaders = ['Column1', 'Column2', 'Column3', 'Column4', 'Column5'];

<Table data={staffData} headers={customHeaders} />

Table with headers prop *Some styling applied to headers for readability

addClasses

The addClasses prop allows you to add classes to the table's container div by passing in an array of strings that will be added as class names.

Example of Table component with addClasses:
const tableClasses = ['table1', 'staff_table'];

<Table data={staffData} addClasses={tableClasses} /> 

Table with addClasses prop *Some styling applied to headers for readability

options

The options prop allows you to add various pre-defined styling options (discussed in detail below) or append various standard CSS styling to rows, columns, or cells as specified in the options object.

The two keys in the options variable passed to the porp must be header and body, and must both be objects themselves:

const baseOptions = {
    header: {},
    body: {},
};

As implied, the header object specifies options to be applied to the header of the table, while the body object specifies options to be applied to the body. Below we will take a look at each respective child object (header and body); their built-in options, as well as how to apply styling to the table through them.

####header object: The header object has a few built-in options that allow the control of some styling functionality within the header of the table, as well as a styles object that takes a targeted approach to applying CSS styling:

| Key | Type | Default Value | Description | | :---: | :---: | :---: | :---: | | initialSortBy | String | n/a | Pass the value of the column header to be sorted by initially. If the initialSortOrder prop is not specified, the designated column will be sorted in ascending order. | | initialSortOrder | String | asc | This must either be asc for ascending order or desc for descending order. | | sortable | Boolean | false | If sortable is true, the column headers will become sortable on click - clicking on a column header that is not sorted will sort it in ascending order. Clicking a column that is sorted in ascending order will resort the column in descending order. Clicking on a column that is sorted in descending order will resort the column in ascending order. | | capitalize | Boolean | false | If capitalize is true, each word of all headers in the table will be capitalized. | | styles | Object | { } | Use defined designators as keys to target header areas, and an object as the value with CSS styling key/value pairs. Valid header key designators are: row, col-all, col-even, col-odd, and col# (ie. - col4) |

Example of using header option:
const tableOptions = {
    header: {
        sortable: true,
        initialSortBy: 'name',
        initialSortOrder: 'desc',
        capitalize: true,
        styles: {
            row: {
                border: '5px solid #0dddc2',
            },
            'col-all': {
                fontWeight: 'bold',
                border: '2px dashed #000',
            },
            'col-odd': {
                backgroundColor: '#5c56ff',
                color: '#fff',
                paddingLeft: '10px',
            },
            'col-even': {
                backgroundColor: '#fc9494',
                textAlign: 'center',
            },
            col2: {
                color: '#00ff00',
            },
        },
    },
    body: {},
};

<Table data={staffData} options={tableOptions} />

Table with addClasses prop

####body object: The body object has a few built-in options that allow the control of some styling functionality within the body of the table, as well as a styles object that takes a targeted approach to applying CSS styling:

| Key | Type | Default Value | Description | | :---: | :---: | :---: | :---: | | zebra | Boolean | false | If zebra is set to true, the background color, set to #e7e7e7 by default but can be explicitly specified using the zebraColor body option, of even or odd rows' , specified by the zebraStart body option, are changed.| | zebraStart | String | odd | zebraStart specifies which rows the zebra background color will be applied to: even or odd. | | zebraColor | String | #e7e7e7 | zebraColor specifies the color that the zebra background. | | styles | Object | { } | Use defined designators as keys to target body areas, and an object as the value with CSS styling key/value pairs. Valid body key designators are: row-all, row-even, row-odd, row# (ie. - row4),col-even, col-odd, col# (ie. - col4), and cell# (ie. - cell4) |

Example of using body option:
const tableOptions = {
    header: {
        styles: {
            'col-all': {
                fontWeight: 'bold',
            },
        },
    },
    body: {
        zebra: true,
        zebraStart: 'odd',
        zebraColor: '#2b87ff',
        styles: {
            'row-all': {
                borderTop: '2px solid #b703c4',
                borderBottom: '2px solid #b703c4',
            },
            'row-even': {
                color: '#ff0000',
            },
            'row-odd': {
                color: '#00ff00',
            },
            'col-all': {
                padding: '10px 0px',
            },
            'col-even': {
                textDecoration: 'overline',
            },
            'col-odd': {
                textDecoration: 'underline',
            },
            col4: {
                border: '2px dashed #363636',
            },
            cell6: {
                backgroundColor: 'orange',
            },
        },
    },
};

<Table data={staffData} options={tableOptions} />

Table with addClasses prop *Some styling applied to headers for readability