Looking for advice on how to sort collection titles by natsort on the CP #6929
-
Hi guys! |
Beta Was this translation helpful? Give feedback.
Answered by
jasonvarga
Oct 20, 2022
Replies: 1 comment 1 reply
-
You might also be able to use the new computed values feature. https://statamic.dev/computed-values Make a computed value that pulls the number out of the title and use that field for sorting. // AppServiceProvider.php boot method
Collection::computed('numbered', 'order', function ($entry) {
return (int) (string) str($entry->title)->afterLast(' ');
}); Tell the collection to sort by that field. # content/collections/collectionname.yaml
sort_by: order Optionally create a computed field in your blueprint that you could use to display the column in the listing: -
handle: order
field:
type: integer
visibility: computed
listable: visible |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
beatwiz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You might also be able to use the new computed values feature. https://statamic.dev/computed-values
Make a computed value that pulls the number out of the title and use that field for sorting.
Tell the collection to sort by that field.
Optionally create a computed field in your blueprint that you could use to display the column in the listing: