Displaying data in table from more than one entity

We know that we can create a datasource in screen XML only from one Entity. What would be the best approach of displaying data in a table when it is coming from several Entities (many tables of a database)?
–Is there any way to create a temporary table programmatically and use it to populate so that it can be used in defining datasource or
–Should I use an Entity and populate with data from different Entities using EntityManager?
–or anything else?

1 Like

The recommended approach is using non-persistent entities.

  • Create an entity and set “Not persistent” in the “Entity type” field.
  • In controller, load persistent entities somehow (through DataManager or from your custom services), instantiate your non-persistent entities and populate their attributes.
  • Create a collectionDatasource for the non-persistent entity, set “Do not refresh” and clear “Allow commit” checkboxes for it.
  • Add non-persistent entities to this datasource by invoking addItem() or includeItem().

If the entities are linked in your data model (for example, Order has a reference to Customer), you can display any attribute of Customer in the Orders table by specifying a path to it in the column name:

<table id="ordersTable">
        <column id="date"/>
        <column id="num"/>
        <column id="customer.name"/>
        <column id="customer.email"/>

But keep in mind that you cannot make such columns editable - changes will not be saved.

Yes , second option is also useful in cases.