- The exported (but undocumented) `applyHooks` function has been deprecated. Please use either `reduceHooks` or `loopHooks` utilities in your custom plugins now.
- The exported (but undocumented) `applyPropHooks` function has been deprecated. Please use the `makePropGetter` utility in your custom plugins now.
- Added the `reduceHooks` exported utility which is used to reduce a value through a collection of hooks. Each hook must return a value (mutation is discouraged)
- Added the `loopHooks` exported utility which is used to loop over a collection of hooks. Hooks are not allowed to return a value (mutation is encouraged)
- Prop-getter hook functions now support returning an array (in addition to the typical object of props). When an array is returned, each item in the array is smart-merged into a new props object (meaning it will intelligently compose and override styles and className)
- Added the `makePropGetter` exported utility which is used to create prop getters from a prop getter hook.
- Prop-getter function supplied to the table have 2 new overloaded options (in addition to the typical object of props):
- `Function(props, instance, ...row/col/context) => Array<props> | props` - If a function is passed to a prop getter function, it will receive the previous props, the table instance, and potentially more context arguments. It is then be expected to return either an array of new props (to be smart-merged with styles and classes, the latest values taking priority over the previous values) or a props object (which will replace all previous props)
- `Array<props>` - If an array is passed to a prop getter function, each prop object in the array will be smart-merged with styles and classes into the props from previous hooks (with the latest values taking priority over the previous values).
- Extracted default hooks into separate file.
- Added the `useOptions` plugin hook, which allows a plugin to reduce/modify the initial options being passed to the table
- Converted almost all usages of `instanceRef.current` to use `useGetLatest(instanceRef.current)` to help with avoiding memory leaks and to be more terse.
- Converted all previous prop-getter definitions to use the new `makePropGetter`
- Reorganized plugin hooks to declare as many hooks in the main plugin function as opposed to in the `useInstance` hook.
- Changed the `useInstanceBeforeDimensions` hook to be a `loopHooks` call instead of a reducer. An error will be thrown now if any of these hook functions returns a value (to discourage mutation of the instance)
- Changed the `useInstance` hook to be a `loopHooks` call instead of a reducer. An error will be thrown now if any of these hook functions returns a value (to discourage mutation of the instance)
- Change the `prepareRow` hook to be a `loopHooks` call instead of a reducer. An error will be thrown now if any of these hook functions returns a value (to discourage mutation of the row)
- The `columnsBeforeHeaderGroups` and `columnsBeforeHeaderGroupsDeps` hooks have been renamed to `flatColumns` and `flatColumnsDeps` respectively, which better reflects what they are used for, rather than their order, which can remain implicit.
- Added `headerGroups` and `headerGroupDeps` hooks, which, similar to `flatColumns`, allow you to decorate (and trigger) the memoized header group generation.
- Added `columns` and `columnsDeps` hooks, which, similar to `flatColumns` and `headerGroups`, allow you to decorate (and trigger) the memoized column generation/decoration.
- The new hook order is as follows: `columns/columnsDeps` => `flatColumns/flatColumnsDeps` => `headerGroups/headerGroupsDeps`
- `useColumnVisibility` now uses the new `headerGroupsDeps` hook to trigger header group regeneration when visibility changes
These definitions mask errors in the other definitions and there are better
ways of extending these.
See https://github.com/tannerlinsley/react-table/pull/1597 for an
example of an existing prototype that was missing but harder to find
because of these definitions.
It turns out that pulling the types directly from a package slightly
changes how visible they are to the consuming application. This makes
sense, previously we explicitly adding the react-table module to the
global namespace an so didn't need explicit imports, but now that's not
the case. So add explicit imports.
* ci: test cross platform
Test on Node.js 10 and 12, long term release support versions.
Test on Linux, Mac, and Windows machines.
* fix: update ic-ci-cli to version 2
includes fixes to support windows
* ci: disable yarn gpg
* ci: double quote string for windows ci
useTableState was an early and hasty abstraction that hasn't proved useful in many ways. Anything
you could do with useTableState, you could easily do using the same options (assuming they exist) in
the useTable hook. For this reason, state is now a first class citizen of the useTable hook, along
with more sane properties and option locations for anything pertaining to state.
Width options (`width`, `minWidth`, `maxWidth`) options are now a part of the core column object.
useBlockLayout and useAbsoluteLayout hooks now use this new internalized information to implement
their layouts. Those examples have been updated. A virtualized-rows example has also been added to
show off how the useBlockLayout hook can be used to virtualize rows with react-window.
* useAbsoluteLayout: To build tables with divs
* Adding `placeholderOf` attribute to column
* Adding `useAbsoluteLayout` in index.js
* Adding `useAbsoluteLayout` example
* Adding `useAbsoluteLayout` in api docs
* Adding test for `useAbsoluteLayout` hook
* TypeScript updates
I've found that trying to get solid TypeScript typings for this library
are a bit of a challenge. The composable nature of the library means
that the types for the builtin functions are by their nature somewhat
minimal, and that the user needs to be able to extend those interfaces
to reflect the specific plugins that are in use.
With that in mind I propose something like this.
To get the best out of them, you then need to extend those interfaces
using declaration merging, see
https://www.typescriptlang.org/docs/handbook/declaration-merging.html
e.g.
```ts
declare module 'react-table-hooks' {
export interface TableInstance<D = any>
extends UseFiltersValues<D>,
UsePaginationValues<D>,
UseExpandedValues,
UseGroupByValues {}
export interface TableState<D = any>
extends UsePaginationState,
UseGroupByState,
UseSortbyState<D>,
UseFiltersState<D> {}
}
```
This also puts the ability to extend those types with any user defined
hooks completely in the users hands.
This gives the greatest flexibility, but I'll admit that it isn't
particularly obvious. Perhaps a typescript readme and example is needed.
* fix useExpanded type
* fix module name
* fix typo
* address review feedback
* add IdType, update Filters definition
useExpanded now uses a flat array of row path keys for tracking expanded state instead of nested
objects. This is both easier to use as a developer, but also enables expanding all rows or even
leaving nested rows in an expanded state, despite their parent rows' expanded state.
BREAKING CHANGE: See description
* Sub rows are selected if the parent row is selected.
* Parent rows are updated accordingly if a subRow is selected.
* Updated useRowSelect snapshot tests to test subRow selection.
* fix(use-sort-by): sorting now ignores column ids that no longer exist
* fix(use-filters): filtering no longer fails when column doesn't exist
* fix(use-sortby): filtering out invalid sortBys before sorting
The renderer function for headers, columns, cells, aggregates, filters, etc used to mix properties
from all of those contexts, including rows. Now thow contexts are located on their own reserved
properties, eg. `Cell: ({ cell: { value}, row, column, ...instance }) => value`
BREAKING CHANGE: The renderer function for headers, columns, cells, aggregates, filters, etc used
in case of using construction like:
```
{
defaultColumn = {}
}
```
`defaultColumn` will get new instance each time, so as result it force to recalculation each of `React.useMemo`.
* [v7] useSort - Multisort functionality: Limit `multiSort` number and configurable shift key
1. Provide configuration for multisort that pressing shift key is not compulsory
2. Configurable limit on max number of columns for multisort, like configuration has been provided that `maxMultiSortColCount` is 3, suppose currenlty table is sorted by `[A, B, C]` and then clicking `D` for sorting should result in table sorted by `[B, C , D]`
* update readme for new multisort options
* Use `isMultiSortEvent` function
so as to make `shift` key optional or take decision based on other parameters for multisorting
* `isMultiSortEvent` updated readme
* chore(package.json): use latest babel core, remove bridge
* test(.babelrc): add test environment so that Jest can use ES6 imports
* test(usetable): fix import
Since useColumns was relying on groupBy logic, this was code smell. I wanted useGroupBy to be able to add that logic all by itself and not have to have dependencies in the core of the table.
To fix that, I've moved the core column and row logic to the useTable hook and added a new hook 'columnsBeforeHeaderGroups' to allow useGroupBy to do what i needs in a more pure way.
* added assertion to check for show property inside column
* reverted previous change
* added a filter to weed out non-visible columns when calculating the size for grouped Headers
* added another case to the previous filter to factor in blank grouped Headers
* Fix pagination resetting to page zero with manualPagination
To be honest I'm not sure what this useLayoutEffect is there to do.
It has no visible effect if you don't use manualPagination, and if you
do it, simply jumps you back to the first page, defeating the point of
you having control of the pagination.
* Conditionally reset page on data change
Rather disable the whole page reset when filters, groupBy or sortBy
change, just because I wanted to disable the page reset on data change,
make that bit be conditional.
With that in mind, usePagination now accepts a
disablePageResetOnDataChange parameter.
V7 adds the option to remove a sort option, so it goes from asc -> desc
-> unset, then repeats. V6 just went from asc -> desc then repeated.
Personally I much preferred this, I think that there's a case to be made
that this is the more expected behavior.
I'm not sure if this is really the best way to fix this since it adds
yet another api option and I completely understand that that is less
than desirable, but I also would rather add an option than have to
duplicate the whole useSortBy hook.
This change allows you to technically use React Table without a layout hook. Under that assumption, you would need to come up with your own styling mechanisms for display.
The useSimpleLayout merely adds a single `width` style to the prop getters for column headers and cells.
The useFlexLayout is much more robust. Personally though, I have moved away from both, and am just using raw `display: table-row/table-cell` styles to let my tables display naturally.
* Install useSimpleLayout and adjust useTable and useRows as required.
* useSimpleLayout integration
* Minor final fix - replace .filter with .forEach
* Used a spread on the path.
Pagination elements are now customizable without having
to create a new Pagination component, that would
mostly mimic the existing one in terms of functionality.
* Adds import instructions to the HOC README
Also fixes up some language and remove other import instructions. It's better to just have the import instructions in just one place.
* Better visualizes a list of functions
I found the added Props by looking into the defaultProps.js when I could not find a way change the styling of the filter row.
Custom Props
Built-in Components
Every single built-in component's props can be dynamically extended using any one of these prop-callbacks:
<ReactTable
getProps={fn}
getTableProps={fn}
getTheadGroupProps={fn}
getTheadGroupTrProps={fn}
getTheadGroupThProps={fn}
getTheadProps={fn}
getTheadTrProps={fn}
getTheadThProps={fn}
+getTheadFilterProps={fn}
+getTheadFilterTrProps={fn}
+getTheadFilterThProps={fn}
* Add aria-label attributes to pagination jump and row count selector with a new prop to specify different text.
* Add new text props for labels to README
When rendering a class component using the `class extends React.Component {}` syntax, you would get an error `TypeError: Cannot call a class as a function` because the check to determine whether a component was a class component was insufficient. It seems pointless to even have a check, however, because the JSX syntax can render both class and functional components.
* initial commit
* update readme
* update examples and src
* edit readme
* use single instance of advancedExpandTable
* add in hoc codesandbox to docs, run eslint on new source file
* Also check ID field when finding pivot col in treeTableHOC
* Pass the ID if you've got one on treeTableHOC
* An expandable cell should never be hidden
* Fix typo
* Edit link to working codesandbox
Fix '100k Rows w/ Pivoting & Sub Components' example
Closes#870
* Add cross-env to remove environment variable errors on Windows
I think this is the most common way of setting columns or expanderDefaults.
I had to find issue #565 and then follow it to issue #394 to see explanations on how to do this.
I have used this library to develop a big application for my company and had been required to make the columns are foldable. I saw that feature is useful and would like to share with everybody. Especially to all developers who developed this great component.
Let me know if any issues with My component. I will fix it accordingly.
* Merge fork from master (#6)
* Examples Refactor + multiSort flag (#619)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Docs testing cleanup (#645)
* Examples Refactor + multiSort flag (#619) (#4)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Examples Refactor + multiSort flag (#619) (#5)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Fork Update (#7)
* Examples Refactor + multiSort flag (#619)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Docs testing cleanup (#645)
* Examples Refactor + multiSort flag (#619) (#4)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Examples Refactor + multiSort flag (#619) (#5)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Update README.md (#584)
* Update README.md
Missing " on Features list,
Extra comma removed
* Update README.md
Added space for component uniformity.
* Update the devDependencies for the linter (#596)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix ThComponent classnames ordering (#673)
Allow for custom classname to overwrite base styles
* Add column to getResizerProps (#667)
* CHANGELOG update
* Doco updates
fixed a typo - ‘row’ to ‘original’
added minimal dock on ‘minRows’
* Merge from original (#9)
* Examples Refactor + multiSort flag (#619)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Docs testing cleanup (#645)
* Examples Refactor + multiSort flag (#619) (#4)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Examples Refactor + multiSort flag (#619) (#5)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Update README.md (#584)
* Update README.md
Missing " on Features list,
Extra comma removed
* Update README.md
Added space for component uniformity.
* Update the devDependencies for the linter (#596)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix ThComponent classnames ordering (#673)
Allow for custom classname to overwrite base styles
* Add column to getResizerProps (#667)
* CHANGELOG update for 6.7.5 (#679)
* Merge fork from master (#6)
* Examples Refactor + multiSort flag (#619)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Docs testing cleanup (#645)
* Examples Refactor + multiSort flag (#619) (#4)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Examples Refactor + multiSort flag (#619) (#5)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Fork Update (#7)
* Examples Refactor + multiSort flag (#619)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Docs testing cleanup (#645)
* Examples Refactor + multiSort flag (#619) (#4)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Examples Refactor + multiSort flag (#619) (#5)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Update README.md (#584)
* Update README.md
Missing " on Features list,
Extra comma removed
* Update README.md
Added space for component uniformity.
* Update the devDependencies for the linter (#596)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix ThComponent classnames ordering (#673)
Allow for custom classname to overwrite base styles
* Add column to getResizerProps (#667)
* CHANGELOG update
* Use preset-env instead of preset-es2015
Remove preset-stage-2 and use individual required plugins.
* Expose es module build
* Update scripts in package.json
* Use rollup for faster and lighter umd builds
Add non minified version of the build.
* Merge fork from master (#6)
* Examples Refactor + multiSort flag (#619)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Docs testing cleanup (#645)
* Examples Refactor + multiSort flag (#619) (#4)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Examples Refactor + multiSort flag (#619) (#5)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Fork Update (#7)
* Examples Refactor + multiSort flag (#619)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Docs testing cleanup (#645)
* Examples Refactor + multiSort flag (#619) (#4)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Examples Refactor + multiSort flag (#619) (#5)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Update README.md (#584)
* Update README.md
Missing " on Features list,
Extra comma removed
* Update README.md
Added space for component uniformity.
* Update the devDependencies for the linter (#596)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix ThComponent classnames ordering (#673)
Allow for custom classname to overwrite base styles
* Add column to getResizerProps (#667)
* CHANGELOG update
* Header focus bug fix
Fixes#685
* Merge fork from master (#6)
* Examples Refactor + multiSort flag (#619)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Docs testing cleanup (#645)
* Examples Refactor + multiSort flag (#619) (#4)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Examples Refactor + multiSort flag (#619) (#5)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Fork Update (#7)
* Examples Refactor + multiSort flag (#619)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Docs testing cleanup (#645)
* Examples Refactor + multiSort flag (#619) (#4)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Examples Refactor + multiSort flag (#619) (#5)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Update README.md (#584)
* Update README.md
Missing " on Features list,
Extra comma removed
* Update README.md
Added space for component uniformity.
* Update the devDependencies for the linter (#596)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix ThComponent classnames ordering (#673)
Allow for custom classname to overwrite base styles
* Add column to getResizerProps (#667)
* CHANGELOG update
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Examples Refactor + multiSort flag (#619) (#4)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* Examples Refactor + multiSort flag (#619) (#5)
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
Still requires some basic sanity test to ensure ReactTable does
not have any fundamental coding errors.
Modified some of the /docs code to help with manual testing.
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
* Refactor HOCs to /src/hoc
Still have to write the HOCReadme.md (still just a placeholder for now)
* Refactor complete
May need to remove some redundant code
* Text change for the HOC samples
* Introduced a 'multiSort' flag
Defaults to 'true'
A 'false' value will turn multi-sort off.
* refactor: Fix defaultProps.js linter errors
* refactor: Fix lifecycle.js linter errors
* refactor: Fix pagination.js linter errors
* refactor: Fix propTypes.js linter errors
* refactor: Fix utils.js linter errors
* refactor: Fix methods.js linter errors
* refactor: Fix index.js linter errors
* Fix for linter changes + CHANGELOG update
* chore: Update the devDependencies for the linter
* A few HOC examples for react-table.
Not really integrated with the whole codesandbox.io approach.
* Missing dependency - shortid
We have found that with longer documentation files, the position of the sponsor link is more effective in helping fund the project when it's higher in the readme.
The current css selectors, eg. `.ReactTable input` cause conflicts with `input` elements inside Cells. So changed it to `.ReactTable .-pagination input`.
This brings `rt-tfoot` into line with `rt-thead` in terms of flex behaviour.
Without this, it's possible for an `rt-tr` to be taller than its containing
`rt-tfoot` without causing it to expand, which causes the outer `rt-table` to
scroll vertically.
* Add column id to the rowInfo object (passed to render). Resolves#237
* Creating a new object instead of modifying existing rowInfo; Refs #253
* Code style compliance. Refs #253
* Prevent transitions while resizing for a smoother effect.
* Disable text selection when resizing columns
* Use PivotValueComponent instead of pivotRender
* Add changelog file
* Convert expander column to be more like a regular column.
* Update story.
* Simplify setting render on defaultExpander.
* Add more control over expander and pivot columns using the column.
* Fix default filtering on pivot column.
* Add comments.
* Add column resizing for non pivot columns.
* Fixing resizing UI issues and mobile functionality.
* Remove calling onChange during resize events so that server example doesn't refetch data every time a column resizes.
* Change precedence in 'getResolvedState'
* Previously existing props would overwrite passed in state
* Now passed in state gets precedence
* added a controlled table example to storybook
* Add column filtering.
* Fix javascript warning from yarn test. Compile storybook and docs.
* Pass standard linting
* Add support for filtering pivot columns.
* Build distribution files.
* Set page to max page available if data changes and has less pages than before.
Closes#159
* Add column filtering.
* Fix javascript warning from yarn test. Compile storybook and docs.
* Pass standard linting
* Add support for filtering pivot columns.
* Build distribution files.
* Rename CollapseOnPageChange to CollapseOnDataChange to more accurately reflect its purpose.
* Add support for collapseOnPageChange.
* Fix collapseOnPageChange efficiency.
* rough draft of "closeSubComponentOnDataChange" and "preventAutoSortWhenComponentIsOpen"
* changed flag name from ...component to ...subcomponent
* fixed problem with sorting not immediately being applied. passes tests now
* changed var names
* Cleanup and simplification
* Fix deps
* Better freezing strategy
* subcomponent reverse
v6 is now considered feature complete to its current abilities and limitations. We are not actively working to fix any issues for v6 any more. We will, however, merge any non-breaking pull requests submitted to fix anything in v6.
# Using v7?
Thanks for using the beta version of React Table v7! We're very excited about it.
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Codesandbox!**
Use a new [react-table codesandbox](https://codesandbox.io/s/m5lxzzpz69) to reproduce the issue.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
**Smartphone (please complete the following information):**
We do not track feature requests through Github. Please use the [Spectrum React Table Forum](https://spectrum.chat/react-table) to talk about new ideas and features.
We do not use Github to track general support. Please use our public support forum at https://spectrum.chat/react-table.
NOTE: If a support/help/question issue is opened, it will be closed immediately and be redirected to the forum. Thanks for helping us keep our issues clean and productive!
- Fix an issue where `useResizeColumns` would crash when using the resizer prop getter
- Fix an issue where `useBlockLayout` was clobbering props sent to headers
## 7.0.0-rc.7
Removed:
-`applyHooks` (exported but undocumented) function has been deprecated. Please use either `reduceHooks` or `loopHooks` utilities in your custom plugins now.
-`applyPropHooks` (exported but undocumented) function has been deprecated. Please use the `makePropGetter` utility in your custom plugins now.
Added:
-`reduceHooks` exported utility which is used to reduce a value through a collection of hooks. Each hook must return a value (mutation is discouraged)
-`loopHooks` exported utility which is used to loop over a collection of hooks. Hooks are not allowed to return a value (mutation is encouraged)
-`makePropGetter` exported utility which is used to create prop getters from a prop getter hook.
-`useOptions` plugin hook, which allows a plugin to reduce/modify the initial options being passed to the table
-`useFinalInstance` plugin hook, which allows a plugin access to the final table instance before it is returned to the user.
Modified:
- Prop-getter hook functions now support returning an array (in addition to the typical object of props). When an array is returned, each item in the array is smart-merged into a new props object (meaning it will intelligently compose and override styles and className)
- Prop-getter function supplied to the table have 2 new overloaded options (in addition to the typical object of props):
-`Function(props, instance, ...row/col/context) => Array<props> | props` - If a function is passed to a prop getter function, it will receive the previous props, the table instance, and potentially more context arguments. It is then be expected to return either an array of new props (to be smart-merged with styles and classes, the latest values taking priority over the previous values) or a props object (which will replace all previous props)
-`Array<props>` - If an array is passed to a prop getter function, each prop object in the array will be smart-merged with styles and classes into the props from previous hooks (with the latest values taking priority over the previous values).
- Extracted default hooks into separate file.
- Converted almost all usages of `instanceRef.current` to use `useGetLatest(instanceRef.current)` to help with avoiding memory leaks and to be more terse.
- Converted all previous prop-getter definitions to use the new `makePropGetter`
- Reorganized plugin hooks to declare as many hooks in the main plugin function as opposed to in the `useInstance` hook.
- Changed the `useInstanceBeforeDimensions` hook to be a `loopHooks` call instead of a reducer. An error will be thrown now if any of these hook functions returns a value (to encourage mutation of the instance)
- Changed the `useInstance` hook to be a `loopHooks` call instead of a reducer. An error will be thrown now if any of these hook functions returns a value (to encourage mutation of the instance)
- Change the `prepareRow` hook to be a `loopHooks` call instead of a reducer. An error will be thrown now if any of these hook functions returns a value (to encourage mutation of the row)
## 7.0.0-rc.6
- The `columnsBeforeHeaderGroups` and `columnsBeforeHeaderGroupsDeps` hooks have been renamed to `flatColumns` and `flatColumnsDeps` respectively, which better reflects what they are used for, rather than their order, which can remain implicit.
- Added `headerGroups` and `headerGroupDeps` hooks, which, similar to `flatColumns`, allow you to decorate (and trigger) the memoized header group generation.
- Added `columns` and `columnsDeps` hooks, which, similar to `flatColumns` and `headerGroups`, allow you to decorate (and trigger) the memoized column generation/decoration.
- The new hook order is as follows: `columns/columnsDeps` => `flatColumns/flatColumnsDeps` => `headerGroups/headerGroupsDeps`
-`useColumnVisibility` now uses the new `headerGroupsDeps` hook to trigger header group regeneration when visibility changes
## 7.0.0-rc.5
- Fixed an issue where the exported `useAsyncDebounce` method would crash if its promise throw an error.
## 7.0.0-rc.4
- A maintenance release, purely intended to update the @latest tag (which was overwritten by a v6 publish)
## 7.0.0-rc.3
- Fixed an issue where `column.clearSortBy` would crash
## 7.0.0-rc.2
-`reducerHandlers` has been deprecated in favor of the new `stateReducers` hook.
- The `previousState` and `instanceRef` are now both generally available in state reducers for convenience.
- The global action property `action.instanceRef` has been deprecated.
- The `reducer` option has been renamed to `stateReducer` and in addition to passing a single reducer function now also supports passing an array of reducers
- Renamed `manualSorting` to be `manualSortBy` to be consistent with other naming conventions
- Removed the `getResetPageDeps` option in favor of the new `autoResetPage` option.
- Removed the `getResetFilterDeps` option in favor of the new `autoResetFilters` option.
- Removed the `getResetSortByDeps` option in favor of the new `autoResetSortBy` option.
- Removed the `getResetGroupByDeps` option in favor of the new `autoResetGroupBy` option.
- Removed the `getResetExpandedDeps` option in favor of the new `autoResetExpanded` option.
- Added a new exported utility called `useAsyncDebounce` to aid with external async side-effects.
- A new `useGetLatest` hook is used internally to track latest instances in a less ref-driven and verbose way.
- A new `useMountedLayoutEffect` hooks is now used internally to handle post-mount side-effects, mostly dealing with autoReset functionality
- Plugin hooks are now "consumed" using an internal `useConsumeHookGetter` hook. When they are consumed, they can no longer be manipulated past that point in the table lifecycle. This should help ensure people are using them in a relatively safe order with consistent expectations.
- Drastically "reduced" the reducer logic itself to be easier to understand and to be a stable reference for the life of the table. This change also means that the reducer must no longer be double-run/back-compared by React for changes in closure, thus actions and stateReducers (including user state reducers) will only fire once per action.
- Removed `debug` and related logging. It has been somewhat useful during development, but is now very noisy in the code. We can debug lifecycle and performance as needed from here on out.
- Removed unnecessary exports from `./utils.js` and moved all intentionally exported utilities to a new `./publicUtils.js` file.
## 7.0.0-rc.1
- Minor regex optimizations during row path creation
## 7.0.0-rc.0
- Added the support for the `Footer` renderer, `column.getFooterProps`, `footerGroups` and `footerGroup.getFooterProps`
## 7.0.0-beta.28
- Added the `useColumnVisibility` plugin as a core plugin along with several new instance and column-level methods to control column visibility
- Added the "column-hiding" example
## 7.0.0-beta.27
- Added the `useControlledState` option, which allows for hook-context control of the resolved internal table state
## 7.0.0-beta.26
- Fixed an issue where the table would crash if useSortBy was reset via the resetSortBy action
- Updated all of the examples to use the "react-table@latest" tag.
-`utils` is no longer an exported variable and instead, all of the individual util methods are exported at the root level of the library.
## 7.0.0-beta.25
- Fixed an issue where `useRowState` would crash due to invalid initial state of previous cell state on `columnId` lookup
## 7.0.0-beta.24
- Changed `selectedRowPaths` to use a `Set()` instead of an array for performance.
- Removed types and related files from the repo. The community will now maintain types externally on Definitely Typed
## 7.0.0-beta.23
- The internal `useMain` hook has been renamed to `useInstance`
- The internal `useBeforeDimensions` hook has been renamed to `useInstanceBeforeDimensions`
- Fixed an issue where `useResizeColumns` wasn't working properly
## 7.0.0-beta.22
- Fixed an issue where `useRowState` would crash due to invalid initial state attempting to spread into the new state
## 7.0.0-beta.21
- Removed deprecated `defaultState` export
## 7.0.0-beta.20
- Internals have been reworked to use `useReducer` instead of `useState` for stability and architecture
- The `state` option has been removed in favor of using a custom reducer
- The `reducer` option has been changed to a new function signature: `function (newState, action, oldState) => newState`
- The `setState` table instance method is no longer supported
- The `dispatch` table instanced method was added
- The `ReactTable.actions` export is now a plain object of action types mapped to identically named action strings
- The `ReactTable.reducerHandlers` export was added, which is a plain object of plugin hook names mapped to their respective reducer functions
## 7.0.0-beta.19
- Added an `isAggregated` boolean parameter to the `aggregate` function signature
## 7.0.0-beta.16
- Removed service workers from examples
- Fixed a memory leak when `instance` was referenced in function closures
- Fixed an issue where the table would infinitely rerender due to incorrect effect dependencies
- Fixed an issue where row grouping and row selection would not work properly together.
## 7.0.0-beta.15
- Fixed an issue where `defaultGetResetPageDeps` was using `data` instead of `rows`
## 7.0.0-beta.14
- Removed
-`disablePageResetOnDataChange` option. use the `getResetPageDeps` option now.
- Added
-`getResetPageDeps` option
-`getResetFilterDeps` option
-`getResetSortByDeps` option
-`getResetGroupByDeps` option
-`getResetExpandedDeps` option
## 7.0.0-beta.13
- Added options
-`defaultCanSort`
-`defaultCanFilter`
-`defaultCanGroupBy`
-`column.defaultCanSort`
-`column.defaultCanFilter`
-`column.defaultCanGroupBy`
- Renamed
-`disableGrouping` to `disableGroupBy`
-`disableSorting` to `disableSortBy`
-`disableGroupBy` to `disableGroupBy`
-`column.disableGrouping` to `column.disableGroupBy`
-`column.disableSorting` to `column.disableSortBy`
-`column.disableGroupBy` to `column.disableGroupBy`
- Removed propType definitions. Since types are now being maintained, it makes little sense to also maintain these. Cooincidentally, this also saves some bundle size in some scenarios where they may not be removed properly by a developer's bundler.
## 7.0.0-beta.0
- Massive changes to the entire project and library. Please consult the README and documentation for more information regarding these changes.
## 6.8.6
#### Fixes & Optimizations
- Since `resolveData` is now capable of materializing data on it's own, the `data` prop is no longer required as a prop-type.
## 6.8.4
#### Fixes & Optimizations
- Only run `resolveData` prop when `data` prop has changed, not any others.
## 6.8.3
#### Fixes & Optimizations
- Allow the `resolveData` prop to alter or materialize new data when the `data` prop changes.
## 6.8.1
#### Fixes & Optimizations
- Updated eslint and code formatting
## 6.7.5
#### Fixes & Optimizations
- Now passes `column` to `getResizerProps` (#667)
- NOTE: `getResizerProps` is now only called if the column is resizable
- Fixes the `className` ordering in defaultProps for ThComponent (#673)
- NOTE: user supplied classNames now come at the end so they can extend the defaults
## 6.7.4
#### Fixes & Optimizations
- Fix Prop types for columns
## 6.7.3
#### Fixes & Optimizations
- Fix the rest of the proptypes
## 6.7.2
#### Fixes & Optimizations
-`getPropTypes` proptype check
## 6.7.1
#### Fixes & Optimizations
-`eslint-config` moved to dev deps
## 6.7.0
## 6.7.0-alpha-0
#### New Features
- Expose page/pageSize to rows/cells
- Supply sort direction to custom sort methods
#### Fixes & Optimizations
- README updates
- Linter cleanup
- Added PropTypes node module
- Deps, linting and style upgrades
## 6.6.0
#### Fixes & Optimizations
- moved repo to react-tools
- Doc examples moved to codesandbox.io
- README updates
- CSS refacting for rt-tfoot to match rt-thead
- CSS more specific for input and select
## 6.5.3
#### Fixes & Optimizations
-`onClick` proxying and eslint
## 6.5.2
#### New Features
- Provide onClick handleOriginal function - #406
#### Fixes & Optimizations
- README updates
-`makePathArray` in utils - #326
- Various fixes: #294, #376, #398, #415,
## 6.5.1
#### Fixes & Optimizations
-`defaultExpanded` now works correctly - #372
-`column.getProps().rest` props are now applied correctly
-`makeTemplateComponent` now supports `displayName` - #289
## 6.5.0
##### New Features
-`column.filterAll` - defaults to `false`, but when set to `true` will provide the entire array of rows to `filterMethod` as opposed to one row at a time. This allows for more fine-grained filtering using any method you can dream up. See the [Custom Filtering example](https://react-table.js.org/#/story/custom-filtering) for more info.
## 6.4.0
##### New Features
-`PadRowComponent` - the content rendered inside of a padding row. Defaults to a react component that renders ` `
## 6.3.0
##### New Features
-`defaultSortDesc` - allows you to set the default sorting direction for all columns to descending.
-`column.defaultSortDesc` - allows you to set the default sorting direction for a specific column. Falls back to the global `defaultSortDesc` when not set at all.
## 6.0.0
##### New Features
- New Renderers:
-`Aggregated` - Custom renderer for aggregated cells
-`Pivot` - Custom renderer for Pivoted Cells (utilizes `Expander` and `PivotValue`)
-`PivotValue` - Custom renderer for Pivot cell values (deprecates the undocumented `pivotRender` option)
-`Expander` - Custom renderer for Pivot cell Expander
- Added custom sorting methods per table via `defaultSortMethod` and per column via `column.sortMethod`
- Pivot columns are now visibly separate and sorted/filtered independently.
- Added `column.resizable` to override global table `resizable` option for specific columns.
- Added `column.sortable` to override global table `sortable` option for specific columns.
- Added `column.filterable` to override global table `filterable` option for specific columns.
- Added `defaultExpanded` table option.
- All callbacks can now be utilized without needing to hoist and manage the piece of state they export. That is what their prop counterparts are for, so now the corresponding prop is used instead of the callback to detect a "fully controlled" state.
- Prevent transitions while column resizing for a smoother resize effect.
- Disable text selection while resizing columns.
##### Breaking API Changes
- New Renderers:
-`Cell` - deprecates and replaces `render`
-`Header` - deprecates and replaces `header`
-`Footer` - deprecates and replaces `footer`
-`Filter`- deprecates and replaces `filterRender`
- Callbacks now provide the destination state as the primary parameter(s). This makes hoisting and controlling the state in redux or component state much easier. eg.
-`onSorting` no longer requires you to build your own toggle logic
-`onResize` no longer requires you to build your own resize logic
- Renamed `onChange` callback -> `onFetchData` which will always fire when a new data model needs to be fetched (or if not using `manual`, when new data is materialized internally).
- Renamed `hideFilter` -> `filterable` (Column option. Note the true/false value is now flipped.)
-`cellInfo.row` and `rowInfo.row` now reference the materialize data for the table. To reference the original row, use `cellInfo.original` and `rowInfo.original`
- Removed `pivotRender` column option. You can now control how the value is displayed by overriding the `PivotValueComponent` or the individual column's `PivotValue` renderer. See [Pivoting Options Story](https://react-table.js.org/?selectedKind=2.%20Demos&selectedStory=Pivoting%20Options&full=0&down=1&left=1&panelRight=0&downPanel=kadirahq%2Fstorybook-addon-actions%2Factions-panel) for a reference on how to customize pivot column rendering.
If you have questions about implementation details, help or support, then please use our dedicated community forum at [Spectrum.chat/react-table](https://spectrum.chat/react-table) **PLEASE NOTE:** If you choose to instead open an issue for your question, your issue will be immediately closed and redirected to the forum.
## Reporting Issues
If you have found what you think is a bug, please [file an issue](https://github.com/tannerlinsley/react-table/issues/new). **PLEASE NOTE:** Issues that are identified as implementation questions or non-issues will be immediately closed and redirected to [Spectrum.chat/react-table](https://spectrum.chat/react-table)
## Suggesting new features
If you are here to suggest a feature, first create an issue if it does not already exist. From there, we will discuss use-cases for the feature and then finally discuss how it could be implemented.
## Development
If you have been assigned to fix an issue or develop a new feature, please follow these steps to get started:
- Fork this repository
- Install dependencies by running `$ yarn`
- Link `react-table` locally by running `$ yarn link`
- Auto-build files as you edit by running `$ yarn start`
- Implement your changes and tests to files in the `src/` directory and corresponding test files
- To run examples, follow their individual directions. Usually this is just `$ yarn && yarn start`.
- To run examples using your local build, link to the local `react-table` by running `$ yarn link react-table` from the example's directory
Enjoy this library? Try them all! [React Query](https://github.com/tannerlinsley/react-query), [React Form](https://github.com/tannerlinsley/react-form), [React Charts](https://github.com/tannerlinsley/react-charts)
### [Become a Sponsor](https://github.com/sponsors/tannerlinsley/)
## Features
- Lightweight at 7kb (and just 2kb more for styles)
-Fully customizable JSX templating
-Supports both Client-side & Server-side pagination and multi-sorting
-Column Pivoting & Aggregation
-Minimal design & easily themeable
-Fully controllable via optional props and callbacks
-<a href="https://medium.com/@tannerlinsley/why-i-wrote-react-table-and-the-problems-it-has-solved-for-nozzle-others-445c4e93d4a8#.axza4ixba" target="\_parent">"Why I wrote React Table and the problems it has solved for Nozzle.io</a> by Tanner Linsley
- Lightweight (5kb - 12kb+ depending on features used and tree-shaking)
This library is being built and maintained by me, @tannerlinsley and I am always in need of more support to keep this project afloat. If you would like to get additional support, add your logo or name on this README, or simply just contribute to my open source Sponsorship goal, [visit my Github Sponsors page!](https://github.com/sponsors/tannerlinsley/)
Simply pass the `data` prop anything that resembles an array or object. Client-side sorting and pagination are built in, and your table will update gracefully as you change any props. [Server-side data](#server-side-data) is also supported!
These are all of the available props (and their default values) for the main `<ReactTable />` component.
```javascript
{
// General
loading:false,// Whether to show the loading overlay or not
defaultPageSize:20,// The default page size (this can be changed by the user if `showPageSizeOptions` is enabled)
minRows:0,// Ensure this many rows are always rendered, regardless of rows on page
showPagination:true,// Shows or hides the pagination component
showPageJump:true,// Shows or hides the pagination number input
showPageSizeOptions:true,// Enables the user to change the page size
pageSizeOptions:[5,10,20,25,50,100],// The available page size options
expanderColumnWidth:30,// default columnWidth for the expander column
### [Become a Sponsor](https://github.com/sponsors/tannerlinsley/)
// Callbacks
onChange:(state,instance)=>null,// Anytime the internal state of the table changes, this will fire
onTrClick:(row,event)=>null,// Handler for row click events
## Previous Versions
// Text
previousText:'Previous',
nextText:'Next',
pageText:'Page',
ofText:'of',
rowsText:'rows',
### Version 6
// Classes
className:'-striped -highlight',// The most top level className for the component
tableClassName:'',// ClassName for the `table` element
theadClassName:'',// ClassName for the `thead` element
tbodyClassName:'',// ClassName for the `tbody` element
trClassName:'',// ClassName for all `tr` elements
trClassCallback:row=>null,// A call back to dynamically add classes (via the classnames module) to a row element
paginationClassName:''// ClassName for `pagination` element
v6 is a great library and while it is still available to install and use, I am no longer offering any long-term support for it. If you intend to keep using v6, I recommend maintaining your own fork of the library and keeping it up to date for your version of React.
// Styles
style:{},// Main style object for the component
tableStyle:{},// style object for the `table` component
theadStyle:{},// style object for the `thead` component
tbodyStyle:{},// style object for the `tbody` component
trStyle:{},// style object for the `tr` component
trStyleCallback:row=>{},// A call back to dynamically add styles to a row element
thStyle:{},// style object for the `th` component
tdStyle:{},// style object for the `td` component
paginationStyle:{},// style object for the `paginination` component
#### Where are the docs for the older v6 version?
// Controlled Props (see Using as a Fully Controlled Component below)
page:undefined,
pageSize:undefined,
sorting:undefined,
expandedRows:undefined,
// Controlled Callbacks
onExpandRow:undefined,
onPageChange:undefined,
onPageSizeChange:undefined,
}
```
Please [visit the v6 branch](https://github.com/tannerlinsley/react-table/tree/v6)
You can easily override the core defaults like so:
#### I want to migrate from v6 to v7. How do I do that?
```javascript
import{ReactTableDefaults}from'react-table'
The differences between the 2 versions are incredibly massive. Unfortunately, I cannot write a one-to-one upgrade guide for any of v6's API, simply because much of it is irrelevant with v7's headless approach. The best approach for migrating to v7 is to learn its API by reading the documentation and then following some of the examples to begin building your own table component.
Object.assign(ReactTableDefaults,{
defaultPageSize:10,
minRows:3,
// etc...
})
```
Or just define them on the component per-instance
```javascript
<ReactTable
defaultPageSize={10}
minRows={3}
// etc...
/>
```
## Columns
`<ReactTable/>` requires a `columns` prop, which is an array of objects containing the following properties
id:'myProperty',// Conditional - A unique ID is required if the accessor is not a string or if you would like to override the column name used in server-side calls
sortable:true,
sort:'asc'or'desc',// used to determine the column sorting on init
show:true,// can be used to hide a column
width:undefined,// A hardcoded width for the column. This overrides both min and max width options
minWidth:100// A minimum width for this column. If there is extra room, column will flex to fill available space (up to the max-width, if set)
maxWidth:undefined// A maximum width for this column.
// Special
expander:false// This option will override all data-related options and designates the column to be used
// for pivoting and sub-component expansion
// Cell Options
className:'',// Set the classname of the `td` element of the column
style:{},// Set the style of the `td` element of the column
render:JSXeg.({value,rowValues,row,index,viewIndex})=><span>{value}</span>, //ProvideaJSXelementorstatelessfunctiontorenderwhateveryouwantasthecolumn's cell with access to the entire row
// value == the accessed value of the column
// rowValues == an object of all of the accessed values for the row
// row == the original row of data supplied to the table
// index == the original index of the data supplied to the table
// viewIndex == the index of the row in the current page
// Header & HeaderGroup Options
header: 'HeaderName' or JSX eg. ({data, column}) => <div>Header Name</div>,
headerClassName: '',// Set the classname of the `th` element of the column
headerStyle:{},// Set the style of the `th` element of the column
// Header Groups only
columns:[...]// See Header Groups section below
}]
```
## Styles
React-table ships with a minimal and clean stylesheet to get you on your feet quickly. It's located at `react-table/react-table.css`.
- 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
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!
## Header Groups
To group columns with another header column, just nest your columns in a header column like so:
```javascript
constcolumns=[{
header:'Favorites',
columns:[{
header:'Color',
accessor:'favorites.color'
},{
header:'Food',
accessor:'favorites.food'
}{
header:'Actor',
accessor:'favorites.actor'
}]
}]
```
## Pivoting & 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
<ReactTable
...
pivotBy={['lastName','age']}
/>
```
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.
constcolumns=[{
header:'Age',
accessor:'age',
aggregate:(values,rows)=>_.round(_.mean(values)),
render:row=>{
// You can even render the cell differently if it's an aggregated cell
Pivoted columns can be sorted just like regular columns, but not independently of each other. For instance, if you click to sort the pivot column in ascending order, it will sort by each pivot recursively in ascending order together.
## Sub Tables & Sub Components
By adding a `SubComponent` props, you can easily add an expansion level to all root-level rows:
If you want to handle pagination, and sorting 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 `onChange` prop. This function is called at `compomentDidMount` and any time sorting or pagination is changed by the user
1. In the `onChange` callback, request your data using the provided information in the params of the function (state and instance)
1. Update your data with the rows to be displayed
1. Optionally set how many pages there are total
```javascript
<ReactTable
...
data={this.state.data}// should default to []
pages={this.state.pages}// should default to -1 (which means we don't know how many pages we have)
loading={this.state.loading}
manual// informs React Table that you'll be handling sorting and pagination server-side
onChange={(state,instance)=>{
// show the loading overlay
this.setState({loading:true})
// fetch your data
Axios.post('mysite.com/data',{
page:state.page,
pageSize:state.pageSize,
sorting:state.sorting
})
.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 <a href="https://github.com/tannerlinsley/react-table/blob/master/stories/ServerSide.js" target="\_parent">async table mockup</a>
## 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
<ReactTable
// Props
page={0}// the index of the page you wish to display
pageSize={20}// the number of rows per page to be displayed
sorting={[{
id:'lastName',
asc:true
},{
id:'firstName',
asc:true
}]}// the sorting model for the table
expandedRows={{
1:true,
4:true,
5:{
2:true,
3:true
}
}}// The nested row indexes on the current page that should appear expanded
// Callbacks
onPageChange={(pageIndex)=>{...}}// 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
onSortingChange={(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
onExpandRow={(index,event)=>{...}}// Called when an expander is clicked. Use this to manage `expandedRows`
/>
```
## Functional Rendering
Possibly one of the coolest features of React-Table is its ability to expose internal state for custom render logic. The easiest way to do this is to optionally pass a function as a child of `<ReactTable />`.
The function you pass will be called with the following items:
- Fully-resolved state of the table
- The standard table generator
- 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 before rendering the table
- Decorating the table with more UI
- Building your own 100% custom display logic, while utilizing the state and methods of the table component
Example:
```javascript
<ReactTable
columns={columns}
data={data}
...
>
{(state,makeTable,instance)=>{
// Now you have full access to the state of the table!
state.decoratedColumns===[...]// all of the columns (with id's and meta)
state.visibleColumns===[...]// all of the columns (with id's and meta)
state.visibleColumns===[...]// all of the columns (with id's and meta)
// etc.
// `makeTable` is a function that returns the standard table markup
returnmakeTable()
// So add some decoration!
return(
<div>
<customPivotBySelect/>
<customColumnHideShow/>
<customAnything/>
{makeTable()}
</div>
)
// The possibilities are endless!!!
}}
</ReactTable>
```
## 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!
## 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,
PaginationComponent:Component,
PreviousComponent:Component,
NextComponent:Component,
LoadingComponent:Component,
ExpanderComponent:Component
})
// Or change per instance
<ReactTable
TableComponent={Component},
TheadComponent={Component},
// etc...
/>
```
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 <a href="https://github.com/tannerlinsley/react-table/blob/master/src/index.js" target="\_parent">the source</a> for the component you wish to replace.
## Contributing
To suggest a feature, create an issue if it does not already exist.
If you would like to help develop a suggested feature follow these steps:
- Fork this repo
-`$ yarn`
-`$ yarn run storybook`
- Implement your changes to files in the `src/` directory
- View changes as you code via our <a href="https://github.com/storybooks/react-storybook" target="\_parent">React Storybook</a> `localhost:8000`
- Make changes to stories in `/stories`, or create a new one if needed
- Submit PR for review
#### Scripts
-`$ yarn run storybook` Runs the storybook server
-`$ yarn run test` Runs the test suite
-`$ yarn run prepublish` Builds the distributable bundle
-`$ yarn run docs` Builds the website/docs from the storybook for github pages
In case you would need to have both v6 and v7 in one app during the migration process (large codebase, complex use cases), you can either (1) fork and maintain your own local version of React Table v6 or (2) install the [`react-table-6` alias package](https://www.npmjs.com/package/react-table-6) for use alongside the `react-table` package.
Types for React Table are maintained externally by the Typescript community and are located at https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-table.
Because React Table is not written in Typescript and the types are not maintained by the core team, there are no guarantees around the types always being up to date or working perfectly. If this is an issue for you, please contribute to the community types and discuss solutions there.
React Table uses React Hooks both internally and externally for almost all of its configuration and lifecycle management. Naturally, this is what allows React Table to be headless and lightweight while still having a concise and simple API.
React Table is essentially a compatible collection of **custom React hooks**:
- Want your custom plugin hook listed here? [Submit a PR!](https://github.com/tannerlinsley/react-table/compare)
### Hook Usage
`useTable` is the **primary** hook used to build a React Table. It serves as the starting point for **every option and every plugin hook** that React Table supports. The options passed into `useTable` are supplied to every plugin hook after it in the order they are supplied, eventually resulting in a final `instance` object that you can use to build your table UI and interact with the table's state.
```js
constinstance=useTable(
{
data:[...],
columns:[...],
},
useGroupBy,
useFilters,
useSortBy,
useExpanded,
usePagination
)
```
### The stages of React Table and plugins
1.`useTable` is called. A table instance is created.
1. The `instance.state` is resolved from either a custom user state or an automatically generated one.
1. A collection of plugin points is created at `instance.hooks`.
1. Each plugin is given the opportunity to add hooks to `instance.hook`.
1. As the `useTable` logic proceeds to run, each plugin hook type is used at a specific point in time with each individual hook function being executed the order it was registered.
1. The final instance object is returned from `useTable`, which the developer then uses to construct their table.
This multi-stage process is the secret sauce that allows React Table plugin hooks to work together and compose nicely, while not stepping on each others toes.
To dive deeper into plugins, see Plugins](TODO) and the [Plugin Guide
### Plugin Hook Order & Consistency
The order and usage of plugin hooks must follow The Laws of Hooks, just like any other custom hook. They must always be unconditionally called in the same order.
> **NOTE: In the event that you want to programmatically enable or disable plugin hooks, most of them provide options to disable their functionality, eg. `options.disableSortBy`**
### Option Memoization
React Table relies on memoization to determine when state and side effects should update or be calculated. This means that every option you pass to `useTable` should be memoized either via `React.useMemo` (for objects) or `React.useCallback` (for functions).
`useAbsoluteLayout` is a plugin hook that adds support for headers and cells to be rendered as absolutely positioned `div`s (or other non-table elements) with explicit `width`. Similar to the `useBlockLayout` hook, this becomes useful if and when you need to virtualize rows and cells for performance.
**NOTE:** Although no additional options are needed for this plugin to work, the core column options `width`, `minWidth` and `maxWidth` are used to calculate column and cell widths and must be set. [See Column Options](#column-options) for more information on these options.
### Instance Properties
-`getTableBodyProps`
- **Usage Required**
- This core prop getter is required to to enable absolute layout for the table body
### Row Properties
-`getRowProps`
- **Usage Required**
- This core prop getter is required to to enable absolute layout for rows
### Cell Properties
-`getCellProps`
- **Usage Required**
- This core prop getter is required to to enable absolute layout for rows cells
### Header Properties
-`getHeaderProps`
- **Usage Required**
- This core prop getter is required to to enable absolute layout for headers
`useBlocklayout` is a plugin hook that adds support for headers and cells to be rendered as `inline-block``div`s (or other non-table elements) with explicit `width`. Similar to the `useAbsoluteLayout` hook, this becomes useful if and when you need to virtualize rows and cells for performance.
**NOTE:** Although no additional options are needed for this plugin to work, the core column options `width`, `minWidth` and `maxWidth` are used to calculate column and cell widths and must be set. [See Column Options](#column-options) for more information on these options.
### Row Properties
-`getRowProps`
- **Usage Required**
- This core prop getter is required to to enable absolute layout for rows
### Cell Properties
-`getCellProps`
- **Usage Required**
- This core prop getter is required to to enable absolute layout for rows cells
### Header Properties
-`getHeaderProps`
- **Usage Required**
- This core prop getter is required to to enable absolute layout for headers
`useColumnOrder` is a plugin hook that implements **basic column reordering**. As columns are reordered, their header groups are reverse-engineered so as to never have orphaned header groups.
### Table Options
The following options are supported via the main options object passed to `useTable(options)`
-`state.columnOrder: Array<ColumnId>`
- Optional
- Defaults to `[]`
- Any column ID's not represented in this array will be naturally ordered based on their position in the original table's `column` structure
-`initialState.columnOrder`
- Identical to the `state.columnOrder` option above
### Instance Properties
The following values are provided to the table `instance`:
-`setColumnOrder: Function(updater: Function | Array<ColumnId>) => void`
- Use this function to programmatically update the columnOrder.
-`updater` can be a function or value. If a `function` is passed, it will receive the current value and expect a new one to be returned.
`useExpanded` is the hook that implements **row expanding**. It is most often used with `useGroupBy` to expand grouped rows or on its own with nested `subRows` in tree-like `data` sets, but is not limited to these use-cases. It supports expanding rows both via internal table state and also via a hard-coded key on the raw row model.
### Table Options
The following options are supported via the main options object passed to `useTable(options)`
-`state.expanded: Array<pathKey: String>`
- Optional
- Must be **memoized**
- An array of expanded path keys.
- If a row's path key (`row.path.join('.')`) is present in this array, that row will have an expanded state. For example, if `['3']` was passed as the `expanded` state, the **4th row in the original data array** would be expanded.
- For nested expansion, you may **join the row path with a `.`** to expand sub rows. For example, if `['3', '3.5']` was passed as the `expanded` state, then the **6th subRow of the 4th row and also the 4th row of the original data array** would be expanded.
- This information is stored in state since the table is allowed to manipulate the filter through user interaction.
- See the [useTable hook](#table-options) for more details
-`manualExpandedKey: String`
- Optional
- Defaults to `expanded`
- This string is used as the key to detect manual expanded state on any given row. For example, if a raw data row like `{ name: 'Tanner Linsley', friends: [...], expanded: true}` was detected, it would always be expanded, regardless of state.
-`expandSubRows: Bool`
- Optional
- Defaults to `true`
- If set to `true`, expanded rows are rendered along with normal rows.
- If set to `false`, expanded rows will only be available through their parent row. This could be useful if you are implementing a custom expanded row view.
-`autoResetExpanded: Boolean`
- Defaults to `true`
- When `true`, the `expanded` state will automatically reset if any of the following conditions are met:
-`data` is changed
- To disable, set to `false`
- For more information see the FAQ ["How do I stop my table state from automatically resetting when my data changes?"](../faq.md#how-do-i-stop-my-table-state-from-automatically-resetting-when-my-data-changes)
### Instance Properties
The following properties are available on the table instance returned from `useTable`
-`rows: Array<Row>`
- An array of **sorted** rows.
### Row Properties
The following additional properties are available on every `row` object returned by the table instance.
- This function will toggle the expanded state of a row between `true` and `false` or, if an `isExpanded` boolean is passed to the function, it will be set as the new `isExpanded` value.
- Rows with a hard-coded `manualExpandedKey` (defaults to `expanded`) set to `true` are not affected by this function or the internal expanded state.
`useFilters` is the hook that implements **row filtering**.
### Table Options
The following options are supported via the main options object passed to `useTable(options)`
-`state.filters: Object<columnId: filterValue>`
- Must be **memoized**
- An object of columnId's and their corresponding filter values. This information is stored in state since the table is allowed to manipulate the filter through user interaction.
-`initialState.filters`
- Identical to the `state.filters` option above
-`manualFilters: Bool`
- Enables filter detection functionality, but does not automatically perform row filtering.
- Turn this on if you wish to implement your own row filter outside of the table (eg. server-side or manual row grouping/nesting)
-`disableFilters: Bool`
- Disables filtering for every column in the entire table.
-`defaultCanFilter: Bool`
- Optional
- Defaults to `false`
- If set to `true`, all columns will be filterable, regardless if they have a valid `accessor`
-`filterTypes: Object<filterKey: filterType>`
- Must be **memoized**
- Allows overriding or adding additional filter types for columns to use. If a column's filter type isn't found on this object, it will default to using the built-in filter types.
- For more information on filter types, see Filtering
-`autoResetFilters: Boolean`
- Defaults to `true`
- When `true`, the `filters` state will automatically reset if any of the following conditions are met:
-`data` is changed
- To disable, set to `false`
- For more information see the FAQ ["How do I stop my table state from automatically resetting when my data changes?"](./faq#how-do-i-stop-my-table-state-from-automatically-resetting-when-my-data-changes)
### Column Options
The following options are supported on any `Column` object passed to the `columns` options in `useTable()`
-`Filter: Function | React.Component => JSX`
- **Required**
- Receives the table instance and column model as props
- Must return valid JSX
- This function (or component) is used to render this column's filter UI, eg.
-`disableFilters: Bool`
- Optional
- If set to `true`, will disable filtering for this column
-`defaultCanFilter: Bool`
- Optional
- Defaults to `false`
- If set to `true`, this column will be filterable, regardless if it has a valid `accessor`
-`filter: String | Function`
- Optional
- Defaults to `text`
- The resolved function from the this string/function will be used to filter the this column's data.
- If a `string` is passed, the function with that name located on either the custom `filterTypes` option or the built-in filtering types object will be used. If
- If a `function` is passed, it will be used directly.
- For more information on filter types, see Filtering
- If a **function** is passed, it must be **memoized**
### Instance Properties
The following values are provided to the table `instance`:
-`rows: Array<Row>`
- An array of **filtered** rows.
-`preFilteredRows: Array<Row>`
- The array of rows **used right before filtering**.
- Among many other use-cases, these rows are directly useful for building option lists in filters, since the resulting filtered `rows` do not contain every possible option.
`useGroupBy` is the hook that implements **row grouping and aggregation**.
- Each column's `getGroupByToggleProps()` function can be used to generate the props needed to make a clickable UI element that will toggle the grouping on or off for a specific column.
- Instance and column-level `toggleGroupBy` functions are also made available for programmatic grouping.
### Table Options
The following options are supported via the main options object passed to `useTable(options)`
-`state.groupBy: Array<String>`
- Must be **memoized**
- An array of groupBy ID strings, controlling which columns are used to calculate row grouping and aggregation. This information is stored in state since the table is allowed to manipulate the groupBy through user interaction.
-`initialState.groupBy`
- Identical to the `state.groupBy` option above
-`manualGroupBy: Bool`
- Enables groupBy detection and functionality, but does not automatically perform row grouping.
- Turn this on if you wish to implement your own row grouping outside of the table (eg. server-side or manual row grouping/nesting)
- Allows overriding or adding additional aggregation functions for use when grouping/aggregating row values. If an aggregation key isn't found on this object, it will default to using the built-in aggregation functions
-`groupByFn: Function`
- Must be **memoized**
- Defaults to `defaultGroupByFn`
- This function is responsible for grouping rows based on the `state.groupBy` keys provided. It's very rare you would need to customize this function.
### Column Options
The following options are supported on any `Column` object passed to the `columns` options in `useTable()`
-`Aggregated: Function | React.Component => JSX`
- Optional
- Defaults to this column's `Cell` formatter
- Receives the table instance and cell model as props
- Must return valid JSX
- This function (or component) formats this column's value when it is being grouped and aggregated, eg. If this column was showing the number of visits for a user to a website and it was currently being grouped to show an **average** of the values, the `Aggregated` function for this column could format that value to `1,000 Avg. Visits`
- If a single `String` is passed, it must be the key of either a user defined or predefined `aggregations` function.
- If a tuple array of `[String, String]` is passed, both must be a key of either a user defined or predefined `aggregations` function.
- The first is used to aggregate raw values, eg. `sum`-ing raw values together
- The second is used to aggregate values that have already been aggregated, eg. `average`-ing the sums produced by the raw aggregation level
- If a `Function` is passed, this function will receive the `values`, original `rows` of those values, and an `isAggregated``Bool` of whether or not the values and rows have already been aggregated.
-`disableGroupBy: Boolean`
- Defaults to `false`
- If `true`, will disable grouping for this column.
### Instance Properties
The following values are provided to the table `instance`:
-`rows: Array<Row>`
- An array of **grouped and aggregated** rows.
-`preGroupedRows: Array<Row>`
- The array of rows originally used to create the grouped rows.
- This function is used to resolve any props needed for this column's UI that is responsible for toggling grouping when the user clicks it.
- You can use the `getGroupByToggleProps` hook to extend its functionality.
- Custom props may be passed. **NOTE: Custom props may override built-in sortBy props, so be careful!**
### Row Properties
The following properties are available on every `Row` object returned by the table instance.
-`groupById: String`
- The column ID for which this row is being grouped.
- Will be `undefined` if the row is an original row from `data` and not a materialized one from the grouping.
-`groupByVal: any`
- If the row is a materialized group row, this will be the grouping value that was used to create it.
-`values: Object`
- Similar to a regular row, a materialized grouping row also has a `values` object
- This object contains the **aggregated** values for this row's sub rows
-`subRows: Array<Row>`
- If the row is a materialized group row, this property is the array of materialized subRows that were grouped inside of this row.
-`depth: Int`
- If the row is a materialized group row, this is the grouping depth at which this row was created.
-`path: Array<String|Int>`
- Similar to normal `Row` objects, materialized grouping rows also have a path array. The keys inside it though are not integers like nested normal rows though. Since they are not rows that can be traced back to an original data row, they are given a unique path based on their `groupByVal`
- If a row is a grouping row, it will have a path like `['Single']` or `['Complicated', 'Anderson']`, where `Single`, `Complicated`, and `Anderson` would all be derived from their row's `groupByVal`.
-`isAggregated: Bool`
- Will be `true` if the row is an aggregated row
### Cell Properties
The following additional properties are available on every `Cell` object returned in an array of `cells` on every row object.
-`isGrouped: Bool`
- If `true`, this cell is a grouped cell, meaning it contains a grouping value and should usually display and expander.
-`isRepeatedValue: Bool`
- If `true`, this cell is a repeated value cell, meaning it contains a value that is already being displayed elsewhere (usually by a parent row's cell).
- Most of the time, this cell is not required to be displayed and can safely be hidden during rendering
-`isAggregated: Bool`
- If `true`, this cell's value has been aggregated and should probably be rendered with the `Aggregated` cell renderer.
`usePagination` is the hook that implements **row pagination**. It can be used for both client-side pagination or server-side pagination. For more information on pagination, see Pagination
> **NOTE** Some server-side pagination implementations do not use page index and instead use **token based pagination**! If that's the case, please use the `useTokenPagination` plugin instead.
### Table Options
The following options are supported via the main options object passed to `useTable(options)`
-`state.pageSize: Int`
- **Required**
- Defaults to `10`
- Determines the amount of rows on any given page
-`initialState.pageSize`
- Identical to the `state.pageSize` option above
-`state.pageIndex: Int`
- **Required**
- Defaults to `0`
- The index of the page that should be displayed via the `page` instance value
-`initialState.pageIndex`
- Identical to the `state.pageIndex` option above
-`pageCount: Int`
- **Required if `manualPagination` is set to `true`**
- If `manualPagination` is `true`, then this value used to determine the amount of pages available. This amount is then used to materialize the `pageOptions` and also compute the `canNextPage` values on the table instance.
-`manualPagination: Bool`
- Enables pagination functionality, but does not automatically perform row pagination.
- Turn this on if you wish to implement your own pagination outside of the table (eg. server-side pagination or any other manual pagination technique)
-`autoResetPage: Boolean`
- Defaults to `true`
- When `true`, the `expanded` state will automatically reset if `manualPagination` is `false` and any of the following conditions are met:
-`data` is changed
-`manualSortBy` is `false` and `state.sortBy` is changed
-`manualFilters` is `false` and `state.filters` is changed
-`manualGroupBy` is `false` and `state.groupBy` is changed
- To disable, set to `false`
- For more information see the FAQ ["How do I stop my table state from automatically resetting when my data changes?"](./faq#how-do-i-stop-my-table-state-from-automatically-resetting-when-my-data-changes)
-`paginateExpandedRows: Bool`
- Optional
- Only applies when using the `useExpanded` plugin hook simultaneously
- Defaults to `true`
- If set to `true`, expanded rows are paginated along with normal rows. This results in stable page sizes across every page.
- If set to `false`, expanded rows will be spliced in after pagination. This means that the total number of rows in a page can potentially be larger than the page size, depending on how many subrows are expanded.
### Instance Properties
The following values are provided to the table `instance`:
-`page: Array<row>`
- An array of rows for the **current** page, determined by the current `pageIndex` value.
-`pageCount: Int`
- If `manualPagination` is set to `false`, this is the total amount of pages available in the table based on the current `pageSize` value
- if `manualPagination` is set to `true`, this is merely the same `pageCount` option that was passed in the table options.
-`pageOptions: Array<Int>`
- An array of zero-based index integers corresponding to available pages in the table.
- This can be useful for generating things like select interfaces for the user to select a page from a list, instead of manually paginating to the desired page.
-`canPreviousPage: Bool`
- If there are pages and the current `pageIndex` is greater than `0`, this will be `true`
-`canNextPage:`
- If there are pages and the current `pageIndex` is less than `pageCount`, this will be `true`
-`gotoPage: Function(pageIndex)`
- This function, when called with a valid `pageIndex`, will set `pageIndex` to that value.
- If the aginateassed index is outside of the valid `pageIndex` range, then this function will do nothing.
-`previousPage: Function`
- This function decreases `state.pageIndex` by one.
- If there are no pages or `canPreviousPage` is false, this function will do nothing.
-`nextPage: Function`
- This function increases `state.pageIndex` by one.
- If there are no pages or `canNextPage` is false, this function will do nothing.
-`setPageSize: Function(pageSize)`
- This function sets `state.pageSize` to the new value.
- As a result of a pageSize change, a new `state.pageIndex` is also calculated. It is calculated via `Math.floor(currentTopRowIndex / newPageSize)`
`useResizeColumns` is a plugin hook that adds support for resizing headers and cells when using non-table elements for layout eg. the `useBlockLayout` and `useAbsoluteLayout` hooks. It even supports resizing column groups!
### Table Options
-`disableResizing: Bool`
- Defaults to `false`
- When set to `true`, resizing is disabled across the entire table
### Column Options
The core column options `width`, `minWidth` and `maxWidth` are used to calculate column and cell widths and must be set. [See Column Options](#column-options) for more information on these options.
-`disableResizing: Bool`
- Defaults to `false`
- When set to `true`, resizing is disabled for this column
### Header Properties
-`getResizerProps`
- **Usage Required**
- This core prop getter is required to to enable absolute layout for headers
-`canResize: Bool`
- Will be `true` if this column can be resized
-`isResizing: Bool`
- Will be `true` if this column is currently being resized
`useRowSelect` is the hook that implements **basic row selection**. For more information on row selection, see Row Selection
### Table Options
The following options are supported via the main options object passed to `useTable(options)`
-`state.selectedRowPaths: Set<RowPathKey>`
- Optional
- Defaults to `new Set()`
- If a row's path key (eg. a row path of `[1, 3, 2]` would have a path key of `1.3.2`) is found in this array, it will have a selected state.
-`initialState.selectedRowPaths`
- Identical to the `state.selectedRowPaths` option above
-`manualRowSelectedKey: String`
- Optional
- Defaults to `isSelected`
- If this key is found on the **original** data row, and it is true, this row will be manually selected
-`autoResetSelectedRows: Boolean`
- Defaults to `true`
- When `true`, the `expanded` state will automatically reset if any of the following conditions are met:
-`data` is changed
- To disable, set to `false`
- For more information see the FAQ ["How do I stop my table state from automatically resetting when my data changes?"](./faq#how-do-i-stop-my-table-state-from-automatically-resetting-when-my-data-changes)
### Instance Properties
The following values are provided to the table `instance`:
- If a row's path key (eg. a row path of `[1, 3, 2]` would have a path key of `1.3.2`) is found in this array, it will have the state of the value corresponding to that key.
- Individual row states can contain anything, but they also contain a `cellState` key, which provides cell-level state based on column ID's to every
**prepared** cell in the table.
-`initialState.rowState`
- Identical to the `state.rowState` option above
-`initialRowStateAccessor: Function`
- Optional
- This function may optionally return the initial state for a row.
- If this function is defined, it will be passed a `Row` object, from which you can return a value to use as the initial state, eg. `row => row.original.initialState`
-`autoResetRowState: Boolean`
- Defaults to `true`
- When `true`, the `rowState` state will automatically reset if any of the following conditions are met:
-`data` is changed
- To disable, set to `false`
- For more information see the FAQ ["How do I stop my table state from automatically resetting when my data changes?"](./faq#how-do-i-stop-my-table-state-from-automatically-resetting-when-my-data-changes)
### Instance Properties
The following values are provided to the table `instance`:
-`setRowState: Function(rowPath: Array<string>, updater: Function | Any) => void`
- Use this function to programmatically update the state of a row.
-`updater` can be a function or value. If a `function` is passed, it will receive the current value and expect a new one to be returned.
- Use this function to programmatically update the cell of a row.
-`updater` can be a function or value. If a `function` is passed, it will receive the current value and expect a new one to be returned.
### Row Properties
The following additional properties are available on every **prepared**`row` object returned by the table instance.
-`state: Object`
- This is the state object for each row, pre-mapped to the row from the table state's `rowState` object via `rowState[row.path.join('.')]`
- May also contain a `cellState` key/value pair, which is used to provide individual cell states to this row's cells
-`setState: Function(updater: Function | any)`
- Use this function to programmatically update the state of a row.
-`updater` can be a function or value. If a `function` is passed, it will receive the current value and expect a new one to be returned.
### Cell Properties
The following additional properties are available on every `Cell` object returned in an array of `cells` on every row object.
-`state: Object`
- This is the state object for each cell, pre-mapped to the cell from the table state's `rowState` object via `rowState[row.path.join('.')].cellState[columnId]`
-`setState: Function(updater: Function | any)`
- Use this function to programmatically update the state of a cell.
-`updater` can be a function or value. If a `function` is passed, it will receive the current value and expect a new one to be returned.
`useSortBy` is the hook that implements **row sorting**. It also support multi-sort (keyboard required).
- Multi-sort is enabled by default
- To sort the table via UI, attach the props generated from each column's `getSortByToggleProps()`, then click any of those elements.
- To multi-sort the table via UI, hold `shift` while clicking on any of those same elements that have the props from `getSortByToggleProps()` attached.
- To programmatically sort (or multi-sort) any column, use the `toggleSortBy` method located on the instance or each individual column.
### Table Options
The following options are supported via the main options object passed to `useTable(options)`
- An array of sorting objects. If there is more than one object in the array, multi-sorting will be enabled. Each sorting object should contain an `id` key with the corresponding column ID to sort by. An optional `desc` key may be set to true or false to indicated ascending or descending sorting for that column. This information is stored in state since the table is allowed to manipulate the filter through user interaction.
-`initialState.sortBy`
- Identical to the `state.sortBy` option above
-`manualSorting: Bool`
- Enables sorting detection functionality, but does not automatically perform row sorting. Turn this on if you wish to implement your own sorting outside of the table (eg. server-side or manual row grouping/nesting)
-`disableSortBy: Bool`
- Disables sorting for every column in the entire table.
-`defaultCanSort: Bool`
- Optional
- Defaults to `false`
- If set to `true`, all columns will be sortable, regardless if they have a valid `accessor`
-`disableMultiSort: Bool`
- Disables multi-sorting for the entire table.
-`isMultiSortEvent: Function`
- Allows to override default multisort behaviour(i.e. multisort applies when shift key is pressed), if this function is provided then returned boolean value from this function will make decision whether newly applied sort action will be considered as multisort or not.
- Receives `event` as argument.
-`maxMultiSortColCount: Number`
- Limit on max number of columns for multisort, e.g. if set to 3, and suppose table is sorted by `[A, B, C]` and then clicking `D` for sorting should result in table sorted by `[B, C , D]`
-`disableSortRemove: Bool`
- If true, the un-sorted state will not be available to columns once they have been sorted.
-`disableMultiRemove: Bool`
- If true, the un-sorted state will not be available to multi-sorted columns.
-`orderByFn: Function`
- Must be **memoized**
- Defaults to the built-in default orderBy function
- This function is responsible for composing multiple sorting functions together for multi-sorting, and also handles both the directional sorting and stable-sorting tie breaking. Rarely would you want to override this function unless you have a very advanced use-case that requires it.
-`sortTypes: Object<sortKey: sortType>`
- Must be **memoized**
- Allows overriding or adding additional sort types for columns to use. If a column's sort type isn't found on this object, it will default to using the built-in sort types.
- For more information on sort types, see Sorting
-`autoResetSortBy: Boolean`
- Defaults to `true`
- When `true`, the `sortBy` state will automatically reset if any of the following conditions are met:
-`data` is changed
- To disable, set to `false`
- For more information see the FAQ ["How do I stop my table state from automatically resetting when my data changes?"](./faq#how-do-i-stop-my-table-state-from-automatically-resetting-when-my-data-changes)
### Column Options
The following options are supported on any `Column` object passed to the `columns` options in `useTable()`
-`defaultCanSort: Bool`
- Optional
- Defaults to `false`
- If set to `true`, this column will be sortable, regardless if it has a valid `accessor`
-`disableSortBy: Bool`
- Optional
- Defaults to `false`
- If set to `true`, the sorting for this column will be disabled
-`sortDescFirst: Bool`
- Optional
- Defaults to `false`
- If set to `true`, the first sort direction for this column will be descending instead of ascending
-`sortInverted: Bool`
- Optional
- Defaults to `false`
- If set to `true`, the underlying sorting direction will be inverted, but the UI will not.
- This may be useful in situations where positive and negative connotation is inverted, eg. a Golfing score where a lower score is considered more positive than a higher one.
-`sortType: String | Function`
- Used to compare 2 rows of data and order them correctly.
- If a **function** is passed, it must be **memoized**
- String options: `basic`, `datetime`, `alphanumeric`. Defaults to `alphanumeric`.
- The resolved function from the this string/function will be used to sort the this column's data.
- If a `string` is passed, the function with that name located on either the custom `sortTypes` option or the built-in sorting types object will be used.
- If a `function` is passed, it will be used.
- For more information on sort types, see Sorting
### Instance Properties
The following values are provided to the table `instance`:
- This function can be used to programmatically toggle the sorting for this column.
- This function is similar to the `instance`-level `toggleSortBy`, however, passing a columnId is not required since it is located on a `Column` object already.
-`getSortByToggleProps: Function(props) => props`
- **Required**
- This function is used to resolve any props needed for this column's UI that is responsible for toggling the sort direction when the user clicks it.
- You can use the `getSortByToggleProps` hook to extend its functionality.
- Custom props may be passed. **NOTE: Custom props may override built-in sortBy props, so be careful!**
-`clearSorting: Function() => void`
- This function can be used to programmatically clear the sorting for this column.
-`isSorted: Boolean`
- Denotes whether this column is currently being sorted
-`sortedIndex: Int`
- If the column is currently sorted, this integer will be the index in the `sortBy` array from state that corresponds to this column.
- If this column is not sorted, the index will always be `-1`
-`isSortedDesc: Bool`
- If the column is currently sorted, this denotes whether the column's sort direction is descending or not.
- If `true`, the column is sorted `descending`
- If `false`, the column is sorted `ascending`
- If `undefined`, the column is not currently being sorted.
`useTable` is the root hook for React Table. To use it, pass it with an optionsobject with at least a `columns` and `data` value, followed by any React Table compatible hooks you want to use.
### Table Options
The following options are supported via the main options object passed to `useTable(options)`
-`columns: Array<Column>`
- Required
- Must be **memoized**
- The core columns configuration object for the entire table.
- Supports nested `columns` arrays via the column's `columns` key, eg. `[{ Header: 'My Group', columns: [...] }]`
-`data: Array<any>`
- Required
- Must be **memoized**
- The data array that you want to display on the table.
-`initialState: Object`
- Optional
- The initial state object for the table.
- Upon table initialization, this object is **merged over the table's `defaultState` object** (eg. `{...defaultState, ...initialState}`) that React Table and its hooks use to register default state to produce the final initial state object passed to the `React.useState` hook internally.
- With every action that is dispatched to the table's internal `React.useReducer` instance, this reducer is called and is allowed to modify the final state object for updating.
- It is passed the `newState`, `action`, and `prevState` and is expected to either return the `newState` or a modified version of the `newState`
- May also be used to "control" the state of the table, by overriding certain pieces of state regardless of the action.
- If you need to control part of the table state, this is the place to do it.
- This function is run on every single render, just like a hook and allows you to alter the final state of the table if necessary.
- You can use hooks inside of this function, but most of the time, we just suggest using `React.useMemo` to memoize your state overrides.
- See the FAQ ["How can I manually control the table state?"](./faq.md#how-can-i-manually-control-the-table-state) for a an example.
-`defaultColumn: Object`
- Optional
- Defaults to `{}`
- The default column object for every column passed to React Table.
- Column-specific properties will override the properties in this object, eg. `{ ...defaultColumn, ...userColumn }`
- This is particularly useful for adding global column properties. For instance, when using the `useFilters` plugin hook, add a default `Filter` renderer for every column, eg.`{ Filter: MyDefaultFilterComponent }`
-`initialRowStateKey: String`
- Optional
- Defaults to `initialState`
- This key is used to look for the initial state of a row when initializing the `rowState` for a`data` array.
- If the value located at `row[initialRowStateKey]` is falsey, `{}` will be used instead.
- Use this function to change how React Table detects unique rows and also how it constructs each row's underlying `path` property.
- Optional
- Must be **memoized**
- Defaults to `(row, relativeIndex) => relativeIndex`
- You may want to change this function if
- By default, it will use the `index` of the row within it's original array.
-`debug: Bool`
- Optional
- A flag to turn on debug mode.
- Defaults to `false`
### Column Options
The following options are supported on any column object you can pass to `columns`.
-`accessor: String | Function`
- **Required**
- This string/function is used to build the data model for your column.
- The data returned by an accessor should be **primitive** and sortable.
- If a string is passed, the column's value will be looked up on the original row via that key, eg. If your column's accessor is `firstName` then its value would be read from `row['firstName']`. You can also specify deeply nested values with accessors like `info.hobbies` or even `address[0].street`
- If a function is passed, the column's value will be looked up on the original row using this accessor function, eg. If your column's accessor is `row => row.firstName`, then its value would be determined by passing the row to this function and using the resulting value.
-`id: String`
- **Required if `accessor` is a function**
- This is the unique ID for the column. It is used by reference in things like sorting, grouping, filtering etc.
- If a **string** accessor is used, it defaults as the column ID, but can be overridden if necessary.
-`columns: Array<Column>`
- Optional
- A nested array of columns.
- If defined, the column will act as a header group. Columns can be recursively nested as much as needed.
-`Header: String | Function | React.Component => JSX`
- Optional
- Defaults to `() => null`
- Receives the table instance and column model as props
- Must either be a **string or return valid JSX**
- If a function/component is passed, it will be used for formatting the header value, eg. You can use a `Header` function to dynamically format the header using any table or column state.
-`Cell: Function | React.Component => JSX`
- Optional
- Defaults to `({ cell: { value } }) => String(value)`
- Receives the table instance and cell model as props
- Must return valid JSX
- This function (or component) is primarily used for formatting the column value, eg. If your column accessor returns a date object, you can use a `Cell` function to format that date to a readable format.
-`width: Int`
- Optional
- Defaults to `150`
- Specifies the width for the column (when using non-table-element layouts)
-`minWidth: Int`
- Optional
- Defaults to `0`
- Specifies the minimum width for the column (when using non-table-element layouts)
- Specifically useful when using plugin hooks that allow the user to resize column widths
-`maxWidth: Int`
- Optional
- Defaults to `0`
- Specifies the maximum width for the column (when using non-table-element layouts)
- Specifically useful when using plugin hooks that allow the user to resize column widths
### Instance Properties
The following properties are available on the table instance returned from `useTable`
-`state: Object`
- **Memoized** - This object reference will not change unless the internal table state is modified.
- This is the final state object of the table, which is the product of the `initialState`, internal table reducer and (optionally) a custom `reducer` supplied by the user.
- This function is used both internally by React Table, and optionally by you (the developer) to update the table state programmatically.
-`type: Actions[type] | String`
- The action type corresponding to what action being taken against the state.
-`...payload`
- Any other action data that is associated with the action
-`columns: Array<Column>`
- A **nested** array of final column objects, **similar in structure to the original columns configuration option**.
- See [Column Properties](#column-properties) for more information
-`flatColumns: Array<Column>`
- A **flat** array of all final column objects.
- See [Column Properties](#column-properties) for more information
-`headerGroups: Array<HeaderGroup>`
- An array of normalized header groups, each containing a flattened array of final column objects for that row.
- **Some of these headers may be materialized as placeholders**
- See [HeaderGroup Properties](#headergroup-properties) for more information
-`footerGroups: Array<HeaderGroup>`
- An array of normalized header groups, but in reverse order, each containing a flattened array of final column objects for that row.
- **Some of these headers may be materialized as placeholders**
- See [HeaderGroup Properties](#headergroup-properties) for more information
-`headers: Array<Column>`
- A **nested** array of final header objects, **similar in structure to the original columns configuration option, but rebuilt for ordering**
- Each contains the headers that are displayed underneath it.
- **Some of these headers may be materialized as placeholders**
- See [Column Properties](#column-properties) for more information
-`flatHeaders[] Array<Column>`
- A **flat** array of final header objects found in each header group.
- **Some of these headers may be materialized as placeholders**
- See [Column Properties](#column-properties) for more information
-`rows: Array<Row>`
- An array of **materialized row objects** from the original `data` array and `columns` passed into the table options
- See [Row Properties](#row-properties) for more information
-`getTableProps: Function(?props)`
- **Required**
- This function is used to resolve any props needed for your table wrapper.
- Custom props may be passed. **NOTE: Custom props will override built-in table props, so be careful!**
-`getTableBodyProps: Function(?props)`
- **Required**
- This function is used to resolve any props needed for your table body wrapper.
- Custom props may be passed. **NOTE: Custom props will override built-in table body props, so be careful!**
-`prepareRow: Function(Row)`
- **Required**
- This function is responsible for lazily preparing a row for rendering. Any row that you intend to render in your table needs to be passed to this function **before every render**.
- **Why?** Since table data could potentially be very large, it can become very expensive to compute all of the necessary state for every row to be rendered regardless if it actually is rendered or not (for example if you are paginating or virtualizing the rows, you may only have a few rows visible at any given moment). This function allows only the rows you intend to display to be computed and prepped with the correct state.
-`flatRows: Array<Row>`
- An array of all rows, including subRows which have been flattened into the order in which they were detected (depth first)
- This can be helpful in calculating total row counts that must include subRows
-`totalColumnsWidth: Int`
- This is the total width of all visible columns (only available when using non-table-element layouts)
- This function can be used to retrieve all necessary props to be placed on an `<input type='checkbox'>` component that will control the visibility of all columns
### HeaderGroup Properties
The following additional properties are available on every `headerGroup` object returned by the table instance.
-`headers: Array<Column>`
- **Required**
- The columns in this header group.
-`getHeaderGroupProps: Function(?props)`
- **Required**
- This function is used to resolve any props needed for this header group's row.
- You can use the `getHeaderGroupProps` hook to extend its functionality.
- Custom props may be passed. **NOTE: Custom props will override built-in table props, so be careful!**
-`getFooterGroupProps: Function(?props)`
- **Required**
- This function is used to resolve any props needed for this header group's footer row.
- You can use the `getFooterGroupProps` hook to extend its functionality.
- Custom props may be passed. **NOTE: Custom props will override built-in table props, so be careful!**
### Column Properties
The following properties are available on every `Column` object returned by the table instance.
-`id: String`
- The resolved column ID from either the column's `accessor` or the column's hard-coded `id` property
-`isVisible: Boolean`
- Whether the column should be currently visible or not.
- Columns that are not visible are still used for sorting, filtering, etc.
-`render: Function(type: String | Function | Component, ?props)`
- This function is used to render content with the added context of a column.
- The entire table `instance` will be passed to the renderer with the addition of a `column` property, containing a reference to the column
- If `type` is a string, will render using the `column[type]` renderer. React Table ships with default `Header` and `Footer` renderers. Other renderers like `Filter` and `Aggregated` are available via plugin hooks.
- If a function or component is passed instead of a string, it will be be passed the table instance and column model as props and is expected to return any valid JSX.
-`totalLeft: Int`
- This is the total width in pixels of all columns to the left of this column
- Specifically useful when using plugin hooks that allow the user to resize column widths
-`totalWidth: Int`
- This is the total width in pixels for this column (if it is a leaf-column) or or all of it's sub-columns (if it is a column group)
- Specifically useful when using plugin hooks that allow the user to resize column widths
-`getHeaderProps: Function(?props)`
- **Required**
- This function is used to resolve any props needed for this column's header cell.
- You can use the `getHeaderProps` hook to extend its functionality.
- Custom props may be passed. **NOTE: Custom props will override built-in table props, so be careful!**
-`getFooterProps: Function(?props)`
- **Required**
- This function is used to resolve any props needed for this column's footer cell.
- You can use the `getFooterProps` hook to extend its functionality.
- Custom props may be passed. **NOTE: Custom props will override built-in table props, so be careful!**
- This function can be used to retrieve all necessary props to be placed on an `<input type='checkbox'>` component that will control the visibility of this column.
### Row Properties
The following additional properties are available on every `row` object returned by the table instance.
-`cells: Array<Cell>`
- An array of `Cell` objects containing properties and functions specific to the row and column it belongs to.
- See [Cell Properties](#cell-properties) for more information
-`values: Object<columnId: any>`
- A map of this row's **resolved** values by columnId, eg. `{ firstName: 'Tanner', lastName: 'Linsley' }`
-`getRowProps: Function(?props)`
- **Required**
- This function is used to resolve any props needed for this row.
- You can use the `getRowProps` hook to extend its functionality.
- Custom props may be passed. **NOTE: Custom props will override built-in table props, so be careful!**
-`index: Int`
- The index of the original row in the `data` array that was passed to `useTable`. If this row is a subRow, it is the original index within the parent row's subRows array
-`original: Object`
- The original row object from the `data` array that was used to materialize this row.
-`path: Array<string>`
- This array is the sequential path of indices one could use to navigate to it, eg. a row path of `[3, 1, 0]` would mean that it is the **first** subRow of a parent that is the **second** subRow of a parent that is the **fourth** row in the original `data` array.
- This array is used with plugin hooks like `useExpanded` and `useGroupBy` to compute expanded states for individual rows.
-`subRows: Array<Row>`
- If subRows were detect on the original data object, this will be an array of those materialized row objects.
-`state: Object`
- The current state of the row. It's lifespan is attached to that of the original `data` array. When the raw `data` is changed, this state value is reset to the row's initial value (using the `initialRowStateKey` option).
- Can be updated via `instance.setRowState` or the row's `setState` function.
### Cell Properties
The following additional properties are available on every `Cell` object returned in an array of `cells` on every row object.
-`column: Column`
- The corresponding column object for this cell
-`row: Row`
- The corresponding row object for this cell
-`value: any`
- The **resolved** value for this cell.
- By default, this value is displayed on the table via the default `Cell` renderer. To override the way a cell displays
-`getCellProps: Function(?props)`
- **Required**
- This function is used to resolve any props needed for this cell.
- You can use the `getCellProps` hook to extend its functionality.
- Custom props may be passed. **NOTE: Custom props will override built-in table props, so be careful!**
-`render: Function(type: String | Function | Component, ?props)`
- **Required**
- This function is used to render content with the added context of a cell.
- The entire table `instance` will be passed to the renderer with the addition of `column`, `row` and `cell` properties, containing a reference to each respective item.
- If `type` is a string, will render using the `column[type]` renderer. React Table ships with a default `Cell` renderer. Other renderers like `Aggregated` are available via hooks like `useFilters`.
- If a function or component is passed instead of a string, it will be be passed the table instance and cell model as props and is expected to return any valid JSX.
`useTokenPagination` is the hook that **aids in implementing row pagination using tokens**. It is useful for server-side pagination implementations that use **tokens** instead of page index. For more information on pagination, see Pagination
React Table is a headless utility, which means out of the box, it doesn't render or supply any actual UI elements. You are in charge of utilizing the state and callbacks of the hooks provided by this library to render your own table markup. [Read this article to understand why React Table is built this way](https://medium.com/merrickchristensen/headless-user-interface-components-565b0c0f2e18). If you don't want to, then here's a quick rundown anyway:
- Separation of Concerns - Not that superficial kind you read about all the time. The real kind. React Table as a library honestly has no business being in charge of your UI. The look, feel, and overall experience of your table is what makes your app or product great. The less React Table gets in the way of that, the better!
- Maintenance - By removing the massive (and seemingly endless) API surface area required to support every UI use-case, React Table can remain small, easy-to-use and simple to update/maintain.
- Extensibility - UI presents countless edge cases for a library simply because it's a creative medium, and one where every developer does things differently. By not dictating UI concerns, React Table empowers the developer to design and extend the UI based on their unique use-case.
## The React Table instance
At the heart of every React Table is the `useTable` hook and the table `instance` object that it returns. This `instance` object contains everything you'll ever need to build a table and interact with its state. This includes, but is not limited to:
- Columns
- Materialized Data
- Sorting
- Filtering
- Grouping
- Pagination
- Expanded State
- Any functionality provided by custom plugin hooks, too!
## Rendering your own UI
As of React Table v7, **you the developer** are responsible for rendering your own UI, but don't let that intimidate you! Table UIs are fun and React Table makes it so easy to wire up your own table UI. The easiest way to learn how to build your own table UI is to [see some existing React Table examples](./examples.md)!
---
After reading about React Table's concepts, you should:
- **Simple** - All of these examples use automatic state management, meaning, they don't hoist any state out of the table or manually control anything. Start here for understanding the basics about how to build your table UI.
Below are some of the most frequently asked questions on how to use the React Table API to solve various table challenges you may encounter
<hr/>
## How can I manually control the table state?
Occasionally, you may need to override some of the table state from a parent component or from somewhere above the usage of `useTable`. In this case, you can turn to `useTable`'s `useControlledState` option. This hook function is run on every render and allows you an opportunity to override or change the final table state in a safe way.
For example, to control a table's `pageIndex` from a parent component:
> **It's important that the state override is done within a `useMemo` call to prevent the state variable from changing on every render. It's also extremely important that you always use the `state` in any dependencies to ensure that you do not block normal state updates.**
## How can I use the table state to fetch new data?
When managing your data externally or asynchronously (eg. server-side pagination/sorting/grouping/etc), you will need to fetch new data as the internal table state changes. With React Hooks, this is fantastically easier than it was before now that we have the `React.useEffect` hook. We can use this hook to "watch" the table state for specific changes and use those effects to trigger fetches for new data (or synchronize any other state you may be managing externally from your table component):
```js
functionTable({data,onFetchData}){
const{
state:{pageIndex,pageSize,sortBy,filters},
}=useTable({
data,
})
// When the these table states change, fetch new data!
React.useEffect(()=>{
onFetchData({pageIndex,pageSize,sortBy,filters})
},[fetchData,pageIndex,pageSize,sortBy,filters])
return</>
}
```
Using this approach, you can respond and trigger any type of side-effect using the table instance!
## How can I debounce rapid table state changes?
React Table has a few built-in side-effects of it's own (most of which are meant for resetting parts of the state when `data` changes). By default, these state side-effects are on and when their conditions are met, they immediately fire off actions that will manipulate the table state. Sometimes, this may result in multiple rapid rerenders (usually just 2, or one more than normal), and could cause any side-effects you have watching the table state to also fire multiple times in-a-row. To alleviate this edge-case, React Table exports a `useAsyncDebounce` function that will allow you to debounce rapid side-effects and only use the latest one.
A good example of this when doing server-side pagination and sorting, a user changes the `sortBy` for a table and the `pageIndex` is automatically reset to `0` via an internal side effect. This would normally cause our effect below to fire 2 times, but with `useAsyncDebounce` we can make sure our data fetch function only gets called once:
## How do I stop my table state from automatically resetting when my data changes?
Most plugins use state that _should_ normally reset when the data sources changes, but sometimes you need to suppress that from happening if you are filtering your data externally, or immutably editing your data while looking at it, or simply doing anything external with your data that you don't want to trigger a piece of table state to reset automatically.
For those situations, each plugin provides a way to disable the state from automatically resetting internally when data or other dependencies for a piece of state change. By setting any of them to `false`, you can stop the automatic resets from being triggered.
Here is an example of stopping basically every piece of state from changing as they normally do while we edit the `data` source for a table:
```js
const[data,setData]=React.useState([])
constskipPageResetRef=React.useRef()
constupdateData=newData=>{
// When data gets updated with this function, set a flag
// to disable all of the auto resetting
skipPageResetRef.current=true
setData(newData)
}
React.useEffect(()=>{
// After the table has updated, always remove the flag
skipPageResetRef.current=false
})
useTable({
...
autoResetPage:!skipPageReset,
autoResetExpanded:!skipPageReset,
autoResetGroupBy:!skipPageReset,
autoResetSelectedRows:!skipPageReset,
autoResetSortBy:!skipPageReset,
autoResetFilters:!skipPageReset,
autoResetRowState:!skipPageReset,
})
```
Now, when we update our data, the above table states will not automatically reset!
Some files were not shown because too many files have changed in this diff
Show More
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.