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,

@Inject
protected GroupDatasource<TestEntity, UUID> entitiesDs;

@Inject
protected GroupTable<TestEntity> entitiesTable;

@Override
public void ready() {
    entitiesTable.setSelected(entitiesDs.getItems().isEmpty() ? null : entitiesDs.getItems().iterator().next());
}
2 Likes

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