Skip to content

How to implement 3-state sorting? #326

Answered by MatthijsMud
nitedani asked this question in Q&A
Discussion options

You must be logged in to vote

Even if it is not supported as part of the library, it can be implemented relatively easily in user-land by wrapping the setter. When the sort status would change from 'desc' to 'asc' you'd instead set a different (non-existent?) column instead. This logic could be placed in a hook like the following:

const useSortOrder = () => {
  const [order, setOrder] = useState<DataTableSortStatus>({ columnAccessor: '', direction: 'asc'});
  const specialSetOrder = useCallback((state: DataTableSortStatus) => {
    setOrder(a => (a.columnAccessor === state.columnAccessor && a.direction === 'desc' && state.direction === 'asc')
      // Set "columnAccessor" to a value that is unlikely to be used.
      ? {

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by icflorescu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
documentation Improvements or additions to documentation help wanted Extra attention is needed question Further information is requested needs more info Needs more information
3 participants
Converted from issue

This discussion was converted from issue #298 on June 08, 2023 17:32.