glin/reactable

Sorting On Grouped Tables With Multiple defaultSorted

rdesalvio opened this issue · 1 comments

I noticed that when you have a grouped table with a 2 sorts defined, the table appears properly on first load. But, when you click on any column to sort, the secondary sort is discarded and you cannot get that back. It feels like there should be a way to maintain that secondary sort after first load. Perhaps this isn't something that should be enabled by default, but it feels like it should be possible considering there are sort type hints and the sorting works on first load.

There probably is some way to fix this with JavaScript(I would love if anyone were able to accomplish this and show me as my javascript definitely leaves something to be desired), but again, I feel like the library should have a setting in colDef perhaps that is able to maintain that secondary sort.

Small code example:

reactable(df, 
                groupBy=c('System'),
                defaultSorted = list(Total='desc', group_num='asc'),
                group_num=colDef(show=FALSE)
)

Would love to have that secondary group_num field maintain its sort status, even though it is not visible.

glin commented

So I'm not 100% sure I understood correctly, but I think what may be looking for is the multi-sort feature when you hold the Shift key while sorting: https://glin.github.io/reactable/articles/examples.html#sorting

When you hold Shift, the sorted column changes sort order while maintaining all other column sorting.