79470776

Date: 2025-02-26 18:52:08
Score: 1
Natty:
Report link

When using a custom onRowSelectionChange, you must manually manage the rowsSelected state.

To ensure the checkboxes update correctly, add the rowsSelected option and pass selectedItems as its value.

An example can be found in the mui-datatables selectable-rows example.

A snippet

const options = {
  // Other options...

  // The custom rowsSelected that you missed
  rowsSelected: this.state.rowsSelected,

  onRowSelectionChange: (rowsSelectedData, allRows, rowsSelected) => {
    console.log(rowsSelectedData, allRows, rowsSelected);
    this.setState({ rowsSelected: rowsSelected });
  },
  // ...
};

Reference: https://github.com/gregnb/mui-datatables/blob/05ed8fc0289177c1a7283ca7d1b3ff996c79a9ef/examples/selectable-rows/index.js

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Starts with a question (0.5): When
  • Low reputation (0.5):
Posted by: Andreas