2

I'm trying to show some additional columns in the entry index, and allow editors to filter and sort by them. The problem is that the fields that need to be used for sorting are set on related entries, not on the entries themselves.

Some more detail: I have a section registrations which tracks user registrations for courses. Registration entries have only two fields:

  • An Entries field course limited to one related entry from the courses section.
  • A Users field participant limited to one related user.

The courses entries have fields for location (Entries field with a relation to an entry in the locations section) and start_date (Date field). Now the client needs to be able to filter registrations by the location and date of the courses entry they are related to – but those fields only exist on the courses entry, so they don't appear in the available columns in the entry index.

One obvious solution is to add those fields to the registrations entries as well, but that feels wrong. I'm duplicating the data, and there's a chance of entries becoming inconsistent. This can again be solved using hooks, but that's a lot of unnecessary work.

I've tried to use Element::EVENT_REGISTER_TABLE_ATTRIBUTES and Element::EVENT_SET_TABLE_ATTRIBUTE_HTML to add the two columns for location and date to the entry list. This works, but it's not possible to filter by those columns, which is required in this case.

I'm not sure how best to solve this. I also thought about programmatically adding a tab to the courses section's field layout that just lists all related registrations. But it should also be possible to export the list of registrations, which we would get 'for free' if we can manage to enable filtering by those related element fields in the entry index.

What's the best approach to solve this? Is there a way to add columns to element indexes that can be filtered and sorted by?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.