We have a custom payload field for a special type of date - a 'partial date' - used in archive collections.
It's composed of { value, year, month, day } - with value being an integer (bitwise manipulated) to create dates where month and day are optional - so for example '20000000' is year 2000 with 00 zero for month and 00 day.
We've created a custom admin 'Cell' component for this field - to present these special dates in the admin panel list view in any format we like.
And.... we can set a default descending sort order in the collection definition for our custom field by using 'dot' notation with a minus sign on the
defaultSortsetting... e.g...
defaultSort: '-publicationDate.value',So this is all great.
But.... if the user tries to change the sort order via the admin table list view, we get an exception:
[18:38:40] ERROR (payload): Error: Invalid field "" passed to sort()Attached is a screenshot. If we 'touch' the 'Publication Date' header sort order - we blow up with the error above. What's more we're now locked out of publications until we clear payload preferences.
Is there any way to tell the payload admin view list view to use one of the values in the composite custom field for the sort? Just like we do in the
defaultSortcollection setting above?
?
Is there a piece of content without this value?
Im assuming thats what might cause the error here
Hi
@858693520012476436- I don't think so. Not sure if this helps but here's our field definition...
https://gist.github.com/58bits/5d845db606dea28b90fb1e7218a79d64I think the problem is that the 'top'-level field is a group, and so it has no value.
ahhh right yeah, nested fields arent yet supported for the view, its on the roadmap
so you cant do like
group.dateOuch.
Can we disable sorting for the view altogether?
A shame - we're so close, since our custom Cell component can present the field fine.
Or perhaps create some kind of computed field at the top level based on sibling data?
thoughts?
thats a common solution right now
@okay cool - how do you create a computed parent field? And can it be hidden from the admin UI?
you can add a field with admin: hidden: true
and then use a beforeChange hook
to populate the hidden field
okay I'll have a go.
thanks!
- it turns out in our case we were half way there - we just needed a custom Field component (in addition to the Cell component) and then a single integer field value for our 'bit register' stored value of the date. We didn't need to store month or day.
Thanks again for the quick replies.
no worries glad you got it fixed
Admin View Sortable Nested Field?
Star
Discord
online
Get dedicated engineering support directly from the Payload team.