feat(useRowSelect): Improve usePagination integration - only select rows on current page #2585
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Currently, useRowSelect isn't all that smart about pagination -- the select all toggle will always select all rows, regardless of whether they're present on the page. While in some user flows this is the sensible behavior, in some cases it's desirable to only select the visible page's rows (this is what Gmail does, for example). If a user of React Table wants this feature, the would likely need to reimplement the useRowSelect plugin on their own.
Solution
My goal here was to maintain the same options provided by the library, so a completely optional and opt-in feature. This means adding a "AllPageRowsSelected" selected counterpart to "AllRowsSelected", and they can be implemented in the same way.
Other changes
I noticed two subtle bugs with useRowSelect that I addressed:
useExpanded
anduseRowSelect
impacted the rows that were selected. In order to operate the selection on the most current state of expanded rows, useExpanded needs to go first. Similarly, I noticed the same thing withusePagination
, row selection will only work correctly if itusePagination
is passed firstrow.subRows
property, but I'm pretty sure it should resolve to the instance'sgetSubRows
function (defaults torow => row.subRows
)Todo