What is best practice for applying a custom sort function to a collection (something that goes beyond
defaultSort
)? I thought I'd be able to use a collection hook here but looks like there are no hooks that have access to the entire
docs
array. Our immediate goal is to set a specific order for a related field drop down options.
Also tried a custom endpoint, but doesn't seem like that affects the local API
Hi Seth!
beforeRead
has access to
doc
which will be the collection of docs you're looking for. You can apply your sort logic there and return the sorted result.
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.