T
TanStack2y ago
inland-turquoise

How to implement a controlled sorting-state?

Hey 👋🏽 , if I want control the sorting state of a table v8 in react. Is this the approach to go?
function MyTable({ sorting, data, onSort }) {

const table = useReactTable({
data,
state: { sorting },
manualSorting: true ,
columns: tableColumns,
getCoreRowModel: getCoreRowModel(),
onSortingChange: (sorting) => {
if (onSort) {
onSort(sorting());
}
}
});

useEffect(() => {
setSorting(sortState);
}, [sortState]);
}
function MyTable({ sorting, data, onSort }) {

const table = useReactTable({
data,
state: { sorting },
manualSorting: true ,
columns: tableColumns,
getCoreRowModel: getCoreRowModel(),
onSortingChange: (sorting) => {
if (onSort) {
onSort(sorting());
}
}
});

useEffect(() => {
setSorting(sortState);
}, [sortState]);
}
Thanks!
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?