Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Admin View Sortable Nested Field?

default discord avatar
58bits2 years ago
10

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

defaultSort

setting... 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

defaultSort

collection setting above?



@858693520012476436

?

  • default discord avatar
    paulpopus2 years ago

    Is there a piece of content without this value?



    Im assuming thats what might cause the error here

  • default discord avatar
    58bits2 years ago

    Hi

    @858693520012476436

    - I don't think so. Not sure if this helps but here's our field definition...

    https://gist.github.com/58bits/5d845db606dea28b90fb1e7218a79d64

    I think the problem is that the 'top'-level field is a group, and so it has no value.

  • default discord avatar
    paulpopus2 years ago

    ahhh right yeah, nested fields arent yet supported for the view, its on the roadmap



    so you cant do like

    group.date
  • default discord avatar
    58bits2 years ago

    Ouch.



    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?



    @858693520012476436

    thoughts?

  • default discord avatar
    paulpopus2 years ago

    thats a common solution right now

  • default discord avatar
    58bits2 years ago

    @okay cool - how do you create a computed parent field? And can it be hidden from the admin UI?

  • default discord avatar
    paulpopus2 years ago

    you can add a field with admin: hidden: true



    and then use a beforeChange hook

  • default discord avatar
    58bits2 years ago

    to populate the hidden field



    okay I'll have a go.



    thanks!



    @858693520012476436

    - 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.

  • default discord avatar
    paulpopus2 years ago

    no worries glad you got it fixed

  • default discord avatar
    58bits2 years ago

    Admin View Sortable Nested Field?

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.