Best way to navigate to first column of first entity in refreshed DataGrid

I have a lookup field and a table attached. They look like this:


<window xmlns="http://schemas.haulmont.com/cuba/window.xsd" caption="msg://caption" 
    class="com.paslists.rade.web.batchEntry.BatchEntry" focusComponent="companyLookup"
        messagesPack="com.paslists.rade.web.batchEntry">
    <dsContext>
        <collectionDatasource id="companiesDs" class="com.paslists.rade.entity.Company" view="_minimal">
            <query>
                <![CDATA[select e from rade$Company e order by e.compname]]>
            </query>
        </collectionDatasource>
        <collectionDatasource id="batchhdrsDs"  class="com.paslists.rade.entity.Batchhdr"  view="batchhdr-view">
            <query>
                <![CDATA[select e from rade$Batchhdr e where e.company.id in (:component$companyLookup) order by e.batchdate, e.id]]>
            </query>
        </collectionDatasource>
        <collectionDatasource id="updtransDs" class="com.paslists.rade.entity.Updtrans" view="updtrans-edit-view">
            <query>
                <![CDATA[select e from rade$Updtrans e where e.traynumber.id= :ds$batchhdrsDs.id]]>
            </query>
        </collectionDatasource>
    <dialogMode height="600" width="800"/>
    <layout expand="batchSplit">
        <lookupField id="companyLookup" align="TOP_CENTER" caption="Company" optionsDatasource="companiesDs"
                     required="true"  requiredMessage="Please choose a Company" width="200px"/>
        <split id="batchSplit"  orientation="vertical" pos="300px"  width="100%">
            <vbox id="vboxBatchhdr"  expand="batchGrid"  height="500px"  spacing="true">
                <buttonsPanel height="30px">
                    <button id="addButton" action="batchhdrTable.create" caption="Create Batch"icon="icons/create.png" />
                    <button id="saveButton" action="batchhdrTable.save"  caption="Save Batch"icon="icons/save.png" />
                    <button id="removeButton"  action="batchhdrTable.remove" caption="Delete Batch" icon="icons/remove.png" />
                </buttonsPanel>
                <grid id="batchGrid"  height="400px" spacing="true">
                    <columns>
                        <column flex="6.0"/>
                        <column/>
                        <column/>
                        <column/>
                    </columns>
                    <rows>
                        <row>
                            <table id="batchhdrTable" editable="true" height="400px" width="650px">
                                <actions>
                                    <action id="create" invoke="onAddBatchhdr"/>
                                    <action id="save" invoke="onSaveBatchhdr"/>
                                    <action id="remove"/>
                                </actions>
                                <columns>
                                    <column id="batchdate" caption="Batch Date" dateFormat="MM/dd/yyyy" editable="true"/>
                                    <column id="id" caption="Batch Number" editable="true"/>
                                    <column id="batchtype" caption="Batch Type" editable="true"/>
                                    <column id="reccount" caption="Count"/>
                                    <column id="totamount" caption="Tot Amount"/>
                                    <column id="username" caption="Entered By"/>
                                </columns>
                                <rows datasource="batchhdrsDs"/>
                            </table>
                        </row>
                    </rows>
                </grid>
        </split>
    </layout>
</window>

I have a ValueChangeListener on the lookup field created in the ready() function of my AbstractWindow. When the field changes, the listener refreshes the datasource for the table. Once that happens, I want the focus to move to the “batchdate” column of the first row of the table.


        // reload all batch headers when company changes
        companyLookup.addValueChangeListener(e -> {
                Company company = (Company) e.getValue();
            batchhdrsDs.refresh();
            updtransDs.refresh();
            if (!batchhdrsDs.getItemIds().isEmpty()) {
                batchhdrTable.requestFocus(batchhdrsDs.getItem(batchhdrsDs.getItemIds().iterator().next()), "batchdate");
            }
        });

It is not working. When I choose a company, the table populates correctly, but I have to click in the row to move the cursor (and to populate the corresponding updtransDs. I can’t figure out how to set the “current row” in a collection datasource or the corresponding table.

What is the best way to move to the first item in the batchhdrDs collection and then to move to the first field in that row in the table?

Hello, Eric!

This bug corresponds to this issue - https://youtrack.cuba-platform.com/issue/PL-8900 and have been already fixed.

Regards,

Gleb

Thanks!