I have a table I designed on a 'react-table'. I want to sort according to the checkboxes I marked on my table. For example, when I press column name, the true ones should be listed first. I'll be happy if you can help me.
picture of the error (true values should have been first or false values by choice)
The other solution works, but it's not necessary.
I got stuck with this as well, until I realized that one can set sortType: 'basic' (which is one of the built-in sorts of react-table) and it will sort the boolean column properly.
The reason that sorting a boolean column doesn't work out of the box is because the default sorting is set to alphanumeric.
After some more research, I learned that it can be done with sortType. We can sort the boolean values by adding this code to the relevant column.
sortType: ((a, b, id) => {
if (a.original[id] > b.original[id]) return -1;
if (b.original[id] > a.original[id]) return 1;
}),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With