data-table-bundle icon indicating copy to clipboard operation
data-table-bundle copied to clipboard

[Sorting] There is no way to clear the applied sorting

Open CMH-Benny opened this issue 1 year ago • 4 comments

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?

CMH-Benny avatar Aug 05 '24 14:08 CMH-Benny

Hey @CMH-Benny, thanks for the report - should be fixed in 0.21.2

Kreyu avatar Aug 05 '24 20:08 Kreyu

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 👍❤️

CMH-Benny avatar Aug 06 '24 11:08 CMH-Benny

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

Kreyu avatar Aug 06 '24 11:08 Kreyu

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 ❤️

CMH-Benny avatar Aug 06 '24 13:08 CMH-Benny

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.

Kreyu avatar Jul 08 '25 13:07 Kreyu

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

Kreyu avatar Jul 09 '25 10:07 Kreyu

Amazing, thank you!

CMH-Benny avatar Jul 24 '25 11:07 CMH-Benny