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 🙏

© 2026 – Pkg Stats / Ryan Hefner

table-factory

v0.0.12

Published

An easy to use table factory for React

Downloads

47

Readme

Table Factory

An easy to use table factory for React.

How to install

npm install table-factory

How to use?

A quick example:

const rows = [
  {id: 1, name: 'Foo', age: 34},
  {id: 2, name: 'Bar', age: 1337}
]

<TableFactory
  id='id'
  columns={{
    id: '#',
    name: 'Name',
    age: 'Age'
  }}
  data={rows}
/>

More examples can be found in examples.

API

Props

All props except data are optional. But when no columns prop is given the alternative columns specification should be given.

<TableFactory
  onRowClick={(event, row) => void} // when <tr> inside the <tbody> is clicked
  header={bool} // show thead yes or not
  id={string} // use this property of the data for the React key for the <tr>'s
  columns={objectOrArray} // specify columns
  elemProps={object} // specify elem specific props (e.g. a class for a <tr>)
  data={array} // list of row objects
/>

columns

The columns prop is either an array of column objects (with a name prop) or an object where the key is the name of the column, and the value the column object. In the second case it's also possible to specify a string as the column object, which will be translated to column object with the title set.

An example:

const columnsArray = [
  {name: 'id', title: '#'},
  {name: 'name': title: 'Name'}
]
const columnsObject = {
  id: '#',
  name: {title: 'Name'}
}

For each column the following props are supported:

| Prop | Description | | --- | --- | | name | column name | | title | column title | | props | props that should be applied on the <th> and the <td> of the column | | thProps | props that should be applied on the <th> of the column | | tdProps | props that should be applied on the <td> of the column | | render | a function to render the contents of the <td>, when discarded the value for 'name' of the row will be used |

The render function has the following signature: (row, col, index, data, columns) => any.

elemProps

The prop elemProps is an object where the keys are either: 'table', 'thead', 'tbody', 'tr', 'th' or 'td'. The values are either objects which specify the props of the element or a callback function which should return an object. The arguments for the callback function vary per element type. The signatures are as following:

| Element type | Arguments | | --- | --- | | table | array data, object columns | | thead | array data, object columns | | tbody | array data, object columns | | tr | bool header, object|null row, int index, array data, object columns | | th | object column, array data, object columns | | td | object column, object row, int index, array data, object columns |

Alternative Columns Specification

It's also possible to specify columns using <th> children. Every sub <th> inside the <TableFactory> should have at least the prop name. This will be the name of the column. All other props on the element will be used like the props in the columns prop. The contents of the <th> will be title.

An example:

<TableFactory id='id' data={rows}>
  <th name='id'>#</th>
  <th name='name'>Name</th>
  <th name='age' props={{
    style: {textAlign: 'right'} // Align both the <th> and the <td> to the right
  }}>Age</th>
</TableFactory>

This sub element syntax can also be used for specifying elemProps like this:

<TableFactory id='id' data={rows} className='table'>
  {/* Specify elem props */}
  <thead className='table__head' />
  <tbody className='table__body' />
  <tr className='table__row' />
  <td className='table__cell' />
  <th className='table__cell table__cell--head' />

  {/* <th>'s with the name prop are ignored as elemProp */}
  <th name='id'>#</th>
  <th name='name'>Name</th>
  <th name='age'>Age</th>
</TableFactory>

Because <tr>'s are used in both <thead>'s and <tbody>'s it's possible to specify props for just the <thead> of the <tbody> situations by nesting them like this:

<TableFactory id='id' data={rows} className='table'>
  {/* Specify thead specific <tr> class */}
  <thead className='table__head'>
    <tr className='table__row--head' />
  </thead>

  {/* Specify tbody specific <tr> class */}
  <tbody className='table__body'>
    <tr className='table__row--body' />
  </tbody>

  {/* Specify base <tr> class for both cases */}
  <tr className='table__row' />

  { ... }
</TableFactory>