Search code examples
reactjsreact-tablereact-table-v7

How can checkboxes be sorted (based on true-false status) in react-table?


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)


Solution

  • 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;
            }),