Skip to content

Add defaultSort option to collections - #1691

Open
bycorekci wants to merge 1 commit into
Thinkmill:mainfrom
bycorekci:feat/collection-default-sort
Open

bycorekci wants to merge 1 commit into
Thinkmill:mainfrom
bycorekci:feat/collection-default-sort

Conversation

@bycorekci

Copy link
Copy Markdown

What

Collections can now configure how their list view is sorted when it first loads:

posts: collection({
  label: 'Posts',
  columns: ['publishedOn'],
  defaultSort: { column: 'publishedOn', direction: 'descending' },
  // ...
});

CollectionPage uses defaultSort as the initial sort descriptor. If it is omitted, or if column is not one of the configured columns, the list keeps the existing behaviour: sorted by slug, ascending.

The column value is typed as a key of the collection schema (restricted to scalar form fields), matching how columns is typed.

Why

The collection list has always started sorted by slug. For collections where the slug is the URL (e.g. a blog), that order is effectively random for editors, who re-sort by date on every page load. defaultSort lets the config express the natural default for the collection.

Refs #1579.

How to test

  1. Add a collection with at least one non-slug column, e.g. columns: ['publishedOn'], plus defaultSort: { column: 'publishedOn', direction: 'descending' }.
  2. Open the collection list in the admin UI: entries are sorted newest first, and the publishedOn column starts in descending order.
  3. Remove defaultSort (or point column at a field that is not in columns): the list falls back to slug ascending, as before.
  4. Click a column header: sorting still updates the descriptor as it did previously.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Dec 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9e1e147

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@keystatic/core Minor
@keystatic/templates-astro Patch
@keystatic/templates-nextjs Patch
@keystatic/templates-remix Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant