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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-clean-table

v1.0.4

Published

Clean, easy customizable table component for React.

Downloads

3

Readme

react-clean-table

Travis npm package Coveralls David

react-clean-table is an easy to configure, full customizable table component for React.

Installation

Using NPM

npm install react-clean-table --save

Using Yarn

yarn add react-clean-table

Using CDN

If you don't use any module bundler then you can just import react-clean-table to your project via <script> tag. You can use it as ReactCleanTable on your javascript.

<script src="https://unpkg.com/react-clean-table/umd/react-clean-table.min.js"></script>

Quick Example

Simple usage of react-clean-table is like this:

import React from 'react';
import { Table, Column } from 'react-clean-table';

const data = [
  {
    id: 1,
    firstName: 'Tillman',
    lastName: 'Franklin',
    company: 'Quarx',
    username: 'tillmanfranklin',
    email: '[email protected]'
  },
  {
    id: 2,
    firstName: 'Maritza',
    lastName: 'Gamble',
    company: 'Rooforia',
    username: 'maritzagamble',
    email: '[email protected]'
  }
];

const FullNameCell = ({ data }) => <span>{data[0]} {data[1]}</span>;
const EmailCell = ({ data }) => <a href={`mailto:${data}`}>{data}</a>;

const Demo = () => (
  <Table
    className="table"
    data={data}
  >
    <Column
      header="ID"
      field="id"
    />
    <Column
      header="Person"
      size="30%"
      field={['firstName', 'lastName']}
      cell={<FullNameCell />}
    />
    <Column
      header="E-mail"
      field="email"
      cell={<EmailCell />}
    />
    <Column
      header="Company"
      field="company"
    />
  </Table>
);

export default Demo;

Usage

Styling

react-clean-table has no styling dependency. Therefore, if you need customize table styling then you can use className props for each element.

<Table
  data={data}
  className="table table-primary"
  theadClassName=""
  tbodyClassName=""
  trClassName=""
  tdClassName=""
  thClassName=""
/>
  {/* columns */}
</Table>

Table Data

You have to pass an array of objects to <Table /> component to make it work. These objects can be nested and have any data type.

const data = [
  {
    key1: 'value 1',
    key2: [1, 2, 3],
    key3: {
    	key4: true,
      key5: {
        key6: 'value 2'
      }
    }
  }
];

<Table data={data}>
	{/* columns */}
</Table>

Columns

You have to specify each column that you want to show with <Column /> component. For example, you can create a table for this data like this:

const data = [
  {
    id: 1,
    firstName: 'Alpcan',
    lastName: 'Aydın',
    email: '[email protected]'
  }
];
<Table data={data} />
  <Column
    header="ID"
    field="id"
  />
  <Column
    header="First Name"
    field="firstName"
  />
  <Column
    header="Last Name"
    field="lastName"
  />
  <Column
    header="Email"
    field="email"
  />
</Table>

All column cells are customizable with components. For examle let's pass a custom <EmailCell /> to email column.

const EmailCell = ({ data }) => <a href={`mailto:${data}`}>{data}</a>;

<Table data={data} />
  <Column
    header="ID"
    field="id"
  />
  <Column
    header="First Name"
    field="firstName"
  />
  <Column
    header="Last Name"
    field="lastName"
  />
  <Column
    header="Email"
    field="email"
    cell={<EmailCell />}
  />
</Table>

You can also pass props to your custom cell component.

const EmailCell = ({ data, showAs }) => <a href={`mailto:${data}`}>{showAs}</a>;

<Table data={data} />
  <Column
    header="ID"
    field="id"
  />
  <Column
    header="First Name"
    field="firstName"
  />
  <Column
    header="Last Name"
    field="lastName"
  />
  <Column
    header="Email"
    field="email"
    cell={<EmailCell showAs="E-mail" />}
  />
</Table>

What if you want to use multiple field from your data in a cell? No problem, just assign an array to field prop.

const EmailCell = ({ data, showAs }) => <a href={`mailto:${data}`}>{showAs}</a>;

const FullNameCell = ({ data }) => <span>{data[0]} {data[1]}</span>;

<Table data={data} />
  <Column
    header="ID"
    field="id"
  />
  <Column
    header="Full Name"
    field={['firstName', 'lastName']}
    cell={<FullNameCell />}
  />
  <Column
    header="Email"
    field="email"
    cell={<EmailCell showAs="E-mail" />}
  />
</Table>

Column Styling

If you want to add a className to speficied <Column /> you can also use tdClassName prop in <Column /> components. Both tdClassName props will be merged.

const EmailCell = ({ data, showAs }) => <a href={`mailto:${data}`}>{showAs}</a>;

const FullNameCell = ({ data }) => <span>{data[0]} {data[1]}</span>;

<Table
  data={data}
  tdClassName="generic-td-class"
/>
  <Column
    header="ID"
    field="id"
    tdClassName="speficied-td-class"
  />
  <Column
    header="Full Name"
    field={['firstName', 'lastName']}
    cell={<FullNameCell />}
  />
  <Column
    header="Email"
    field="email"
    cell={<EmailCell showAs="E-mail" />}
  />
</Table>

/*
Output for ID td:
<td class="generic-td-class speficied-td-class">cell</td>
*/

Data Accessing

You can use dot notation in order to access to spesific data.

const data = [
  {
    key1: 'value 1',
    key2: ['x', 'y', 'z'],
    key3: {
    	key4: true,
        key5: {
        	key6: 'value 2',
            key7: ['a', 'b', 'c']
        }
    }
  }
];

const field = 'key1';
// or
const field = 'key2.2';
// or
const field = 'key3.key5.key6';
// or
const field = 'key3.key5.key7.1';

<Table data={data}>
  <Column
  	header="Simple Header"
    field={field}
  />
</Table>

Column Size

If you want to specify a column size then you can use size prop in your <Column /> components.

const data = [
  {
    id: 1,
    firstName: 'Alpcan',
    lastName: 'Aydın',
    email: '[email protected]'
  }
];
<Table data={data} />
  <Column
    header="ID"
    field="id"
    size={10}
  />
  <Column
    header="First Name"
    field="firstName"
    size="100px"
  />
  <Column
    header="Last Name"
    field="lastName"
    size="50"
  />
  <Column
    header="Email"
    field="email"
    size="45%"
  />
</Table>

Contributing

To suggest a feature, please open an issue if does not already exist. If you want to develop some feature please follow these steps:

  • Fork this repo.
  • Make sure yarn installed in your computer.
  • Implement your feature. (you can use yarn start command to have hot-reload enabled dev server.)
  • Check your code via yarn run lint
  • Add tests to cover your code.
  • Run all tests to ensure that they pass via yarn run test
  • Check code coverage via yarn run test:coverage
  • Send a pull request to this repo.