function SelectOutsideOfTable() {
const [data, setData] = useState([
{
fruit: "Apple",
id: 0,
},
{
fruit: "Orange",
id: 1,
},
]);
const toggleRowChecked = (row) => {
return (row.tableData && row.tableData.checked ? !row.tableData.checked : true);
}
const toggleSelectAll = () => {
const newData = data.map((row) => ({
...row,
tableData: {
checked: toggleRowChecked(row),
},
}));
setData(newData);
};
const columns = [
{
title: "Fruit",
field: "fruit",
},
{
title: "ID",
field: "id",
},
];
return (
<div>
<button onClick={toggleSelectAll}>Toggle Selection</button>
<MaterialTable
title="Select All External"
columns={columns}
data={data}
options={{
selection: true,
}}
/>
</div>
);
}