Select On Row Click
Usage#
import MaterialTable from "@material-table/core";
<MaterialTable
// ...
components={{
Row: (props) => {
return <MTableBodyRow {...props} onRowClick={onRowClicked} />;
},
}}
options={{
selection: true,
}}
/>;
Live Demo#
note
See here for more on the GLOBAL_VARS
we use in our demos
Live Editor
function SelectionOnRowClick() {const [data, setData] = useState(SELECTION_DATA);return (<MaterialTabledata={data}columns={SELECTION_COLS}options={{selection: true,}}onRowClick={(event, rowData) => {// Copy row data and set checked stateconst rowDataCopy = { ...rowData };rowDataCopy.tableData.checked = !rowDataCopy.tableData.checked;// Copy data so we can modify itconst dataCopy = [...data];// Find the row we clicked and update it with `checked` propdataCopy[rowDataCopy.tableData.id] = rowDataCopy;setData(dataCopy);}}/>);}
Result