MountainConqueror
MountainConqueror

Reputation: 602

How can I add asc/desc sorting by every column to my react app?

I created github-search-app with react + redux . (+thunk)

So here is the code of my app on GitHub (it is really a very, very simple app).

https://github.com/elminsterrr/react-js-github-search-app

enter image description here

After each search, the search result is saved to redux store. Now I want to use that locally saved data and manipulate them. So I want to add to my project this features:

  1. Pagination
  2. Ability to control number of rows rendered (5/10/15/20)

  3. Asc/desc sorting by every column (after clicking on column name)

1 and 2 are ok, but this ("Asc/desc sorting by every column") looks hard to me. I'm stuck.

Please write how you would approach that problem and maybe it will be enough to get me going...

Upvotes: 0

Views: 575

Answers (1)

Lafi
Lafi

Reputation: 1342

Why are you building the table component instead of using the react-table component from npm? Example

Otherwise you need to order items in the state by dispatching an action that contains the column name so you could identify the prop to sort your data through.

Upvotes: 1

Related Questions