You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Multisort does not work when providing a custom sort function #3512
Multisort seems to work just fine...as long as you are using built-in sort types (see this example, which loads with the first two columns included in the default sort). As soon as I attempt to use a custom sort function, sorting only seems to take into account the first column specified (see this example, which is identical to the functional first example - although it specifies a custom sort function). I tried looking through the documentation, as well as looking through the source code for the built-in sort types, and I don't see anything different from what I am doing?
(Interestingly enough, the sort icons would make it seem like both columns were sorted; but if you put a breakpoint in the custom sort function, you can clearly see that it never gets called for the second column. Also potentially worth noting is that this only seems to be an issue if both columns use a custom sort. If I alter the second example such that the first column uses one of the built-in sort types - either by manually using one, or just accepting the default - then the multisort appears to function as expected.)
@tannerlinsley any insight here? (Or even just a thread to pull at? I have tried chasing the sort function calling through the project code a bit, but really don't see a huge difference between the built-in sorting types and a provided custom function.)
@reinrl This, in fact, seems to be a problem with your custom sort type. You see, in the example you provided, your defaultAlphanumericSort only returns 1 or -1.
However, if you look at the defaultOrderByFn of react-table, you will notice that the secondary (tertiary and so on ... ) sorting is only applied, if the previous sorting functions returned 0.
Extend your custom sort type to return 0 on equality and you should be fine.
This issue has been detected as stale and automatically closed. It's very likely that your issue has remained here this long because it would require breaking changes to v7. React Table v8 is currently in alpha (soon beta!) and already contains bug fixes, performance improvements and architectural changes that likely address this issue.
If your v7 issue has been previously labeled as requiring breaking changes, please try the new v8 alpha/beta releases
If your v7 issue has not already been labeled as a breaking change, open a new issue.
If this was a v8 issue and was closed by mistake, please reopen or leave a comment below.
Activity
reinrl commentedon Nov 10, 2021
@tannerlinsley any insight here? (Or even just a thread to pull at? I have tried chasing the sort function calling through the project code a bit, but really don't see a huge difference between the built-in sorting types and a provided custom function.)
sbdfh commentedon Jan 5, 2022
@reinrl This, in fact, seems to be a problem with your custom sort type. You see, in the example you provided, your
defaultAlphanumericSortonly returns 1 or -1.However, if you look at the
defaultOrderByFnof react-table, you will notice that the secondary (tertiary and so on ... ) sorting is only applied, if the previous sorting functions returned 0.Extend your custom sort type to return 0 on equality and you should be fine.
reinrl commentedon Jan 5, 2022
@sbdfh gooooood eyes - thanks for catching that!
github-actions commentedon Apr 8, 2022
This issue is being marked as stale (no activity in the last 14 days)
github-actions commentedon Apr 8, 2022
This issue has been detected as stale and automatically closed. It's very likely that your issue has remained here this long because it would require breaking changes to v7. React Table v8 is currently in alpha (soon beta!) and already contains bug fixes, performance improvements and architectural changes that likely address this issue.