Reset pagination on sorting
See original GitHub issueAt first thanks for this awesome npm package, I really like its API and find it easy to use.
That said, I have a disagreement on how pagination should be handled when users sort data by clicking on a table column.
Currently when a user goes to let’s say page 7 and then sorts the table differently, even-though the displayed data changed, page number remains 7.
In my humble opinion, the page number should be reset to 0 in that case.
From a user perspective, I would say sorting data has a clear intent: finding the biggest/smallest value(s) among many rows. In this scenario, it makes sense to show the first page as the user probably doesn’t care about seeing page 7 of the rearranged dataset.
This actually is the behaviour of all datatables I could test so far so I thought I should kindly point it out in this issue.
In the case you disagree with this view, I decided to take a look at how to implement this myself. However I couldn’t find an elegant way to change the table internal page state.
From what I understand, the table options page
property is read only once when the MUIDataTable component mounts. It is then ignored upon re-rendereing.
That sounded a bit counter-intuitive to me as other options like count
are read and updated on every render.
I think if the page option is read only once when the components gets mounted, it would make sense to rename it to initalPage
. Then the option called page
could actually be the property allowing developers to control the table page state.
Expected Behavior
I was expecting pagination to get reset to 0 after clicking on a column, which sorts rows.
Current Behavior
Page number remains the same regardless of user actions. In some cases it probably would makes sense to reset pagination or at let devs control it.
Your Environment
Tech | Version |
---|---|
Material-UI | 4.5.2 |
MUI-datatables | 2.12.4 |
React | 16.11 |
browser | Chrome |
etc |
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:6
What if you allowed both options with an attribute so that we can set it to our desired pagination?
It’s fair to say that if you change mui-datatables behavior on that one, people would open issues asking for putting it back the other way around.
To me the behavior I suggested makes much more sense but I guess other people can have the opposite view.
In any case thanks for your feedback, if I can find the time to work on it I’ll submit a PR.