Force reorder of a column to it's current or default order
column.toggleSort
allows you to specify desc: boolean
, to set the direction to ascending or descending. Is there any way to trigger a re-order to default order for the column? Removing the sort state won't work in my case as the column is really sorted manually based on the values of a sibling column. As far as the library is concerned, it's not even sorted to begin with (it's the sibling column which is sorted).6 Replies
other-emeraldOP•3y ago
The awkward set up is due to a workaround being used to 'fix' the behaviour of row grouping for column groups. If there's a better way to do that, I am also very open to that.
genetic-orange•3y ago
Is this api help?
https://tanstack.com/table/v8/docs/api/features/sorting#resetsorting
Sorting | TanStack Table Docs
State
Sorting state is stored on the table using the following shape:
other-emeraldOP•3y ago
No I'm afraid not. That really just removes the sort state from the table (or restores its initial value). Neither of which actually force a re-order.
genetic-orange•3y ago
Did you set
manualSorting
to true
? From my experience, the table row will be always sorted according to your sorting state even if your data has been changed. Do you have any snippets to share?other-emeraldOP•3y ago
No I'm not using manual sorting.
@Maintainer - Table after a bit more poking around I think this is actually a bug (or at least a limitation of the library). See example here: https://codesandbox.io/s/silly-johnson-tim07q
If (for example) you group on the Last Name column, then expand out the first few row groups, and then cycle through the sort order on the First Name column, you will see the subrows go into
asc
order, then desc
order, but then the subrows stay in desc
order when you cycle back to the unsorted state. Intuitively I would expect them to return to their initial (unsorted) state. Do you agree?CodeSandbox
silly-johnson-tim07q - CodeSandbox
silly-johnson-tim07q using @faker-js/faker, @tanstack/react-table, react, react-dom, react-scripts
other-emeraldOP•3y ago
(due to the random data generation you may need to refresh the data a few times till you get a suitable dataset to see the problem - i.e. you need some row groups with three or more subrows which don't coincidentally already start in asc/desc order)