Skip to content

Make stablesort configurable #16556

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

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from

Conversation

barryvdh
Copy link

Makes sure to add a unique key to the orderBy to prevent missing/duplicate items when pagination because of unstable sorting, when keys are the same.

Description

Re-does #16552

This adds a stableSort option to tables, to add an additional pagination key so that a unique key is always available when sorting, in the case of keys with the same value. Fixes #15865

Visual changes

Sorting on provider type (which is AWS for multiple). See that 25 and 26 are on page 1 and 3. There are some values missing entirely when paginating.

Before
Screenshot 2025-06-16 at 11 27 31
After
Screenshot 2025-06-16 at 11 28 55

Functional changes

This adds a $table->stableSort() option which adds the sorting. Default behavior in v3 is off. Maybe in v4 we can turn it on by default. (and use $table->stableSort(false) instead.

The query changes to add a secondary orderBy. For custom queries, in the future we might make the stable sort key configurable?

  • Code style has been fixed by running the composer cs command.
  • Changes have been tested to not break existing functionality.
  • Documentation is up-to-date.

Copy link
Member

@danharrin danharrin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please implement this in applySortingToTableQuery() (check the 4.x branch), not pagination.

Please add a test to ListRecordsTest

Please rename the methods/property to defaultKeySort(bool | Closure $condition = true), $hasDefaultKeySort and hasDefaultKeySort()

Please submit an additional PR to merge the branch into 4.x, allowing the default key sort to be turned off. The merge should enable the feature

Please document the behaviour change in the 4.x upgrade guide

I realise that there are alot of requests here, but I am super busy with other 4.x issues right now and I would appreciate the help to ensure that I don't have to go back and clean up this feature.

@github-project-automation github-project-automation bot moved this from Todo to In Progress in Roadmap Jun 17, 2025
@danharrin danharrin added the enhancement New feature or request label Jun 17, 2025
@danharrin danharrin added this to the v3 milestone Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pending changes
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

Missing table items on globally scoped models when sorting by created_at
2 participants