Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

Sorting by multiple columns #309

Open
astraldawn opened this issue Aug 16, 2016 · 5 comments
Open

Sorting by multiple columns #309

astraldawn opened this issue Aug 16, 2016 · 5 comments

Comments

@astraldawn
Copy link

Is it possible to have a custom sorting function work on multiple columns?

E.g.

Col 1 Col 2
1 A
3 B
2 B
1 B

If I attempt to sort Col 2, the table sorts by Col 2 and then sorts Col 1 in ascending order.

cklab added a commit to cklab/reactable that referenced this issue Aug 25, 2016
@cklab
Copy link
Contributor

cklab commented Aug 25, 2016

+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. cklab@6b05e0a

cklab added a commit to cklab/reactable that referenced this issue Aug 30, 2016
cklab added a commit to cklab/reactable that referenced this issue Oct 14, 2016
cklab added a commit to cklab/reactable that referenced this issue Nov 21, 2016
@Olliepop
Copy link

@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;
    }
}

@isaachinman
Copy link

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.

@isaachinman
Copy link

@cklab Did you use sortFunction to fallback on a different value comparison if the initial value comparison is identical?

@cklab
Copy link
Contributor

cklab commented Jan 23, 2017

@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.

cklab added a commit to cklab/reactable that referenced this issue Dec 27, 2017
  - glittershark#309 provide row values to sortFunction
  - support filtering on all rows
  - support sorting by columns that do not specify a rowSpan
  - Specify column when warning about missing data property for TD
  - allow user to display a custom component when table has no children
  - glittershark#353 - allow other react components besides Td within Tr
  - support for components that ultimately resolve to a Td to be rendered in a Tr component
  - glittershark#84 - colspan support
  - prevent handleClick prop from making it to rendered component
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants