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

Make table sorting deterministic #860

Closed
cjcenizal opened this issue May 21, 2018 · 1 comment
Closed

Make table sorting deterministic #860

cjcenizal opened this issue May 21, 2018 · 1 comment
Assignees
Labels

Comments

@cjcenizal
Copy link
Contributor

In the example below, you can see that changing the pagination results in the order of the rows changing:

table_pagination

This is because the table is sorted on dateOfBirth, but they all possess the same birth dates.

One solution could be to allow the user to specify a secondary property to sort on. As long as the secondary properties are not also identical, this will result in matching items being sorted deterministically. If the user doesn't provide a secondary sort property, then we could fall back to sorting on the itemId, if it's provided.

@cjcenizal cjcenizal changed the title Making table sorting deterministic Make table sorting deterministic May 21, 2018
@chandlerprall chandlerprall self-assigned this Jul 30, 2018
@chandlerprall
Copy link
Contributor

Two items to address here:

  1. bug when there is no query, in-memory table mutates the items prop, this affects subsequent sorting calls
  2. feature a secondary sort-by column

Fixing 1 solves this issue in the table docs and should introduce row stability in most cases. However, the ES spec does not specify anything about Array.prototype.sort being stable; most major implementations try to provide stable implementations, but the V8 team has stated they do not intend to do so (even though it often appears to be as the steps to ). Further, there is a difference between sort stability and function output being stable. Sort stability ensures that items with equal values will be sorted into the same order they were in originally, while stable output is simply that the function returns the same output when given the same input. The latter is true for all sort implementations, which makes the table sort stable from the user's point of view.

I think secondary/multiple sort-by columns is an intriguing idea but it carries additional design work to properly implement, so I am not addressing that in this issue. Feel free to raise a new issue for that discussion if that's desired functionality! Further, if we think true stable sort is something that we want for these tables we will need to add one of the many such JS user-space sort implementations. For now I am going ahead with the simple fix of avoiding mutation the input items prop.

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

No branches or pull requests

2 participants