Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the default sort direction to DESC on first click on each column header #290

Open
Jaguar1 opened this issue Apr 5, 2021 · 5 comments

Comments

@nihgwu
Copy link
Contributor

nihgwu commented Apr 5, 2021

you can always use controlled state to control the next sort direction, for the sort indicator, you can use customised SortIndicator as well

@Jaguar1
Copy link
Author

Jaguar1 commented Apr 7, 2021

you can always use controlled state to control the next sort direction, for the sort indicator, you can use customised SortIndicator as well

Hello, thank you for replying.

Sort indicator is nice and I do not want to mess with changing it. The problem is that currently the component always returns 'ASC' in onColumnSort sortBy on first click:

onColumnSort = sortBy => {
   this.setState({
     sortBy,
     data: this.state.data.reverse()
  });
};
// ...
<Table
   fixed
   columns={this.state.columns}
   data={this.state.data}
   sortBy={this.state.sortBy}
   onColumnSort={this.onColumnSort}
/>

This seems to be the initial state of sort.
Isn't it possible to pass some property with default first sort to the component like "firstSort=DESC"?

Thank you once again!

@nihgwu
Copy link
Contributor

nihgwu commented Apr 7, 2021

I don't want to bloat the api, perhaps next time I should simply omit the next sort order, it could means nothing in your case, you can simply ignore it, in that case you can even clear the sort state after a toggle round, DESC -> ASC -> NONE https://autodesk.github.io/react-base-table/examples/multi-sort

@Jaguar1
Copy link
Author

Jaguar1 commented Apr 8, 2021

Hi again,

In my case I can have multiple columns (50+) with financial data, and just one of them must be with a default DESC sort at the very beginning. The rest must not be ordered. This is a list of companies with their data, and the only column with default DESC order is Total Operating Revenue. At the very beginning the rest must not be ordered (no multi-sort as well). User can order by single column on header click but he/she must be able to order only by a single column: exactly like on the example I provided.

Your NPM package is really great and I truly believe it would be an user-friendly option to provide API property like: 

defaultSortDirection = 'DESC'

Best regards,
Vladimir

@nihgwu
Copy link
Contributor

nihgwu commented Jun 10, 2021

Sorry for the later response, the problem is that in that case we would need more props like clearing sort on the second click, in the future perhaps I should support custom reducer for the next sort state

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants