'Select all' also selects disabled checkboxes / rows
Describe the bug A disabled checkbox can't be checked normally, but when you click 'select all', the disabled checkboxes are selected. The header bar indicates the selected rows as well.
To Reproduce Add 'selection: true', and something like
selectionProps: (rowData) => ({
disabled: rowData.active === 'no'
})
Click the 'select all'.
Expected behavior Disabled rows can never be selected, not on checkbox-click, and not with 'select all'
Screenshots
(2 rows, disabled from selecting)
(after 'select all')
Desktop (please complete the following information):
- MT version 1.39.0
+1
What is the solution for this issue?
Issue 854 is marked in this ticket and closed, similarly issue 854 is closed by marking duplicate of issue 686.
I'm also facing this issue, 'select All' in header is selecting disabled records as well.
It's been almost a year since this issue was reported. What's the solution for this?
PRs are welcome
i do something like this.
selectionProps: (rowData) => {
const checked = rowData.active === 'no' ? {checked: false} : {};
return {
disabled: rowData.active === 'no',
...checked
}
}
but in selected records it is included
@code404sg Hi, thanks for the tips, but this is not reset the selectioned values for the table. Correct?
@KannarFr yes. i found another solution but select all is the problem.
when you select all the count selected is all. and when you deselect/select on the record the total selected record is correct.
selectionProps: rowData => {
const checked = rowData.id === 1 ? {checked: false} : {}
// add this code
if(rowData.id === 1){
rowData.tableData['checked'] = false;
}
return {
disabled: rowData.id === 1,
color: 'secondary',
...checked
}
}
guys can you help me how can i pull request? i found a solution. i dont know how can i contribute
in src/utils/data-manager.js in line 213
from this d.tableData.checked = checked; to this row.tableData.checked = row.tableData.disabled ? false : checked;
and in the selectionProps do this ` selectionProps: rowData => { rowData.tableData.disabled = rowData.name === 'A1';
return {
disabled: rowData.name === 'A1';
}
} `
process is i add another node for the disabled checkbox to check if this is a disabled i fork the project you can view here https://github.com/code404sg/material-table
@mbrn created a pull request out of @code404sg 's changes here https://github.com/mbrn/material-table/pull/1787 need review
Working workaround as higher order component:
import MaterialTable from "material-table";
import MTableToolbar from "material-table/dist/components/m-table-toolbar"
const withSelectAllFix = Component => ({components, options, enabledSelectionFilter, ...props}) => {
const selectionProps = rowData => {
if (enabledSelectionFilter(rowData)) {
return {}
}
else return {
disabled: true,
checked: false
}
};
const Toolbar = ({selectedRows, ...toolbarProps}) => {
return <MTableToolbar selectedRows={selectedRows.filter(enabledSelectionFilter)} {...toolbarProps}/>
};
const fixedComponents = Object.assign({}, components, {Toolbar});
const fixedOptions = Object.assign({}, options, {selectionProps});
return <Component components={fixedComponents} options={fixedOptions} {...props}/>
};
const FixedMaterialTable = withSelectAllFix(MaterialTable);
// And example usage wrapped in Playground component:
const Playground = props =>
<FixedMaterialTable
columns={[{
title: 'Sample Name',
field: 'sampleName'
}]}
data={[
{
sampleName: 'abc'
},
{
sampleName: 'cde'
},
{
sampleName: 'efg'
},
{
sampleName: 'ghi'
},
]}
enabledSelectionFilter={rowData => rowData.sampleName.includes('e')}
options={{
selection: true
}}
/>;
export default Playground;
Here is the solution, although there select all gets a little buggy, not sure how to work around that:
https://stackblitz.com/edit/react-9prvyj
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You can reopen it if it required.
Any update for this issue ?
It is still broken, it is not documented either.
On Mon, Jan 18, 2021 at 1:38 AM FreeWheel [email protected] wrote:
Any update for this issue ?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mbrn/material-table/issues/686#issuecomment-762120332, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABHBBI7GKEUGEAYVDU72TYTS2P6RVANCNFSM4HVAAYXA .
-- Jesse Willard 347.741.0404 @jessewillardcom
The issue as shown in https://stackblitz.com/edit/react-9prvyj is not fool proof for paginated tables. Although a good attempt. When can we expect a fix for this?
Any news about that problem? Anyone found any solution or it's going to be a fix in program?
the checkbox "select all" can be disabled?
This is still an issue. I just ended up adding my own checkbox as first columns
Why was this closed? Its still broken