material-table icon indicating copy to clipboard operation
material-table copied to clipboard

'Select all' also selects disabled checkboxes / rows

Open rnacken opened this issue 7 years ago • 19 comments

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 image (2 rows, disabled from selecting) image (after 'select all')

Desktop (please complete the following information):

  • MT version 1.39.0

rnacken avatar Jun 06 '19 10:06 rnacken

+1

AugustoCalaca avatar Jun 07 '19 01:06 AugustoCalaca

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.

mrafivyr avatar Jan 02 '20 11:01 mrafivyr

It's been almost a year since this issue was reported. What's the solution for this?

ahfontaine avatar Mar 05 '20 16:03 ahfontaine

PRs are welcome

AugustoCalaca avatar Mar 06 '20 14:03 AugustoCalaca

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 avatar Mar 13 '20 07:03 code404sg

@code404sg Hi, thanks for the tips, but this is not reset the selectioned values for the table. Correct?

KannarFr avatar Mar 14 '20 17:03 KannarFr

@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 } }

code404sg avatar Mar 16 '20 01:03 code404sg

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

code404sg avatar Mar 16 '20 02:03 code404sg

@mbrn created a pull request out of @code404sg 's changes here https://github.com/mbrn/material-table/pull/1787 need review

gsstar9028 avatar Apr 01 '20 20:04 gsstar9028

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;

lbiernot avatar Jun 23 '20 09:06 lbiernot

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

jessewillardcom avatar Aug 27 '20 15:08 jessewillardcom

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.

stale[bot] avatar Nov 25 '20 15:11 stale[bot]

Any update for this issue ?

freewheel70 avatar Jan 18 '21 09:01 freewheel70

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

jessewillardcom avatar Jan 19 '21 12:01 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?

dheerajsah avatar Mar 02 '21 19:03 dheerajsah

Any news about that problem? Anyone found any solution or it's going to be a fix in program?

flaviodelgrosso avatar Apr 01 '21 16:04 flaviodelgrosso

the checkbox "select all" can be disabled?

AlvaroCarrillo avatar Jun 22 '21 19:06 AlvaroCarrillo

This is still an issue. I just ended up adding my own checkbox as first columns

soumyaDivami avatar Jun 30 '21 14:06 soumyaDivami

Why was this closed? Its still broken

TylerKelso avatar Nov 25 '24 22:11 TylerKelso