V7: Custom sorting, sortType, parameter "desc" is undefined. #1974
Replies: 5 comments
-
Using latest version ? |
Beta Was this translation helpful? Give feedback.
-
"react-table": "^7.0.0-beta.20", |
Beta Was this translation helpful? Give feedback.
-
This flag was added near to that version only, not sure that it is included in mentioned version, please use the latest version to resolve your issue. |
Beta Was this translation helpful? Give feedback.
-
Thank you @gargroh, it works. |
Beta Was this translation helpful? Give feedback.
-
It's unclear from the docs what the sortType function passed in should return. Looking at sortTypes.js it should return 0, -1, or 1.
Should this simple function perhaps be exposed so that it can be imported? @tannerlinsley |
Beta Was this translation helpful? Give feedback.
-
Hi!
First, thank you for this great library.
I'm currently implementing a custom sorting function that would allow me to keep all the null values at the bottom of the table.
Therefore I created a custom function that looks like this:
` const customSortType = useCallback((rowA, rowB, columnId, desc) => {
console.log("inside customSortType", desc);
let a = getRowValueByColumnID(rowA, columnId);
let b = getRowValueByColumnID(rowB, columnId);
let dateA = new Date(a.date).getTime();
let dateB = new Date(b.date).getTime();
Unfortunately, the last parameter is always undefined. Should I initiate it somewhere?
This is how I initiate my table:
const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow, } = useTable({ columns, data, initialState: { sortBy: [{id: "name", desc: false}] } }, useSortBy);
And here is the code of my column:
const COLUMN_LAST_CHECK_UP = { Header: makeHeader(HEADER_LAST_CHECK_UP), accessor: "lastCheckUp", Cell: LastCheckUpCell, sortType: customSortType };
Thanks for your help!
Beta Was this translation helpful? Give feedback.
All reactions