Fixed Data Table 2

A React table component designed to allow presenting millions of rows of da...

README

Fixed-Data-Table-2


Fixed-Data-Table-2 is a continuation of facebook/fixed-data-table.  The original repo is no longer maintained and has many pull requests awaiting response.

FixedDataTable is a React component for building and presenting data in a flexible, powerful way. It supports standard table features, like headers, columns, rows, header groupings, and both fixed-position and scrolling columns.

The table was designed to handle thousands of rows of data without sacrificing performance. Scrolling smoothly is a first-class goal of FixedDataTable and it's architected in a way to allow for flexibility and extensibility.

Features of FixedDataTable:
Fixed headers and footer
Both fixed and scrollable columns
Handling huge amounts of data
Variable row heights (with adaptive scroll positions)
Column resizing
Performant scrolling
Customizable styling
Jumping to a row or column
Controlled scroll API allows touch support

Things the FixedDataTable doesn't do:
FixedDataTable does not provide a layout reflow mechanism or calculate content layout information such as width and height of the cell contents. The developer has to provide the layout information to the table instead.
FixedDataTable does not handle sorting of data. Instead it allows the developer to supply data getters that can be sort-, filter-, or tail-loading-aware.
FixedDataTable does not fetch the data (see above)

This version of FixedDataTable is maintained by Schrödinger, Inc. It is a forked version of Facebook’s FixedDataTable Repository available here available under the BSD License. Contributions and modifications to FixedDataTable are also subject to the BSD License see here.

Getting started


Install fixed-data-table-2 using npm.

  1. ```shell
  2. npm install fixed-data-table-2
  3. ```
Add the default stylesheet dist/fixed-data-table.css using a link tag or import it with a CSS module.

Implementing a table involves three component types- ``,``, and ``.

`
` contains configuration information for the entire table, like dimensions and row count.

  1. ```javascript

  2.   const rows =[0,1,2];

  3.   <Table
  4.     rowHeight={50}
  5.     rowsCount={100}
  6.     width={5000}
  7.     height={5050}
  8.     headerHeight={50}
  9.     ...
  10.   </Table>
  11. ```    

`` defines the way data is displayed for one column in the table, including all cell behavior for that column. Rather than manipulating each cell directly, pass a cell component as a prop to the column, and the column will render a cell for each index in the data array.

  1. ```javascript
  2.     <Column
  3.       header={<Cell>Col 1</Cell>}
  4.       cell={<Cell>Column 1</Cell>}
  5.       width={2000}
  6.     />
  7. ```
The cell components in a column will receive the current array index of your data as a prop (this.props.rowIndex). Use this to access the correct value for each cell.
  1. ```javascript
  2.     const rows = [0,1,2];
  3.     
  4.     <Column
  5.       header={<Cell>Column 1</Cell>}
  6.       cell={({rowIndex, ...props}) => (
  7.         <Cell {...props}>
  8.         {rows[rowIndex]}
  9.         </Cell>
  10.       )}
  11.       width={2000}
  12.     />
  13. ```

If your data is an array of objects, define a columnKey prop for each column and it too will be passed to all cells in that column.
  1. ```javascript
  2.     const rows = [
  3.       { someKey: "someValue" },
  4.       { someKey: "anotherValue" },
  5.       { someKey: "yetAnother" }
  6.     ];
  7.     
  8.   <Column
  9.     header={<Cell>Col 1</Cell>}
  10.     columnKey="someKey"
  11.     cell={({ rowIndex, columnKey, ...props }) =>
  12.       <Cell {...props}>
  13.         {rows[rowIndex][columnKey]}
  14.       </Cell>}
  15.     width={2000}
  16.   />;


  17. ```

You may find it useful to define custom Cell components, which can also be passed to the Column:
  1. ```javascript
  2.     const MyCustomCell = ({ isSpecial }) =>
  3.       <Cell>
  4.         {isSpecial ? "I'm Special" : "I'm Not Special"}
  5.       </Cell>;


  6.     <Column
  7.       header={<Cell>Col 3</Cell>}
  8.       cell={<MyCustomCell isSpecial/>}
  9.       width={2000}
  10.     />

  11. ```

Code Sample

For more detailed examples, please see the examples section of the documentation. If you need help getting started with a React build system, we recommend create-react-app.
  1. ```javascript
  2. import React from 'react';
  3. import ReactDOM from 'react-dom';
  4. import {Table, Column, Cell} from 'fixed-data-table-2';
  5. import 'fixed-data-table-2/dist/fixed-data-table.css';


  6. // Table data as a list of array.
  7. const rows = [
  8.   "first row",
  9.   "second row",
  10.   "third row"
  11.   // .... and more
  12. ];

  13. // Custom cell implementation with special prop
  14. const MyCustomCell = ({ mySpecialProp }) =>
  15.   <Cell>
  16.     {mySpecialProp === "column2" ? "I'm column 2" : "I'm not column 2"}
  17.   </Cell>;

  18. // Render your table
  19. ReactDOM.render(
  20.   <Table
  21.     rowHeight={50}
  22.     rowsCount={rows.length}
  23.     width={5000}
  24.     height={5000}
  25.     headerHeight={50}>
  26.     <Column
  27.       header={<Cell>Col 1</Cell>}
  28.       cell={<Cell>Column 1 static content</Cell>}
  29.       width={2000}
  30.     />
  31.     <Column
  32.       header={<Cell>Col 2</Cell>}
  33.       cell={<MyCustomCell mySpecialProp="column2" />}
  34.       width={1000}
  35.     />
  36.     <Column
  37.       header={<Cell>Col 3</Cell>}
  38.       cell={({rowIndex, ...props}) => (
  39.         <Cell {...props}>
  40.           Data for column 3: {rows[rowIndex]}
  41.         </Cell>
  42.       )}
  43.       width={2000}
  44.     />
  45.   </Table>,
  46.   document.getElementById('example')
  47. );
  48. ```

Browser Support


| Chrome        | Firefox           | IE  | Safari
| Latest | Latest | 11+ | Unsupported* |

* Safari may function correct, but we are not actively testing with it


Contributions


Use GitHub issues for requests.

We actively welcome pull requests; learn how to contribute.

BY CONTRIBUTING TO FIXEDDATATABLE, YOU AGREE THAT YOUR CONTRIBUTIONS WILL BE LICENSED UNDER THE BSD LICENSE. Furthermore, by contributing to FixedDataTable, you hereby grant to Schrödinger and any recipients of your contributions, including but not limited to users of this site, a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, use, make and distribute your contributions and any derivative works under all intellectual property rights including but not limited to copyright and patent. BY CONTRIBUTING TO FIXEDDATATABLE, YOU REPRESENT AND WARRANT THAT YOU ARE LEGALLY ENTITLED TO GRANT THE FOREGOING LICENSE.