Created UI record filtering

Hi, we are creating our first cuba project and we are struggling with this situation:

For instance we have 3 entities

USER: linked to the Cuba sistem user. USER has an ASSOCIATION with TOWN_HALL
TOWN_HALL: we can link a user to his town all
WORKGROUP: all the workgroup created in the TOWN. WORKGROUP has an ASSOCIATION with TOWN_HALL

If we create the UI with Cuba, we have 3 sections:
a) the combo box to select the user
b) the grid to create and link all the town hall we want to link to that user…
c) the grid to create and link all the workgroup we want to link to that user…

the problem we have is that we would like to have in the WORKGROUP grid only the workgroups linked to the TOWN_HALL linked in the b) grid … right now the two grids works independently … we cannot establish a “filter” from grid b) to grid c) …

Is there a way to do what we need?

Thank you very much for your time
Angelo

Hi,

i created an example that should solve the problem you are describing. You can find it here: https://github.com/mariodavid/springfield-town-hall-management


Springfield town hall management

This CUBA example shows how to have dependent tables in order to select a particular value of a M:1:N association.

Example domain model

domain-model

Filtering between dependent grids

The key point of this example shows how to let two grids be dependent on each other. In this case it is the grids:

  • Town Hall
  • Workgroup

First - a town hall should be selected. After that the second grid: “Workgroup” should only contain the workgroups
that are associated to that particular town hall, that was selected in the first grid.

The magic happens in employee-assign-workgroup.xml:

<collectionDatasource id="allTownHallsDs"
                      class="de.diedavids.cuba.cedg.entity.TownHall"
                      view="_minimal">
    <query>
        <![CDATA[select e from cedg$TownHall e]]>
    </query>
</collectionDatasource>
<collectionDatasource id="allWorkgroupsOfTownHallDs"
                      class="de.diedavids.cuba.cedg.entity.Workgroup"
                      view="workgroup-view">
    <query>
        <![CDATA[select e from cedg$Workgroup e where e.townHall.id = :ds$allTownHallsDs]]>
    </query>
</collectionDatasource>

The second collection datasource has a :ds reference to the the first datasource. CUBA will therefore filter out
the correct workgroups for this particular town hall. See the result:

Application result

app-overview

Bye
Mario

2 Likes

Thank you Mario for your answer, i think it’s the must complete answer i had from a forum post!!! thank you ver much

I checked it out and it seems we have to customize a bit the UI that cuba creates automatically no? We have to create a new UI, create custom datasources and assign them to the right grid datasources… it is correct?

than you very much again
Angelo

hi,

yeah, from your description i was not really able to get which UI you are looking for. But the “assign workgroup” is somewhat similar. I replaced the user drop down with a selection in the table.

But the dependent grids should be pretty similar, right?

The screens are generated and then partially adjusted (especially the “assign workgroup”).

Bye
Mario

Thank you Mario for your help.

As i wrote in the first post ( as super beginner as i am) i created the view on
USER: linked to the Cuba sistem user. USER has an ASSOCIATION with TOWN_HALL
TOWN_HALL: we can link a user to his town all
WORKGROUP: all the workgroup created in the TOWN. WORKGROUP has an ASSOCIATION with TOWN_HALL

and cuba generated me an edit form with
a) the combo box to select the user
b) the grid to create and link all the town hall we want to link to that user…
c) the grid to create and link all the workgroup we want to link to that user…

i saw you used another approach to the solution, that was because mine wasn’t correct and the “record filter” can be done only with your solution? and so i cannot have it in one form as the generated?

thank you VERY much
angelo