diff --git a/docs/pages/examples/RowSelectionExample.tsx b/docs/pages/examples/RowSelectionExample.tsx index 4829ca8..5c72ca7 100644 --- a/docs/pages/examples/RowSelectionExample.tsx +++ b/docs/pages/examples/RowSelectionExample.tsx @@ -1,3 +1,4 @@ +import { Button } from '@mantine/core'; import { RowSelectionState } from '@tanstack/react-table'; import { useState } from 'react'; import { @@ -11,55 +12,66 @@ import { import { demoData } from '../../demoData'; export default function RowSelectionExample() { + const [data, setData] = useState(demoData); const [selected, setSelected] = useState({}); + + const removeSelected = () => { + const next = data.filter((_, i) => !selected[i]); + setSelected({}); + setData(next); + }; + return ( - cell.getValue()?.toLocaleDateString(), - filterFn: dateFilterFn, - }, - { - accessorKey: 'bool', - filterFn: booleanFilterFn, - }, - ]} - /> + <> + + cell.getValue()?.toLocaleDateString(), + filterFn: dateFilterFn, + }, + { + accessorKey: 'bool', + filterFn: booleanFilterFn, + }, + ]} + /> + ); } diff --git a/src/DataGrid.tsx b/src/DataGrid.tsx index b669763..a2cb3a1 100644 --- a/src/DataGrid.tsx +++ b/src/DataGrid.tsx @@ -226,7 +226,8 @@ export function DataGrid({ const handleRowSelectionChange: OnChangeFn = useCallback( (arg0) => { - table.setState((state) => { + table.setState(() => { + const state = table.getState(); const next = functionalUpdate(arg0, state.rowSelection); onRowSelectionChange && onRowSelectionChange(next); return {