react-data-table-component icon indicating copy to clipboard operation
react-data-table-component copied to clipboard

Sort doesn't taking the default order for the column

Open dileepthomas opened this issue 5 years ago • 2 comments

So as shown in the https://jbetancur.github.io/react-data-table-component/?path=/story/sorting--custom-sort-function for the sort. By default all the columns is starting from asc.

To Reproduce the Issue.

  1. Click on title column -> output will be asc
  2. Click on title column -> output will be desc
  3. Click on director column -> output will be desc // this should start from asc order

So the issue is basically for each column it should start from default value of sort order.

Just adding this snippet from the TableCol.js file

` // change sort direction only if sortColumn (currently selected column) is === the newly clicked column // otherwise, retain sort direction if the column is switched

if (sortColumn === column.selector) { direction = sortDirection === 'asc' ? 'desc' : 'asc'; }`

So when you log the sortColumn its not updating as soon, which means we are not getting the updated value. Getting a previous value.

Any fix on this will be helpful.

dileepthomas avatar May 20 '20 14:05 dileepthomas

I am hesitant to call this a bug since the current implementation is to "remember" the last sort state. I agree RDT should probably reset the sort to the default sort order when moving columns but this is going to take some effort. I'll flag this as an enhancement when I get time or if someone wants to attempt a PR

jbetancur avatar May 20 '20 20:05 jbetancur

What is the better way to have this feature, since i see the context value is getting the previous value. Also while checking on the sort, if you click first time asc, second click desc then it should not sort. can we have that feature with any prop or its not there. Checked the docs didn't find it.

dileepthomas avatar May 21 '20 10:05 dileepthomas