feat: add default_sort option to sortable fields#7665
Merged
martinjagodic merged 2 commits intomainfrom Dec 4, 2025
Merged
Conversation
demshy
approved these changes
Dec 4, 2025
pranaysahith
pushed a commit
to pranaysahith/decap-cms
that referenced
this pull request
Dec 8, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds support for default sorting on collection views with enhanced
sortable_fieldsconfiguration options.Motivation:
Previously, when users defined
sortable_fieldsfor a collection, they would see an unsorted list on the first load. Users had to manually select their preferred sort order every time they opened a collection, or rely on localStorage to remember their previous selection. This PR introduces the ability to define a default sort order that will be applied on the first view of a collection, improving the user experience by showing entries in a meaningful order immediately.Additionally, this PR enhances
sortable_fieldsto support custom labels, making the sort dropdown more user-friendly when field names don't match what users expect to see in the UI.What's New:
ascordesc)sortable_fieldsnow supports both the existing string format and a new object format with additional propertiesHow to Use:
String Format - Existing
Object Format - New
Object Format Properties
When using the object format, you can specify:
field(required): The name of the field to sort bylabel(optional): Custom label to display in the sort dropdowndefault_sort(optional): Sets this field as the default sorttrueor'asc': Sort ascending (A-Z, oldest first)'desc': Sort descending (Z-A, newest first)default_sortproperty per collectionValidation Rules
Only one default: If you specify
default_sorton multiple fields, you'll get a validation error:User preferences take priority: Once a user manually selects a sort order, their preference is saved in localStorage and will override the default on subsequent visits
Complete Example
With this configuration:
sortable_fieldsand the deprecatedsortableFieldswork with all new featuresTest plan
Unit Tests:
default_sortboolean and enum valuesdefault_sortManual Testing:
Default Sort Behavior:
Custom Labels:
User Preference Persistence:
Validation:
default_sortfieldsExample Configuration:
See
/dev-test/config.ymlfor a working example:Type Safety:
TypeScript definitions updated in:
/packages/decap-cms-core/index.d.ts- Public API types/packages/decap-cms-core/src/types/redux.ts- Internal typesBoth
sortable_fieldsand deprecatedsortableFieldssupport the full type:Checklist
Please add a
xinside each checkbox:A picture of a cute animal (not mandatory but encouraged)