How do you properly use the "sortType" function for a column? #2778
Replies: 3 comments 4 replies
-
I found the following piece of useful advide from stack overflow: 'desc identifies the direction of the sort. Even though desc is supplied, the sort function should NOT reverse the return values. react table automatically does this.' Try this in your column: `
}) just as a side note to anyone who is reading this - -if you can explain to me how to properly insert code comments on here i would be very grateful |
Beta Was this translation helpful? Give feedback.
-
You don't need to handle desc for basic sorting, I imagine its there in case there's some custom behavior your want when thing are being sorted the other direction. Are you memoizing the sortType function?
Then in my table:
|
Beta Was this translation helpful? Give feedback.
-
@timothydowd's suggestion only works if the
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi! I'm having issues with the
sortType
function on the column options.The definition says
sortType: String | Function(rowA: <Row>, rowB: <Row>, columnId: String, desc: Bool)
, and the docs mentionIf a function is passed, it must be memoized. The sortType function should return -1 if rowA is larger, and 1 if rowB is larger. react-table will take care of the rest.
.Does this mean we need to handle the
desc
argument in our custom sort function, or does react-table handle that?Also, whether I am handling
desc
or not in thesortType
function, the ordering doesn't change and I can't figure out why.Here is my
sortType
function for reference, using the provideddesc
argBeta Was this translation helpful? Give feedback.
All reactions