Open astraldawn opened 8 years ago
+1, kinda in need of this too as of late.
@glittershark thoughts about providing the row data when calling the sortFunction? I'm using this for the time being, let me know and I can make a PR. https://github.com/cklab/reactable/commit/6b05e0a9a98a24809f852d403c0a9a22cb9834a7
@cklab sortFunction
should accept row data rather than the cell innerHTML (as it currently does), so we may sort values which have been formatted for our specific usecase without regex within the sort. i.e
{
column: 'efficiency',
sortFunction: (rowA, rowB) => {
return rowA.efficiency > rowB.efficiency ? 1 : -1;
}
}
Is there any update on this? It seems sensible to have fallback sorting, so that if the top-level column sort results in a bunch of rows with equal values, we can have secondary sorting logic for those equal-value rows.
@cklab Did you use sortFunction
to fallback on a different value comparison if the initial value comparison is identical?
@isaachinman I'm using pr #321 which calls sortFunction like so:
sortFunction(keyA, keyB, rowA, rowB)
So, if we have a sort definition with column: "name"
and for the table, we have the data
data=[
{ name: "John", lastName: "Doe" },
{ name: "John", lastName: "Smith" }
]
sample arguments for sortFunction (with pr #321) would look like:
keyA: "John"
keyB: "John"
rowA: { name: "John", lastName: "Doe" }
rowB: { name: "John", lastName: "Smith" }
I then use the objects rowA and rowB to perform further comparisons, as needed.
Is it possible to have a custom sorting function work on multiple columns?
If I attempt to sort Col 2, the table sorts by Col 2 and then sorts Col 1 in ascending order.