When using enableCellSelect={true} the onRowSelect doesn't work
Hello everyone, I'm trying to get the react data grid working with cell edition capabilities and row selection as well, but it doesn't work as expected. Here is the code:
<ReactDataGrid
ref={this.gridRefBuilder} minHeight={350} enableCellSelect={true}
rowKey='idinventory' columns={columns} rowGetter={this.rowGetterInventory}
onRowSelect={this.onRowSelectInventory}
enableRowSelect='multi' onRowUpdated={this.onHandleUpdateInventory}
rowsCount={this.props.inventories ? this.props.inventories.length : 0}/>
In the very beginning it seemed not to be the big deal, but the method onRowSelectInventory is not called at all if enableCellSelect={true}, which is frustrating because I need to tell a toolbar if a row is selected. By the way if enableCellSelect={true} the first top left cell appears selected.
Is there anybody with a solution? It's been over a week trying to get a solution over the internet and every possible solution I found tells only nonsenses, because the method doesn't work for real.
To clarify are you trying to select rows with the checkbox or simply clicking the row?
To clarify are you trying to select rows with the checkbox or simply clicking the row?
just by selecting the row...
Hi @soma83.
Row selection and cell selection are different things.
Cell selection is used when you want the ability to select a cell (makes sense when you have a editable grid or you want to navigate in the grid).
Row selection is the ability to select a few rows to do something (for example to save data only for those rows). In our use case that is achieved with a checkbox for each row in the grid.
To enable row selection a few steps need to be done, specify a onRowSelect callback is not enough. You can check this example where an explanation is given about the way row selection needs to be implemented.
You will need to inject a rowSelection prop to specify the kind of selection you want. An example of that shape would be:
{
showCheckbox: true,
enableShiftSelect: true,
onRowsSelected: this.onRowsSelected,
onRowsDeselected: this.onRowsDeselected,
selectBy: {
indexes: this.state.selectedIndexes
}
}