gregnb / gregnb/mui-datatables

Reset pagination on sorting

Open
#1,047 6 comments 5 reactions 0 assignees View on GitHub
enhancement help wanted new feature
Dominant language
JavaScript
Stars
2.7k
Forks
906
PR merge metrics
No merged PRs in 30d

Description

At 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 | |

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.