Reputation: 21
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. In the inverse case, using a custom sort for the first column and a built-in sort for the second column, again only the first column specified is actually sorted. I also [posted this as a potential bug on the project itself][https://github.com/tannerlinsley/react-table/issues/3512], but am cross-posting it here on the off chance that I just missed something when attempting to implement my custom sort functions.)
Upvotes: 0
Views: 1749
Reputation: 21
From the corresponding project issue:
"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."
Upvotes: 1