From dc629aedfa98a9b6a165f1603bbfe5656935ac4e Mon Sep 17 00:00:00 2001 From: Marian Lumba Date: Thu, 8 Aug 2019 16:11:32 -0400 Subject: [PATCH 1/3] updating code sandbox links (#1437) --- README.md | 2 +- examples/editable-data/README.md | 2 +- examples/expanding/README.md | 2 +- examples/filtering/README.md | 2 +- examples/grouping/README.md | 2 +- examples/pagination-controlled/README.md | 2 +- examples/pagination/README.md | 2 +- examples/row-selection/README.md | 2 +- examples/sorting/README.md | 2 +- examples/sub-components/README.md | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0ec9ebb..01c1272 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) 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 From d4303a2468b37bd300bc2994aee201063fae5a02 Mon Sep 17 00:00:00 2001 From: gargroh <42495927+gargroh@users.noreply.github.com> Date: Wed, 14 Aug 2019 22:17:02 +0530 Subject: [PATCH 2/3] [v7] useSort - Multisort functionality: Limit max cols and optional shift key (#1433) * [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 --- README.md | 5 +++++ src/plugin-hooks/useSortBy.js | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 01c1272..32c3912 100644 --- a/README.md +++ b/README.md @@ -587,6 +587,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/src/plugin-hooks/useSortBy.js b/src/plugin-hooks/useSortBy.js index 4323ae3..1c0daa8 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, From c77ffacdc9975a6ef8c8d329da793f5f2d3add27 Mon Sep 17 00:00:00 2001 From: Eugene Krevenets Date: Thu, 15 Aug 2019 16:11:12 +0200 Subject: [PATCH 3/3] improve(sort): don't sort subrows less than 2 characters (#1449) it improves performance because cuts a lot of sorting manipulations --- src/plugin-hooks/useSortBy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugin-hooks/useSortBy.js b/src/plugin-hooks/useSortBy.js index 1c0daa8..773d323 100755 --- a/src/plugin-hooks/useSortBy.js +++ b/src/plugin-hooks/useSortBy.js @@ -252,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)