ScrollTo newly created item in browse screen

I have a material.browse screen where I have an option to copy material. After I have copied a material using the following code:

 openEditor(material, WindowManager.OpenType.NEW_TAB, ParamsMap.of("copyMaterial", copyMaterial)).addCloseWithCommitListener(() ->
                materialsDs.refresh());

The newly created material is refreshed on the browser screen. Now I want the cursor is scrolled onto the newly created material in the browser screen immediately after refresh.

As we know the following way selects the expected item in the table

materialsDataGrid.scrollTo(copyMaterial);

But where do I call this at have it scrolled to automatically?

Hi,

There is the known issue with auto-scrolling. In your case, you can try to call scrollTo in CollectionChangeListener with type REFRESH.

Hi Gleb
Thanks. May I request you to share a code snipped?

regards

Could you attach a demo project, so that I can update it according to my suggestion?

Hi Gleb
Please find attached a test Application as requested. Take the following steps:

  1. Create an order and save, say order no 1 created. Stay in Order.browse screen
  2. Place the cursor on order no.1 and click on Copy button and update wit as Order no. 2 in the editor screen. When you save it, you will see the selection in order.browse will remain as earlier but what I want is, the cursor should move on the newly copied order no. 2. Thanks for your suggestions.

testApplication.zip (87.2 KB)

Hi,

The following works for me both for Table and DataGrid:

public void onCopy(Component source) {
        Order order = ordersDs.getItem();

        Order order1 = metadata.create(Order.class);
        order1.setName(order.getName());
        order1.setQuantity(order.getQuantity());

        openEditor(order1, WindowManager.OpenType.DIALOG)
                .addCloseWithCommitListener(() -> {
                    ordersDs.refresh();

                    ordersDataGrid.setSelected(order1);
                    ordersDataGrid.scrollTo(order1);
                    ordersDataGrid.requestFocus();
                });
    }

Thank you Gleb, worked perfectly.