Skip to content

How to implement custom sort button #2951

Discussion options

You must be logged in to vote

I found a solution. I was trying to keep the function outside of the actual table component function to keep it slim and pass the column in as a prop, but I think there was more instance properties required to make that work? Instead I've just put the dropDownHeader function directly inside the useTable function and directly access the main table's toggleSortBy function. Works great.

...
useTable(
...

function dropDownHeader (column) {
  function sortAscHandler () {
    toggleSortBy(column.id, false, false)
  }
  return (
    <button onClick={() => sortAscHandler()}>Sort Asc</button>
  )
}

and then I call the dropdown function in the table body as below:

<div className='th'
     {...col…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ankursehdev
Comment options

Answer selected by automatedmachine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants