Open bjornwang opened 2 years ago
Any update on this? This feature would be life-changing
Agreed, this is a sorely needed feature particularly for reference arrays with mixed types... Any ETA on this?
i, personally, would really enjoy this feature immensely
Ok this feature actually exists, I guess it's just not that well documented:
defineField({
name: 'articles',
type: 'array',
of: [{
type: 'reference', to: [{ type: 'newsArticle' }],
options: {
sort: [{ field: '_createdAt', direction: 'desc' }] // SORTING REFERENCE FIELDS SEARCH
}
}],
title: 'Articles',
hidden: false,
})
Full credit: https://github.com/sanity-io/sanity/issues/2295#issuecomment-1743936873
Can anyone confirm that it still works? No sorting for me - I'm using Sanity 3.54.0. By the way, I use defineArrayMember inside the "of".
Still works! Using Sanity 3.61.0.
Is your feature request related to a problem? Please describe. Sometimes reference fields are used for small, well-defined sets of configuration values. In these scenarios it would be great to be able to sort them.
For example, in this case (see screenshot), the document type has a length field used for sorting which would be great to use for the reference selector too to get the shortest period at the top of the list. (The list contains predefined identifiers used in integration with a legacy system, hence the strange selection of durations.)
Describe the solution you'd like Add a sort order option just like we have optional filters for references today.
Describe alternatives you've considered Prefixing the values with numbers or alphabetic characters to affect the order.