react-data-grid icon indicating copy to clipboard operation
react-data-grid copied to clipboard

Updating selectedRows property on onRowClick event stops double click from working

Open neetinnagap opened this issue 3 years ago • 9 comments

I have a data grid setup like following:

<DataGrid
        rowKeyGetter={rowKeyGetter}
        columns={columns}
        rows={rows}
        onRowsChange={setRows}
        selectedRows={selectedRows}
        onSelectedRowsChange={setSelectedRows}
        rowRenderer={RowRenderer}
        onSelectedCellChange={selectedCellChange}
        onRowClick={rowClickHandler}
        rowHeight={30}
></DataGrid>

I want to set selected rows on row click and not on checkbox click:

  const [selectedRows, setSelectedRows] = useState<Set<number>>(() => new Set());
  function rowClickHandler(row: any) {
    let selectedRowsSet = new Set(selectedRows);
    if (selectedRowsSet.has(row.id)) {
      selectedRowsSet.delete(row.id);
    } else {
      selectedRowsSet.add(row.id);  
    }
    setSelectedRows(selectedRowsSet);
  }

But the above function disables functionality for double click to edit cell. I think it may be due to the state change that occurs when I call the setSelectedRows function to update selected row.

Is there any way in which I can click rows for selection and double click for cell edit to work ?

neetinnagap avatar Jul 29 '21 09:07 neetinnagap

I have the same requirement i want to stop propagating row click on click of checkbox. Also i would like to see the checkbox selected values.

theone3nu avatar Aug 08 '21 09:08 theone3nu

i have the same problem.

onRowClick and on RowDoubleClick are not working together.

ghost avatar Sep 21 '21 11:09 ghost

@neetinnagap can you create a codesandbox example?

amanmahajan7 avatar Sep 21 '21 16:09 amanmahajan7

Screenshot_20210921-204907.png

It was my workaround to handle Double click. Look at Screenshot

A Timer and Trigger Double click manually

It would be nicer If the grid can handle it . .

ghost avatar Sep 21 '21 18:09 ghost

@amanmahajan7

it would be nicer and also important to have an event for onCellNavigate or something like that.

Background: You always need the currently active cell - either I activate it with a click or with the keyboard - and in this case the onCellNavigate event should be triggered. Independent of onRowClick

OnRowDoubleClick should also work independently of onRowClick too.

Thank you for the great job.

ghost avatar Sep 23 '21 10:09 ghost

@theone3nu did you find the solution to stop event propagation when you select checkbox?

Karpengold avatar Jun 15 '22 13:06 Karpengold

Maybe related to this Issue: I had some problems with onSelectedCellChange wich causes the cell editor to go out of edit mode. Finnally I found out, that its triggered by the rerender because I stored the position inside the state object. When using onSelectedCellChange{(e)=>{this.selectedCell = e}} instead of setState it works fine for me.

nikiosna avatar Jun 22 '22 12:06 nikiosna