Display name instead of ID for relation

Hi everyone,

I’ve applied given instructions in the page ( Display name instead of ID for relation | UI Bakery Docs

But i need customer names in alphabetical order in the select, so when i add ā€œorder by nameā€ to the query, it doesnot work. ā€œorder by idā€ works…

I think, ā€œselectā€ component need a ā€œis_sortedā€ property.

Best regards

Hi @Alpay_Alkan,

If you have the same setup as in the instructions, meaning two related tables, where one table has the IDs as foreign keys and the other table has the names corresponding to the IDs as primary IDs, then you must order the table with the foreign keys according to the names in the table with the primary keys.

For example, using the users and orders table from the [Sample] Postgres data source.

Table orders

id user_id status …
10117 148 ā€œresolvedā€
10284 299 ā€œshippedā€
… … …

Table users

id name …
148 Alexandra Vandervort
299 Allan O’Reilly

In the action that loads the orders table, you can’t simply order by customer name, since that column is in the other table. What I would do, is making sure the users table is fetched first and then get the orders table. In the ā€œTransform resultsā€ option of the action, you can then use the data from the users table to sort the orders table.

So we have the loadUsers action, that just loads the table

And then we have the loadOrders action, where we first check if the users table has already been loaded

If not then execute the action that loads the table

And then in the step that loads the orders table, we sort based on the names from the customers table

Together with the instructions in the docs, so changing the field type to select/tag and mapping the value in the ā€œView settingsā€ to the name, it will display the names in alphabetical order now:

1 Like