Association table filter based on current opened entity

I am probably missing something easy, but I am at a loss and I am hoping someone can help.

Using Version 7.1.1. I have a CountryRaDetails entity that has a many to one association with Project and Country entities.

image

In the view for the countryRaDetails entity I see that the attribute projectNo is available.

image

On the PROJECT editor screen I have the countryRaDetails table embedded on the page. Currently the countryRaDetails table is showing all projects.

image

image

I would like this table to only show entries for the current project number that is opened.

The project-edit.xml file

<instance id="projectDc"
 class="com.chi.starship.entity.Project"
 view="project-view">
<loader/>
<collection id="projectSiteDc" property="projectSite"/>
<collection id="productDc" property="product"/>
</instance>

<collection id="countryRaDetailsDc" class="com.chi.starship.entity.CountryRaDetails" view="countryRaDetails-view">
<loader id="countryRaDetailsDl">
<query><![CDATA[select e from starship_CountryRaDetails e ]]></query>
</loader>
</collection>


<table id="countryRaTable" dataContainer="countryRaDetailsDc" width="100%" height="200px">
                        <actions>
                            <action id="create" type="create"/>
                            <action id="edit" type="edit"/>
                            <action id="remove" type="remove"/>
                        </actions>
                        <columns>
                            <column id="region" caption="Region" />
                            <column id="country" caption="Country" />
                            <column id="project" caption="Project" />
                            <column id="raSubmissionPlanned" caption="Submission Planned" />
                            <column id="raSubmissionActual" caption="Submission Actual" />
                            <column id="raApprovalPlanned" caption="Approval Planned" />
                            <column id="raApprovalActual" caption="Approval Actual" />
                            <!--<column id="regionName"/>-->
                        </columns>
                        <buttonsPanel>
                            <button id="createRaButton" action="countryRaTable.create"
                                    caption="Add RA Details"/>
                            <button id="editRaButton" action="countryRaTable.edit" stylename="friendly"
                                    caption="Edit RA Details"/>
                            <button id="removeRaButton" action="countryRaTable.remove" stylename="danger"/>
                        </buttonsPanel>
                    </table>

In the countryRaDetailsDc collection if I hard code the specific project number it filters as expected.
select e from starship_CountryRaDetails e where e.project.projectNo = ‘1234’

image

image

I can’t seem to figure out how to filter based on the current opened Project.

Any help would be much appreciated.

Hi @Stephen,
Since you are using version 7.1, there are 2 possible solutions:

  1. DataLoadCoordinator
<collection id="countryRaDetailsDc" class="com.chi.starship.entity.CountryRaDetails" view="countryRaDetails-view">
    <loader id="countryRaDetailsDl">
        <query><![CDATA[select e from starship_CountryRaDetails e where e.project = :container_projectDc]]></query>
    </loader>
</collection>

Don’t forget the facets tag:

    <facets>
        <dataLoadCoordinator auto="true"/>
    </facets>
  1. Dependencies Between Data Components

Regards,
Peterson.

2 Likes

Hi,

I’m not 100% sure if I understand your data model correctly, but in case you have a 1:N association/composition in the project entity to the CountryRaDetails entity, you can also just use the relationship to automatically filter for those that are selected for a particular project.

If the 1:N attribute is included in the View CUBA studio will auto generate a table and create a nested collection data container.

An example that does that can be found here (it uses 6.x datasources, but the idea is the same):

Cheers
Mario

1 Like