useSortBy的文档中描述了sortType属性:
sortType: String | Function(rowA: <Row>, rowB: <Row>, columnId: String, desc: Bool)
Used to compare 2 rows of data and order them correctly.
If 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.
String options: basic, datetime, alphanumeric. Defaults to alphanumeric.
The resolved function from the this string/function will be used to sort the this column's data.
If a string is passed, the function with that name located on either the custom sortTypes option or the built-in sorting types object will be used.
If a function is passed, it will be used.
For more information on sort types, see Sorting
但是它并没有完全解释如何使用它。
那么如何提供sortType函数呢?
rowA.values[id]
而不是rowA.original[id]
。此外,常见的语义>
可能会返回1
而不是-1
。 - Ken LinsortType
与您的比较函数的名称(例如compareNumericString
)即可。 - Ken Lin