Datasource not clearing

equipmentAddonsDs.clear();
       
        if (equipment.getEquipmentAddons().size() > 0) {
            for (EquipmentAddons equipmentAddon : equipment.getEquipmentAddons()) {
                equipmentAddonsDs.addItem(equipmentAddon);
            }
        }

When I run the code above, the first iteration shows 0 items in the equipmentAddonsDs. On the second iteration, there are 51. Then, 52, 53, and so on. There are always an extra 50 items after the first .addItem(). Can you think of a reason why adding 1 item to a ds would add an extra 50?

No. Could you give us more details about the datasource type and how you count its size? Also, you could debug your code and find out what it really contains.

I am passing a CollectionDataSource used in a table to a window, using

Window window = openWindow(“project$EquipmentAddons.browse”, WindowManager.OpenType.DIALOG, params);

passing the CollectionDatasource in as a param. The window has a GroupDataSource, so I’m clearing it, then copying the items over from the CollectionDataSource that was passed in. I can’t get that to work!

So, I’ve tried passing in the Equipment item instead, but that is causing the error where it’s adding tons of data when the first item is copied over.

All I need to do is open a table in a new window, because the table doesn’t fit on the screen. It sounds so easy, but I just can’t get it. How would you do it?

//The datasource in the source screen.

<datasource id="equipmentDs"  
                    class="com.tab.edge.entity.collateral.Equipment"  
                    view="equipment-view">  
            <collectionDatasource id="equipmentAddonsDs" //   <----  
                                  property="equipmentAddons"/>  
      </datasource>  
...  

//The dataSource and table in the target screen

<dsContext>  
        <groupDatasource id="equipmentAddonsDs"  
                         class="com.tab.edge.entity.collateral.EquipmentAddons"  
                         view="_local">  
            <query>  
                <!&#91;CDATA&#91;select e from edge$EquipmentAddons e&#93;&#93;>  
            </query>  
        </groupDatasource>  
    </dsContext>  
    <dialogMode height="600"  
                width="800"/>  
    <layout spacing="true">  
        <groupTable id="equipmentAddonsTable"  
                    caption="Equipment Addons"  
                    editable="true"  
                    height="100%"  
                    width="100%">  
            <columns>  
                <column id="active"  
                        align="CENTER"  
                        editable="true"  
                        width="70px"/>  
                <column id="retailAmount"  
                        width="80px"/>  
                <column id="name"/>  
            </columns>  
            <rows datasource="equipmentAddonsDs"/>  
            <rowsCount/>  
        </groupTable>  
    </layout>

I see. The datasource loads first 50 records and you add more.

You should set the following parameters for the datasource: refreshMode=“NEVER” and allowCommit=“false”. Query is obviously not needed.

So, for example I want to show the list of order lines in a separate window:

I open the window from the Order editor passing the Order instance as a parameter:

public void onShowBtnClick() {
    openWindow("sales$OrderLine.browse", WindowManager.OpenType.DIALOG, ParamsMap.of("order", getItem()));
}

The sales$OrderLine.browse screen descriptor:

<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
        caption="msg://browseCaption"
        class="com.company.sales.web.orderline.OrderLineBrowse"
        focusComponent="orderLinesTable"
        lookupComponent="orderLinesTable"
        messagesPack="com.company.sales.web.orderline">
    <dsContext>
        <groupDatasource id="orderLinesDs"
                         allowCommit="false"
                         class="com.company.sales.entity.OrderLine"
                         refreshMode="NEVER"
                         view="orderLine-with-product"/>
    </dsContext>
    <dialogMode height="600"
                width="800"/>
    <layout spacing="true">
        <groupTable id="orderLinesTable"
                    height="100%"
                    width="100%">
            <columns>
                <column id="product"/>
                <column id="quantity"/>
            </columns>
            <rows datasource="orderLinesDs"/>
            <rowsCount/>
        </groupTable>
    </layout>
</window>

The screen controller:

public class OrderLineBrowse extends AbstractLookup {

    @WindowParam
    private Order order;

    @Inject
    private GroupDatasource<OrderLine, UUID> orderLinesDs;

    @Override
    public void ready() {
        for (OrderLine orderLine : order.getLines()) {
            orderLinesDs.includeItem(orderLine);
        }
    }
}

Hope this helps.

Thank you so much! I tried a lot of things, but not the “allowCommit=“false””, and “refreshMode=“NEVER”” part.
You’re awesome.