onRowSelected (useRowSelect missing feature?) #3723
-
Hi, I've been using I'd figured I'd do something like const [data, setData] = useState();
const doWhatever = (rows) => setData(rows);
return <Table onRowsSelected={doWhathever} /> but I don't see a way with current API to send Any idea? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
For those of you coming here and wondering if I found something, I ended up doing a "nasty hack" with some const [selectedData, setSelectedData] = useState<readonly T[]>([]);
const selectionColumn = {
id: 'selection',
Header: ({
getToggleAllRowsSelectedProps,
selectedFlatRows,
}: UseRowSelectInstanceProps<T>) => {
// This is a hack to compensate "onRowSelected" missing feature from React Table
useEffect(() => {
if (onRowSelection !== undefined) {
const rows = selectedFlatRows.map(({ original }) => original);
if (!isEqual(rows, selectedData)) {
setSelectedData(rows);
onRowSelection(rows);
}
}
}, [selectedFlatRows]);
return (
<div>
<IndeterminateCheckbox {...getToggleAllRowsSelectedProps()} />
</div>
);
},
Cell: ({ row }: { readonly row: UseRowSelectRowProps<T> }) => (
<div>
<IndeterminateCheckbox {...row.getToggleRowSelectedProps()} />
</div>
),
}; I'll be glad to point to a better answer if there's one :) |
Beta Was this translation helpful? Give feedback.
-
What I did to manage Table state outside of Table component:
|
Beta Was this translation helpful? Give feedback.
For those of you coming here and wondering if I found something, I ended up doing a "nasty hack" with some
useEffect
anduseState
to detect the change. It looks like that