gregnb / gregnb/mui-datatables
Clicking header cell bypasses checks inside of isRowSelectable
- Dominant language
- JavaScript
- Stars
- 2.7k
- Forks
- 906
- PR merge metrics
- No merged PRs in 30d
Description
Say I wanted to limit the number of checked rows to 5. I could do that using isRowSelectable, and it works - until I check the checkbox header. Example:
https://codesandbox.io/s/muidatatables-custom-toolbar-qg0i9
## Expected Behavior
Selecting the header would not bypass checks made inside of isRowSelectable.
## Current Behavior
When the checkbox header is selected, it runs isRowSelectable for each row, but for each function call it uses the prevSelectedRows object from the previous state and doesn't factor in that a row may have been added. This means it can bypass limits/checks a developer has placed inside of isRowSelected.
The code should instead create a copy of the selectedRows object and update it after each isRowSelected call to add the row if it can be selected.
## Steps to Reproduce (for bugs)
1. Open https://codesandbox.io/s/muidatatables-custom-toolbar-qg0i9
2. Try to select more than 5 rows, see that the limit is in place.
3. Toggle the header checkbox a few times and see that it allows you to select more than 5 rows.
## Your Environment
| Tech | Version |
|--------------|---------|
| Material-UI | 3.2.2 |
| MUI-datatables | 2.9.0 |
| React | 16.4 |
| browser | Crome |
| etc | |
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.