Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multisort does not work when providing a custom sort function #3512

Closed
reinrl opened this issue Oct 25, 2021 · 5 comments
Closed

Multisort does not work when providing a custom sort function #3512

reinrl opened this issue Oct 25, 2021 · 5 comments
Labels

Comments

@reinrl
Copy link

reinrl commented Oct 25, 2021

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.)

@reinrl
Copy link
Author

reinrl commented 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
Copy link

sbdfh commented 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 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.

@reinrl
Copy link
Author

reinrl commented Jan 5, 2022

@sbdfh gooooood eyes - thanks for catching that!

@github-actions
Copy link

github-actions bot commented Apr 8, 2022

This issue is being marked as stale (no activity in the last 14 days)

@github-actions github-actions bot added the Stale label Apr 8, 2022
@github-actions
Copy link

github-actions bot commented 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.

  • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants