5

Using react-table V7 useSortBy hook's toggleSortBy function toggles ascending first then descending and then on third toggle instead of setting isSortedDesc to false, it sets isSorted to false.

I want to keep toggling between true and false values till a different header is clicked.

check this link for reference of the issue

priyanshu sinha
  • 595
  • 6
  • 14

1 Answers1

8

You can make use of toggleSortBy function on the table header from column property and call it on onClick event

<th 
      {...column.getHeaderProps(column.getSortByToggleProps())} 
      onClick={() => column.toggleSortBy(!column.isSortedDesc)}
>

Working demo

Shubham Khatri
  • 270,417
  • 55
  • 406
  • 400