-
66
- ? "#85cc00"
- : row.value > 33
- ? "#ffbf00"
- : "#ff2e00",
- borderRadius: "2px",
- transition: "all .2s ease-out"
- }}
- />
-
- )
- }
-];
-```
-
-## Styles
-
-- React-table ships with a minimal and clean stylesheet to get you on your feet quickly.
-- The stylesheet is located at `react-table/react-table.css`.
-- There are countless ways to import a stylesheet. If you have questions on how to do so, consult the documentation of your build system.
-
-#### Classes
-
-- Adding a `-striped` className to ReactTable will slightly color odd numbered rows for legibility
-- Adding a `-highlight` className to ReactTable will highlight any row as you hover over it
-
-#### CSS
-
-We think the default styles looks great! But, if you prefer a more custom look, all of the included styles are easily overridable. Every single component contains a unique class that makes it super easy to customize. Just go for it!
-
-#### JS Styles
-
-Every single react-table element and `get[ComponentName]Props` callback supports `classname` and `style` props.
-
-## Custom Props
-
-#### Built-in Components
-
-Every single built-in component's props can be dynamically extended using any one of these prop-callbacks:
-
-```javascript
-
-```
-
-If used, **a callback prop must return an valid object**, even if it's an empty one.
-
-These callbacks are executed with each render of the element with four parameters:
-
-1. Table State
-2. RowInfo (undefined if not applicable)
-3. Column (undefined if not applicable)
-4. React Table Instance
-
-This makes it extremely easy to add, say... a row click callback!
-
-```javascript
-// When any Td element is clicked, we'll log out some information
-
{
- return {
- onClick: (e, handleOriginal) => {
- console.log("A Td Element was clicked!");
- console.log("it produced this event:", e);
- console.log("It was in this column:", column);
- console.log("It was in this row:", rowInfo);
- console.log("It was in this table instance:", instance);
-
- // IMPORTANT! React-Table uses onClick internally to trigger
- // events like expanding SubComponents and pivots.
- // By default a custom 'onClick' handler will override this functionality.
- // If you want to fire the original onClick handler, call the
- // 'handleOriginal' function.
- if (handleOriginal) {
- handleOriginal();
- }
- }
- };
- }}
-/>
-```
-
-You can use these callbacks for dynamic styling as well!
-
-```javascript
-// Any Tr element will be green if its (row.age > 20)
- {
- return {
- style: {
- background: rowInfo.row.age > 20 ? "green" : "red"
- }
- };
- }}
-/>
-```
-
-#### Column Components
-
-Just as core components can have dynamic props, columns and column headers can too!
-
-You can utilize either of these prop callbacks on columns:
-
-```javascript
-const columns = [{
- getHeaderProps: () => (...),
- getProps: () => (...)
-}]
-```
-
-In a similar fashion these can be used to dynamically style just about anything!
-
-```javascript
-// This columns cells will be red if (row.name === Santa Clause)
-const columns = [
- {
- getProps: (state, rowInfo, column) => {
- return {
- style: {
- background: rowInfo.row.name === "Santa Clause" ? "red" : null
- }
- };
- }
- }
-];
-```
-
-## Pivoting and Aggregation
-
-Pivoting the table will group records together based on their accessed values and allow the rows in that group to be expanded underneath it.
-To pivot, pass an array of `columnID`'s to `pivotBy`. Remember, a column's `id` is either the one that you assign it (when using a custom accessors) or its `accessor` string.
-
-```javascript
-
-```
-
-Naturally when grouping rows together, you may want to aggregate the rows inside it into the grouped column. No aggregation is done by default, however, it is very simple to aggregate any pivoted columns:
-
-```javascript
-// In this example, we use lodash to sum and average the values, but you can use whatever you want to aggregate.
-const columns = [
- {
- Header: "Age",
- accessor: "age",
- aggregate: (values, rows) => _.round(_.mean(values)),
- Aggregated: row => {
- // You can even render the cell differently if it's an aggregated cell
- return row.value (avg);
- }
- },
- {
- Header: "Visits",
- accessor: "visits",
- aggregate: (values, rows) => _.sum(values)
- }
-];
-```
-
-Pivoted columns can be sorted just like regular columns including holding down the `` button to multi-sort.
-
-## Sub Tables and Sub Components
-
-By adding a `SubComponent` props, you can easily add an expansion level to all root-level rows:
-
-```javascript
- {
- return (
-
- You can put any component you want here, even another React Table! You
- even have access to the row-level data if you need! Spark-charts,
- drill-throughs, infographics... the possibilities are endless!
-
- );
- }}
-/>
-```
-
-## Server-side Data
-
-If you want to handle pagination, sorting, and filtering on the server, `react-table` makes it easy on you.
-
-1. Feed React Table `data` from somewhere dynamic. eg. `state`, a redux store, etc...
-1. Add `manual` as a prop. This informs React Table that you'll be handling sorting and pagination server-side
-1. Subscribe to the `onFetchData` prop. This function is called at `componentDidMount` and any time sorting, pagination or filterting is changed in the table
-1. In the `onFetchData` callback, request your data using the provided information in the params of the function (current state and instance)
-1. Update your data with the rows to be displayed
-1. Optionally set how many pages there are total
-
-```javascript
- {
- // show the loading overlay
- this.setState({loading: true})
- // fetch your data
- Axios.post('mysite.com/data', {
- page: state.page,
- pageSize: state.pageSize,
- sorted: state.sorted,
- filtered: state.filtered
- })
- .then((res) => {
- // Update react-table
- this.setState({
- data: res.data.rows,
- pages: res.data.pages,
- loading: false
- })
- })
- }}
-/>
-```
-
-For a detailed example, take a peek at our async table mockup
-
-## Fully Controlled Component
-
-React Table by default works fantastically out of the box, but you can achieve even more control and customization if you choose to maintain the state yourself. It is very easy to do, even if you only want to manage _parts_ of the state.
-
-Here are the props and their corresponding callbacks that control the state of the a table:
-
-```javascript
- {...}} // Called when the page index is changed by the user
- onPageSizeChange={(pageSize, pageIndex) => {...}} // Called when the pageSize is changed by the user. The resolve page is also sent to maintain approximate position in the data
- onSortedChange={(newSorted, column, shiftKey) => {...}} // Called when a sortable column header is clicked with the column itself and if the shiftkey was held. If the column is a pivoted column, `column` will be an array of columns
- onExpandedChange={(newExpanded, index, event) => {...}} // Called when an expander is clicked. Use this to manage `expanded`
- onFilteredChange={(filtered, column) => {...}} // Called when a user enters a value into a filter input field or the value passed to the onFiltersChange handler by the Filter option.
- onResizedChange={(newResized, event) => {...}} // Called when a user clicks on a resizing component (the right edge of a column header)
-/>
-```
-
-## Functional Rendering
-
-Possibly one of the coolest features of React-Table is its ability to expose internal components and state for custom render logic. The easiest way to do this is to pass a function as the child of ``.
-
-The function you pass will be called with the following items:
-
-- Fully-resolved state of the table
-- A function that returns the standard table component
-- The instance of the component
-
-You can then return any JSX or react you want! This turns out to be perfect for:
-
-- Accessing the internal state of the table without a `ref`
-- Decorating the table or extending it with your own UI
-- Building your own custom display logic
-
-Accessing internal state and wrapping with more UI:
-
-```javascript
-
- {(state, makeTable, instance) => {
- return (
-
-
-
- state.allVisibleColumns ==={" "}
- {JSON.stringify(state.allVisibleColumns, null, 4)}
-
-
- {makeTable()}
-
- );
- }}
-
-```
-
-The possibilities are endless!
-
-## Sorting
-
-Sorting comes built in with React-Table.
-
-- Click a column header to sort by its accessor.
-- Click it again to reverse the sort.
-- Set `defaultSortDesc` property to `true` to make the first sort direction default to descending.
-- Override a specific column's default sort direction by using the same `defaultSortDesc` property on a column, set to `true`
-
-## Multi-Sort
-
-When clicking on a column header, hold shift to multi-sort! You can toggle `ascending` `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!
-
-You can set the `multiSort` prop to `false` to disable this feature (which may be useful for server-side sorting when you are not
-going to sort multiple columns).
-
-## Custom Sorting Algorithm
-
-To override the default sorting algorithm for the whole table use the `defaultSortMethod` prop.
-
-To override the sorting algorithm for a single column, use the `sortMethod` column property.
-
-Supply a function that implements the native javascript [`Array.sort`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) interface. This is React Table's default sorting algorithm:
-
-- `a` the first value to compare
-- `b` the second value to compare
-- `desc` true if sort is descending, false if ascending
-
-```javascript
-defaultSortMethod = (a, b, desc) => {
- // force null and undefined to the bottom
- a = a === null || a === undefined ? -Infinity : a;
- b = b === null || b === undefined ? -Infinity : b;
- // force any string values to lowercase
- a = typeof a === "string" ? a.toLowerCase() : a;
- b = typeof b === "string" ? b.toLowerCase() : b;
- // Return either 1 or -1 to indicate a sort priority
- if (a > b) {
- return 1;
- }
- if (a < b) {
- return -1;
- }
- // returning 0 or undefined will use any subsequent column sorting methods or the row index as a tiebreaker
- return 0;
-};
-```
-
-## Filtering
-
-Filtering can be enabled by setting the `filterable` option on the table.
-
-If you don't want particular column to be filtered you can set the `filterable={false}` option on the column.
-
-By default the table tries to filter by checking if the row's value starts with the filter text. The default method for filtering the table can be set with the table's `defaultFilterMethod` option.
-
-If you want to override a particular column's filtering method, you can set the `filterMethod` option on a column.
-
-By default, `filterMethod` is passed a single row of data at a time, and you are responsible for returning `true` or `false`, indicating whether it should be shown.
-
-Alternatively, you can set `filterAll` to `true`, and `filterMethod` will be passed the entire array of rows to be filtered, and you will then be responsible for returning the new filtered array. This is extremely handy when you need to utilize a utility like fuzzy matching that requires the entire array of items.
-
-To completely override the filter that is shown, you can set the `Filter` column option. Using this option you can specify the JSX that is shown. The option is passed an `onChange` method which must be called with the the value that you want to pass to the `filterMethod` option whenever the filter has changed.
-
-See Custom Filtering demo for examples.
-
-## Component Overrides
-
-Though we confidently stand by the markup and architecture behind it, `react-table` does offer the ability to change the core componentry it uses to render everything. You can extend or override these internal components by passing a react component to it's corresponding prop on either the global props or on a one-off basis like so:
-
-```javascript
-// Change the global default
-import { ReactTableDefaults } from 'react-table'
-Object.assign(ReactTableDefaults, {
- TableComponent: component,
- TheadComponent: component,
- TbodyComponent: component,
- TrGroupComponent: component,
- TrComponent: component,
- ThComponent: component,
- TdComponent: component,
- TfootComponent: component,
- ExpanderComponent: component,
- AggregatedComponent: component,
- PivotValueComponent: component,
- PivotComponent: component,
- FilterComponent: component,
- PaginationComponent: component,
- PreviousComponent: undefined,
- NextComponent: undefined,
- LoadingComponent: component,
- NoDataComponent: component,
- ResizerComponent: component
-})
-
-// Or change per instance
-
-```
-
-If you choose to change the core components React-Table uses to render, you must make sure your replacement components consume and utilize all of the supplied and inherited props that are needed for that component to function properly. We would suggest investigating the source for the component you wish to replace.
+Documentation for v7 is coming soon. If you're looking for the [v6 documentation, click here](/tree/v6)
## Contributing