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-table-responsive-sb

v0.1.2

Published

React Table Responsive is a library that provides a responsive table with pagination, search, and filter functionality.

Downloads

8

Readme

React Table Component

This is an npm package for creating tables in any React web application. With this package, you can create tables with pagination, sorting, and multi level filters. It's an lightweight and easy to use package with responsive design.

Check out the demo page for a live example.

Installation

npm install react-table-responsive-sb

Usage

import { ChakraTable } from "react-table-responsive-sb";

const sampleProps = {
  loading: false,
  error: null,
  rowData: [
    { id: 1, name: 'John Doe', age: 28 },
    { id: 2, name: 'Jane Smith', age: 34 },
  ],
  sortable: true,
  caption: 'Sample Table',
  pagination: true,
  rowsPerPage: 5,
  paginationLength: 3,
  filterRowsByColumnGroup: [
    { column: 'name', values: ['John Doe', 'Jane Smith'] },
  ],
  columnsData: [
    { label: 'id', name: 'ID' },
    { label: 'name', name: 'Name' },
    { label: 'age', name: 'Age' },
  ],
  tableParentClass: 'custom-parent-class',
  tableChildClass: 'custom-child-class',
  disableDefaultScrollStyle: false,
};

const App = () => (
    <ChakraTable {...sampleProps} />
);

export default App;

Props

  • loading: Boolean - Default: false. Shows a loading spinner when true.
  • error: any - Error object to display if there's an error.
  • rowData: Array - Array of objects representing the rows data.
  • sortable: Boolean - Default: false. Enables sorting of columns by clicking the column name.
  • caption: String - Header for the table. Displays search, total rows, total filtered rows, and filter.
  • pagination: Boolean - Default: false. Enables pagination.
  • rowsPerPage: Number - Default: 6. Number of rows per page when pagination is enabled.
  • paginationLength: Number - Default: 5. Sets the limit for pagination numbers range.
  • filterRowsByColumnGroup: Array - Array of objects for filtering rows by column group.
  • columnsData: Array - Array of objects representing the columns data.
  • tableParentClass: String - Custom class for the table parent.
  • tableChildClass: String - Custom class for the table child.
  • disableDefaultScrollStyle: Boolean - Default: false. Disables default scroll style.

Feature List / Optional Props

sortable: Boolean, To sort columns by ascending or descending when clicking the column name. This won't work for cell renderer components inside a column. Only for string and numbers

caption: String, This is the header props for the table, default behaviour has no header so headers are visible only when a caption is provided. It displays search, total rows, total filtered rows and filter.

Search Bar: Default disabled. Search will be enabled once captions are provided so its default behaviour depends on captions that enable headers.

pagination: Boolean, Default: Pagination is turned off by default so this prop is required if you want to enable the pagination.

defaultRowsPerPage: Number, By default the rows per page is enabled when pagination is enabled. Default rows per page are 6 if no value is provided.

defaultPaginationLength: Number, these set the limit for pagination numbers range for example a value of 5 will limit displaying 1-5 with next and previous buttons to jump to 6-10 and thus by it goes on till the rows end. The default pagination length is 5 if no value is provided.

filterRowsByColumnGroup: Array of Objects.

Format: [ { column: 'name of column 1', values: [ 'filter list of this column 1', 'multi filters for same columns' ] }, { column: 'name of column 2', values: [ 'filter list of this column 2', 'multi filters for same columns' ] } ].

The default behaviour of filters is disabled if filterRowsByColumnGroup is not provided.

Example: filterRowsByColumnGroup={[{ column: 'status', values: ['failed', 'waiting', 'paid'] }, { column: 'name', values: ['Sai Barath', 'Lokesh'] }, { column: 'purchaseId', values: ['25602'] }]}

row: Arrays of Objects, Rows Data. Format: [ { columnName: value }, { columnName: value }, { columnName: value } ] .

headers: Arrays of Objects, List of columns;

Format: [ { label: 'API name or local name', name: 'display name for header', cellRenderer: <react component>, optional, use only if you need to add components in row }, { label: 'API name or local name', name: 'display name for header'} ]

cellRenderer: React Component, the Default behaviour is to render a normal row value but if cellRenderer is provided then a callback function will return an array with array[0]: column name & array[1]: row value. For every single row, this cellRenderer will be called with new row values to give options to render different options based on row values instead of the same component.

Example

const columnsData = useMemo(() => [
  { label: 'timeStamp', name: 'TimeStamp' },
  { label: 'status', name: 'Status', cellRenderer: StatusRenderer }
], []);

function StatusRenderer(value) {
  const backgroundColor = value[1] === 'failed' ? 'bg-red-200' : value[1] === 'waiting' ? 'bg-yellow-100' : 'bg-green-200';
  return <div className={`flex items-center p-1 capitalize text-gray-800 font-medium text-sm rounded-lg justify-center min-w-[60px] ${backgroundColor}`}>{value[1]}</div>;
}

Sample Table Pics

Sample Table

Filter Pics

Filter Example

Search Pics

Search Example

Advanced Version: Check out the advanced version using React with Ag-grid library