diff --git a/docs/api.md b/docs/api.md index 67c49eb..890de34 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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` diff --git a/src/plugin-hooks/useSortBy.js b/src/plugin-hooks/useSortBy.js index 25dcd53..e458817 100755 --- a/src/plugin-hooks/useSortBy.js +++ b/src/plugin-hooks/useSortBy.js @@ -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 => {