diff --git a/README.md b/README.md index 97196b2..fb2b19b 100644 --- a/README.md +++ b/README.md @@ -191,7 +191,7 @@ import { - [Row Selection](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/row-selection) - [Expanding](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/expanding) - [Sub Components](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/sub-components) - - [Editable Data](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/editable-cells) + - [Editable Data](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/editable-data) - Controlled - [Pagination (Controlled)](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/pagination-controlled) @@ -591,6 +591,11 @@ The following options are supported via the main options object passed to `useTa - Disables sorting for every column in the entire table. - `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 presssed), 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` diff --git a/examples/editable-data/README.md b/examples/editable-data/README.md index 12dead0..1ef271b 100644 --- a/examples/editable-data/README.md +++ b/examples/editable-data/README.md @@ -2,5 +2,5 @@ This project was bootstrapped with [Create React App](https://github.com/faceboo You can: -- [Open this example in a new CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/basic) +- [Open this example in a new CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/editable-data) - `yarn` and `yarn start` to run and edit the example diff --git a/examples/expanding/README.md b/examples/expanding/README.md index 12dead0..a73dce3 100644 --- a/examples/expanding/README.md +++ b/examples/expanding/README.md @@ -2,5 +2,5 @@ This project was bootstrapped with [Create React App](https://github.com/faceboo You can: -- [Open this example in a new CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/basic) +- [Open this example in a new CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/expanding) - `yarn` and `yarn start` to run and edit the example diff --git a/examples/filtering/README.md b/examples/filtering/README.md index 12dead0..7b4d95a 100644 --- a/examples/filtering/README.md +++ b/examples/filtering/README.md @@ -2,5 +2,5 @@ This project was bootstrapped with [Create React App](https://github.com/faceboo You can: -- [Open this example in a new CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/basic) +- [Open this example in a new CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/filtering) - `yarn` and `yarn start` to run and edit the example diff --git a/examples/grouping/README.md b/examples/grouping/README.md index 12dead0..24e30c3 100644 --- a/examples/grouping/README.md +++ b/examples/grouping/README.md @@ -2,5 +2,5 @@ This project was bootstrapped with [Create React App](https://github.com/faceboo You can: -- [Open this example in a new CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/basic) +- [Open this example in a new CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/grouping) - `yarn` and `yarn start` to run and edit the example diff --git a/examples/pagination-controlled/README.md b/examples/pagination-controlled/README.md index 12dead0..156c20a 100644 --- a/examples/pagination-controlled/README.md +++ b/examples/pagination-controlled/README.md @@ -2,5 +2,5 @@ This project was bootstrapped with [Create React App](https://github.com/faceboo You can: -- [Open this example in a new CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/basic) +- [Open this example in a new CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/pagination-controlled) - `yarn` and `yarn start` to run and edit the example diff --git a/examples/pagination/README.md b/examples/pagination/README.md index 12dead0..efedd93 100644 --- a/examples/pagination/README.md +++ b/examples/pagination/README.md @@ -2,5 +2,5 @@ This project was bootstrapped with [Create React App](https://github.com/faceboo You can: -- [Open this example in a new CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/basic) +- [Open this example in a new CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/pagination) - `yarn` and `yarn start` to run and edit the example diff --git a/examples/row-selection/README.md b/examples/row-selection/README.md index 12dead0..2b4ca04 100644 --- a/examples/row-selection/README.md +++ b/examples/row-selection/README.md @@ -2,5 +2,5 @@ This project was bootstrapped with [Create React App](https://github.com/faceboo You can: -- [Open this example in a new CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/basic) +- [Open this example in a new CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/row-selection) - `yarn` and `yarn start` to run and edit the example diff --git a/examples/sorting/README.md b/examples/sorting/README.md index 12dead0..82f3ed1 100644 --- a/examples/sorting/README.md +++ b/examples/sorting/README.md @@ -2,5 +2,5 @@ This project was bootstrapped with [Create React App](https://github.com/faceboo You can: -- [Open this example in a new CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/basic) +- [Open this example in a new CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/sorting) - `yarn` and `yarn start` to run and edit the example diff --git a/examples/sub-components/README.md b/examples/sub-components/README.md index 12dead0..1c657c4 100644 --- a/examples/sub-components/README.md +++ b/examples/sub-components/README.md @@ -2,5 +2,5 @@ This project was bootstrapped with [Create React App](https://github.com/faceboo You can: -- [Open this example in a new CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/basic) +- [Open this example in a new CodeSandbox](https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/sub-components) - `yarn` and `yarn start` to run and edit the example diff --git a/src/plugin-hooks/useSortBy.js b/src/plugin-hooks/useSortBy.js index 4323ae3..773d323 100755 --- a/src/plugin-hooks/useSortBy.js +++ b/src/plugin-hooks/useSortBy.js @@ -31,6 +31,8 @@ const propTypes = { manualSorting: PropTypes.bool, disableSorting: PropTypes.bool, disableMultiSort: PropTypes.bool, + isMultiSortEvent: PropTypes.func, + maxMultiSortColCount: PropTypes.number, disableSortRemove: PropTypes.bool, disableMultiRemove: PropTypes.bool, } @@ -55,6 +57,8 @@ function useMain(instance) { disableSortRemove, disableMultiRemove, disableMultiSort, + isMultiSortEvent = (e) => e.shiftKey, + maxMultiSortColCount = Number.MAX_SAFE_INTEGER, hooks, state: [{ sortBy }, setState], plugins, @@ -128,6 +132,8 @@ function useMain(instance) { desc: hasDescDefined ? desc : sortDescFirst, }, ] + // Take latest n columns + newSortBy.splice(0, newSortBy.length - maxMultiSortColCount); } else if (action === 'toggle') { // This flips (or sets) the newSortBy = sortBy.map(d => { @@ -177,7 +183,7 @@ function useMain(instance) { e.persist() column.toggleSortBy( undefined, - !instance.disableMultiSort && e.shiftKey + !instance.disableMultiSort && isMultiSortEvent(e) ) } : undefined, @@ -246,7 +252,7 @@ function useMain(instance) { // If there are sub-rows, sort them sortedData.forEach(row => { - if (!row.subRows) { + if (!row.subRows || row.subRows.length <= 1) { return } row.subRows = sortData(row.subRows)