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-temp

v0.0.1

Published

A fast, lightweight, opinionated table and datagrid built on React

Downloads

4

Readme

react-table

A fast, lightweight, opinionated table and datagrid built on React

Chart.js on Slack

Features

  • Lightweight at 3kb (and just 2kb more for styles)
  • No composition needed
  • Uses customizable JSX and callbacks for everything
  • Client-side pagination and sorting
  • Server-side support
  • Minimal design & easily themeable

Why you may not want to use this component:

  • No support for infinite scrolling. We chose to avoid the complex problems that come with it, and instead provide reliable and predictable pagination.
  • You need tables built in something other than traditional HTML table elements.

Installation

$ npm install react-table

Styles

React-table is built to be dropped into existing applications or styled from the ground up, but if you'd like a decent starting point, you can optionally include our default theme react-table.css. We think it looks great, honestly :)

Quick Usage

import ReactTable from 'react-table'

const data = [{
  name: 'Tanner Linsley',
  age: 26,
  friend: {
    name: 'Jason Maurer',
    age: 23,
  }
},{
  ...
}]

const columns = [{
  header: 'Name',
  accessor: 'name',
}, {
  header: 'Age',
  accessor: 'age'
}, {
  header: 'Friend Name',
  accessor: d => d.friend.name
}, {
  header: 'Friend Age',
  accessor: 'friend.age'
}]

<ReactTable
  data=[{...}]
  columns={[]}
/>

Client-side Data

To use client-side data, simply pass the data prop an array. Client-side filtering and pagination is built in, and your table will update gracefully if you change any props.

Server-side Data

If you want to handle pagination, and sorting on the server, react-table makes it easy on you. Instead of passing the data prop an array, you provide a function instead.

This function will be called on mount, pagination events, and sorting events. It also provides you all of the parameters to help you query and format your data.

<ReactTable
  data={(params, callback) => {

    // params will give you all the info you need to query and sort your data
    params == {
      page: 0, // The page index the user is requesting
      pageSize: 20, // The current pageSize
      pages: -1, // The amount of existing pages (-1 means there is no page data yet)
      sorting: [ // An array of column sort models (yes, you can multi-sort!)
        {
          id: 'columnID', // The columnID (usually the accessor string, but can be overridden for server-side or required if the column accessor is a function)
          ascending: true or false
        }
      ]
    }

    // Query your data however you'd like, then structure your response like so:
    const result = {
      rows: [...], // Your data for the current page/sorting model
      pages: 10 // optionally provide how many pages exist (this is only needed if you choose to display page numbers, and only the first time you make the call or if the page count changes)
    }

    // You can return a promise that resolve the result
    return Axios.post('/myDataEnpoint', params) // resolves to `result`

    // or use the manual callback whenever you please
    setTimeout(() => {
      callback(result)
    }, 5000)

    // That's it!

  }}
/>

Multi-Sort

When clicking on a column header, hold shift to multi-sort! You can toggle aascending descending and none for multi-sort columns. Clicking on a header without holding shift will clear the multi-sort and replace it with the single sort of that column. It's quite handy!

Default Props

{
  className: '-striped -highlight',
  pageSize: 20,
  minRows: 0,
  data: [],
  previousComponent: <button {...props} className='-btn'>{props.children}</button>,
  nextComponent: <button {...props} className='-btn'>{props.children}</button>,
  previousText: 'Previous',
  nextText: 'Next',
  loadingComponent: <span>Loading...</span>,
  column: { // default properties for every column's model
    sortable: true,
    show: true
  }
}

You can easily override the core defaults like so:

import { ReactTableDefaults } from 'react-table'

Object.assign(ReactTableDefaults, {
  pageSize: 10,
  minRows: 3,
  // etc...
})

Or just define them on the component

<ReactTable
  pageSize={10}
  minRows={3}
  // etc...
})

Column Props

[{
  // Required
  header: 'Header Name' or JSX eg. ({data, column}) => <div>Header Name</div>,
  accessor: 'propertyName' or Accessor eg. (row) => row.propertyName,

  // Optional
  id: 'myProperty', // A unique ID is needed if the accessor is not a string or if you would like to override the column name used in server-side calls
  render: JSX eg. ({row, value, index}) => <span>{value}</span>, // Provide a JSX element or stateless function to render whatever you want as the column's cell with access to the entire row
  sortable: true,
  sort: 'asc' or 'desc',
  show: true,
  width: Number, // Locks the column width to this amount
  minWidth: Number // Allows the column to flex above this minimum amount
}]