Show column from Relation Table

Hi, John!

How difficult is it to show a column from the Relation Table along with a column from the Selection Table (see fig. below)?

image

What I need to accomplish is something like this:

$crud->setRelationNtoN('actors', 'film_actor', 'actor', 'film_id', 'actor_id', '{fullname} - {priority}');

or even

$crud->setRelationNtoN('actors', 'film_actor', 'actor', 'film_id', 'actor_id', '{priority} - {first_name} {last_name}');

Note that ‘priority’ comes from the Relation Table, not Selection Table. I need this badly! Do you have any idea on how to add this info to my datagrid?

Thanks in advance!

Hello @bgeneto ,

There is unfortunately a limitation of the react-select that Grocery CRUD is using which is not supporting reordering. I will check if we can use a different plugin so we can support priority field as well.

I will keep you updated on this one.

Regards
Johnny

Okay. I thought that, in this case, the solution would be in the backend (php).

Note that I need (very common situation, IMHO) not only to order by ‘priority’ but also show the ‘priority’ column data alongside the data in the ‘Selection Table’:

$crud->setRelationNtoN('actors', 'film_actor', 'actor', 'film_id', 'actor_id', '{fullname} ({priority})', 'priority');

I think it is very common for the ‘Relation Table’ to have additional fields (like ‘priority’ in your own example), not only the two FKs. So… those extra fields are there for a reason, we need to have a way to use them, whether to order or display them (or both). ‘priority’ is just an example. We could have created_at, updated_at and many other data in the ‘Relation Table’.

We could use a simple callbackColumn() to display the extra ‘priority’ field. But setting a callbackColumn() on a relational (simple or n-to-n) field breaks the whole thing (the datagrid shows the ids), as well as setting a custom field type (see here).

Thx and best regards!