Repository navigation
Sort manipulation with v9 configs #6649
|
There are many tables in our app which default to small view windows, but for which users want to have the ability to pin rows. Using the sticky-top rows from the built-in pinning feature means that the view for the unpinned rows shrinks too much, so we currently implement pinning as a sort on a hiden column It would be nice if there were a way to do this using the preferred v9 state management, or maybe if there were a way to specify that a sort column should not be removed by the built-in updater. |
Replies: 1 comment 1 reply
|
You can keep v9's atom ownership and still use For the pins-enabled case, keeping your existing features, columns and data setup, import { useCreateAtom } from '@tanstack/react-store'
import { functionalUpdate, type SortingState } from '@tanstack/react-table'
const sortingAtom = useCreateAtom<SortingState>([
{ id: 'isPinned', desc: true },
])
const table = useTable({
features,
columns,
data,
atoms: { sorting: sortingAtom },
onSortingChange: (updater) => {
sortingAtom.set((old) => [
{ id: 'isPinned', desc: true },
...functionalUpdate(updater, old).filter((s) => s.id !== 'isPinned'),
])
},
})Filtering first also handles attempts to reverse or duplicate I checked this with React Table 9.3.1, including column toggles, clearing, resets and atom subscriptions. The sorting update path still calls the change handler when an external atom owns the state. If |
You can keep v9's atom ownership and still use
onSortingChangeto enforce the extra sort.atoms.sortingsupplies the current value, so you don't needstate.sortingor a React state setter.For the pins-enabled case, keeping your existing features, columns and data setup,