table icon indicating copy to clipboard operation
table copied to clipboard

Pivot sorting clears order of data...

Open ernani opened this issue 9 years ago • 4 comments

I am sending a list of activities with activityId, but, the sort in the rest response is a date. The table is pivoted by that field, activityId, then, I wanted the dates to be following that order of precedence, but, it messes it up, and, I may have to create a sorting for the date fields, but, since it is coming from my rest call, why would I have to?

My version is: "react-table": "6.5.3"

Thanks!

ernani avatar Aug 24 '17 19:08 ernani

I am also experiencing issues with sorting and pivot tables but I want to confirm this is the same issue before raising my own. For example, take this example https://react-table.js.org/#/story/controlled-component:

If I sort one of the pivot columns for example "first name" column in DESC and expand the "ability" group and then click again on "first name" to sort by ASC order I would expect the "zoo" group to be collapse and "ability" to be expanded. Instead, it appears that the grid is saving expansions by index as opposed to an item(s), is this the same issues you are having?

bernalrs avatar Aug 31 '17 07:08 bernalrs

This was one of the concerns I've had, but my problem was different. I wasn't taking care of the row ordering when doing the Aggregate function for some columns, I've had to tweak that to get it to sort properly along with the pivoted data. Checking the default behavior by looking at the component source really helped me out.

Regarding your case, you are right on affirming that the pivoting is pivoted by row index and not data index. That though can be managed by when sorting the data, ensure you also obtain the id of the data and id of the index and update expanded rows indexes to reflect that. I guess that the power of this component is that it doesn't assume anything for you, you are totally and absolutely free to do whatever you want, it gives you all you need to work it out, but you gotta do it yourself!

ernani avatar Aug 31 '17 12:08 ernani

@ernani Did you find the solution for your problem??? I am also facing problems in order to maintain the the order of the data coming from rest call when table is pivoted.

swp44744 avatar May 08 '18 18:05 swp44744

Try discarding if the types are array when implementing your sorting function.

ernani avatar May 10 '18 04:05 ernani