function passed to onRowsSelect option gets called with strange results
When I pass any function other than console.log to onRowsSelect, the checkbox never gets checked and the behavior is very odd
Expected Behavior
I would expect the function to get called and the checkbox to appear checked after.
Current Behavior
function doesn't get called
Steps to Reproduce (for bugs)
> const options = {
> filter: true,
> print: false,
> filterType: 'dropdown',
> responsive: 'stacked',
> selectableRows: true,
> customToolbar: () => { return <CustomToolbar history={this.props.history} /> },
> onRowsSelect: (_, rowsSelected) => {
> console.log(rowsSelected)
> this.setState({ rowsSelected })
> }
> };
..
<MUIDataTable
title={"Template list"}
data={data}
columns={['Name','Description','Public','Output','Created', 'Edit', 'Delete']}
options={options}
/>
1. 2. 3. 4.
Your Environment
| Tech | Version |
|---|---|
| Material-UI | latest |
| MUI-datatables | latest |
| React | |
| browser | |
| etc |
It seems if you setState within the onRowsSelected function it doesn't allow you to check the checkboxes, or it does, but it goes from true to false before the check is highlighted.
This ended up working for me, not pretty but got the job done: onRowSelect = (currSelected, _) => { const data = {...currSelected[0]}; const selected = [...this.state.rowsSelected]; var index = selected.indexOf(data.index); if (index > -1) selected.splice(index, 1) else selected.push(data.index); this.setState({ rowsSelected: selected, }); };
My issue is getting the selected rows into state because I want to pass them.
That's what I did with the code above. It gets the indexes of the rows into state and then I use those later when a button is pressed in the custom selected toolbar
Ok, I've updated mine to be like what you have there and my checkboxes don't work.
You take the setState code out and the checkboxes work, also the select all checkboxes cause an error which I have raised as part of another issue here, #128
Going to look into both these issues this weekend. Thanks for raising them guys
Could do something like this:
rowsSelected: this.state.rowsSelected,
onRowsSelect: (rowsSelected, allRows) => {
const selected = allRows.map(item => item.index);
this.setState({
rowsSelected: selected,
});
},
Anyway, going to close the issue since it is not an issue the callback function simply fires successfully