Auto select first row of table when screen openned

Can I set the table or datasource to select the first item automatically when screen is loaded?
By default, no row is selected.

Hello, @thuylx!

You can use setSelected method of table. For example,

protected GroupDatasource<TestEntity, UUID> entitiesDs;

protected GroupTable<TestEntity> entitiesTable;

public void ready() {
    entitiesTable.setSelected(entitiesDs.getItems().isEmpty() ? null : entitiesDs.getItems().iterator().next());

I put these command in init() so it does not work.
I move to ready() as you advised, it works now.
Many thanks.

1 Like