including key of rowKeyGetter on the onRowsChange handler

This issue has been tracked since 2023-02-05.

Use case

I am feeding initial data from server and enabling editing for some columns. I want to track the changes as and when any of the cell is edited. A simple useState should help me with that where I will be storing Map of key with row Id and and object of updated key/value pairs.

eg
Map { id1: { name: "Bobby", age:22 }} // there are more columns, name and age are only cells updated for row with that id.

Why ?
I will later use event handlers like discard changes, save changes.
For Save changes handler, I would want to pass the list of id 's back to the server to make the mutation cal.

Note:

  • idx is not useful in this case.
  • I could still access the value by using index from the second arg in onRowsChanged and the newly updated row. But, I feel this should be something ready available to consume from the API // something like
    updatedRows[RowsChangeData[indexes][0]]]

Proposed solution

Pass the key to the onRowsChanged handler if the user have used rowKeyGetter.

function rowKeyGetter(row) {
  return row.id;
}
export interface CalculatedColumn<TRow, TSummaryRow = unknown,KeyT> extends Column<TRow, TSummaryRow> {
  readonly idx: number;
  .....other props
  readonly key?: KeyT;  // optionally add this value if the user has provided a rowKeyGetter function 
}

or maybe pass as a sepearte key

    onRowsChange(updatedRows, {
      indexes: [rawRowIdx],
      column,
      key: getRowGetterkey(row) // optionally add this value if the user has provided a rowKeyGetter function
    });

If it sounds good, I can send a pr If you'd like.

More Details About Repo
Owner Name adazzle
Repo Name react-data-grid
Full Name adazzle/react-data-grid
Language TypeScript
Created Date 2015-03-06
Updated Date 2023-03-23
Star Count 5922
Watcher Count 129
Fork Count 2072
Issue Count 161

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date