[useSort] Provide API to clear sorting at column level (#1476)

* [useSort] Provide API to clear sorting at column level

* updated docs
This commit is contained in:
gargroh 2019-08-28 22:21:04 +05:30 committed by Tanner Linsley
parent f4b165d378
commit 8742ce39c2
2 changed files with 14 additions and 1 deletions

View File

@ -458,6 +458,8 @@ The following properties are available on every `Column` object returned by the
- 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`

View File

@ -173,7 +173,18 @@ function useMain(instance) {
if (column.canSort) {
column.toggleSortBy = (desc, multi) =>
toggleSortBy(column.id, desc, multi)
toggleSortBy(column.id, desc, multi);
column.clearSorting = () => {
return setState(old => {
const { sortBy } = old;
const newSortBy = sortBy.filter(d => d.id !== column.id);
return {
...old,
sortBy: newSortBy,
}
}, actions.sortByChange);
};
}
column.getSortByToggleProps = props => {