Populate data of Default selected table row into another table

1.8k views Asked by At

I have a requirement which consists of one table at the top and a tab-sheet which consists of 3 tabs at the bottom. Within 3 tabs contains 3 different tables, and my requirement here is a when clicked on the top table some related data must be displayed in each of tables in the tab-sheet.

This functionality is working fine for me when I click on the table rows now but the problem here is when application is loaded, in the top table the first row must be selected by default and the related data must be populated and displayed in tab-sheet tables. How can I implement this by using built-in listeners? If example is provided it will be of great help.

1

There are 1 answers

0
miq On

Since the functionality is working after clicking a row, I can assume your listener is working properly.

I believe you can just use the top Table's method myTable.setValue(table.firstItemId()) after initializing the view. Assuming that your listener calls (for example) method myApplication.rowSelected(Item item) you can manually call this after setting the table value.

Example:

void init() {
    myTable.addListener(new ItemClickEvent.ItemClickListener() {
        void itemClick(ItemClickEvent event) {
            rowSelected(event.getItem());
        }
    });

    if(!myTable.getItemIds().isEmpty()) {
        Object firstId = myTable.firstItemId();
        myTable.setValue(firstId);
        myTable.rowSelected(myTable.getItem(firstId));
    }
}

void rowSelected(Item item) {
    // Do stuff
}