Pagination for Collection Property

Hi, I have a problem when trying to create pagination for a composition field of an object.

This is my instance xml:

    <instance id="purchaseOrderDc" class="com.fpt.scf.entity.PurchaseOrder" provided="true">
        <fetchPlan extends="_base">
            <property name="bank" fetchPlan="_base"/>
            <property name="bankBranch" fetchPlan="_base"/>
            <property name="scfContract" fetchPlan="_base"/>
            <property name="anchor" fetchPlan="_base"/>
            <property name="distributor" fetchPlan="_base"/>
            <property name="currency" fetchPlan="_base"/>
            <property name="poItems" fetchPlan="_base"/>
            <property name="poDeliveries" fetchPlan="_base"/>
        </fetchPlan>
        <loader id="purchaseOrderDl" provided="true"/>
        <collection id="itemsDc" property="poItems"/>
        <collection id="poDeliveriesDc" property="poDeliveries"/>
    </instance>

And I want to create a pagination for the collection “itemsDc” (“poItems” is a composition field of entity “PurchaseOrder”)

I tried to use: simplePagination and pagination but both have the same result like the picture below:

            <simplePagination id="simplePagination" itemsPerPageVisible="true" autoLoad="true"
                              itemsPerPageOptions="10, 20, 30"
                              itemsPerPageDefaultValue="20"/>

            <pagination itemsPerPageVisible="true" itemsPerPageDefaultValue="20" itemsPerPageOptions="10,20,30"
                        align="MIDDLE_RIGHT" maxVisiblePages="3" id="pagination">
                <containerProvider dataContainer="itemsDc"/>
            </pagination>

image

There are 2 problems:

  1. The table has total 11 rows but on init, the row/page is set to “3647” (I don’t know where this number comes from)
  2. When I set row/page = 10, it does not paginate, there is only 1 page with 11 rows.

Pls help me to create a pagination for a Collection Property. Thanks

image
Bạn hãy thử dùng cái này.

vì nó là collection trong property nên không có loader để set ý bác.

lúc ông loaddata ra rồi ông thử maxResults rồi getField thử xem

Hello!

Sorry for the long reply. The pagination does not work with nested CollectionContainer because it does not have Loader.

To save benefits of composition and have pagination simultaneously I can suggest you to move itemsDc to separate container with query that selects items for current PurchaseOrder. So the pagination will work with this container correctly.

Then override actions Create and Edit to open editor with parent DataContext. It will enable @Composition behavior.

For instance:

@Autowired
private ScreenBuilders screenBuilders;
@Autowired
private DataManager dataManager;

@Subscribe("itemsTable.create")
public void onItemsTableCreate(Action.ActionPerformedEvent event) {
    Item newItem = dataManager.create(Item.class);
    newItem.setPurchaseOrder(getEditedEntity());

    screenBuilders.editor(itemsTable)
            .newEntity(newItem )
            .withParentDataContext(getScreenData().getDataContext())
            .show();
}

@Subscribe("itemsTable.edit")
public void onItemsTableEdit(Action.ActionPerformedEvent event) {
    Item selected = itemsTable.getSingleSelected();
    if (selected == null) {
        return;
    }

    screenBuilders.editor(itemsTable)
            .editEntity(selected)
            .withParentDataContext(getScreenData().getDataContext())
            .show();
}

It works perfectly!
Many Thanks.