[Sorting] There is no way to clear the applied sorting
Hey there, it's me again :D
after the Persistence was fixed to restore the URL params properly I noticed that suddenly the persistance of sorting also works better as before, previously it was only possible to apply sorting for one column, but now it adds sorting for multiple columns if clicked. However it is fully impossible to escape this state now, because even if you delete the sort params from URL and reload the page, the persistence retores them. Is there an easy way to add a clear sorting button or add a third state to the colum header to take sorting away?
Steps to reproduce:
- Open table
- Click sortable colum header
- Click another sortable column header
- See both "active" and see if behavior is correct, for me it isn't
- Try to get back to a single column to be sorted, or go back to no sorting (for me it's impossible)
It also seems that multi sort doesn't work perfectly, could be my search index that has the issues, I pass it multiple sorts actually, however I guess the order matters and we can't control the order currently, so I guess without further thinking it's not the best idea to allow multi sort?
WDYT?
Hey @CMH-Benny, thanks for the report - should be fixed in 0.21.2
Oh wow, you're fast! 😮 Thank you so much, I updated it and now it is back to only allow one column to be sorted. 🎉
I still can't remove the sorting, so after a sorting was applied once, you can only switch the column, but no way to go to the default state, if persitence is enabled. It's not the biggest Deal, for me it works good enough for now, but it might be worth to revisit this in the future to allow for multi column sort and clearing off a sorting at some point.
Thank you so much for your fast reaction and fix, looking good now 👍❤️
Oh, right, I focused on the bug and ignored the fact we're talking about clearing the sorting - sorry.
You're right, currently there's no way to remove applied sorting - the controls are always alternating between "asc" and "desc". I think the most common way to handle this is alternating between "asc", "desc" and "don't sort" (we'll have to send null to prevent loading from persistence). I'll try to implement it soon, good to know the bug is gone 😄
Cheers
Thank you so much! And no problem at all - It kinda was about two things, the bug and the clearing :)
I think a third toggle state is the easiest option for now and is a quick win 🎉
In the long run it might be a nice addition if there is a dropdown or some other fancy control element that allows to choose asc/desc/clear and to set a priority, so that we could kinda control the order that would allow for controlled multi sort then, but this is for sure a whole new feature :)
Thanks again for fixing the issue so fast! I am close to have a first version with your awesome bundle running ❤️
Working on it, should be shipped tomorrow. The "third state" will be configurable globally or per data table, since some might prefer the current behavior of switching between asc and desc.
Since 0.31, sorting is now clearable by default, so third click will undo the sorting instead of cycling back to "asc". Previous behavior can be restored: https://data-table-bundle.swroblewski.pl/docs/features/sorting.html#clearing-the-sorting
Amazing, thank you!