Andris
(Andris Lapinsh)
May 11, 2010, 11:49am
1
Hi all!
Code:
Table table = new Table();
table.setSelectable(true);
...
addComponent(table);
table.select(new Integer(1));
Works correctly. After opening the window, selects the first row in the table
But code:
table.addListener(new ItemSetChangeListener() {
private static final long serialVersionUID = -9008670032927481120L;
@Override
public void containerItemSetChange(ItemSetChangeEvent event) {
if (event.getContainer().size() == 0) {
selectedItem = 0;
updateButtonLayoutUp.recordsExist(false);
} else {
updateButtonLayoutUp.recordsExist(true);
}
table.select(new Integer(1));
}
});
Not selects first row in the table, after refresh data container.
Why is this happening?
Henri
(Henri Muurimaa)
May 11, 2010, 6:43pm
2
Table.select() takes an item ID as a parameter, not an index. To select the first item try something like this:
table.select(table.getItemIds().iterator().next());
Andris
(Andris Lapinsh)
May 12, 2010, 6:47am
3
Table.select() takes an item ID as a parameter, not an index. To select the first item try something like this:
table.select(table.getItemIds().iterator().next());
Hello Henri!
Unfortunately your code does not select the first row 8o
Risto
(Risto Yrjänä)
May 14, 2010, 10:13am
5
It depends whether you replace the container in the table, or add items to it. The ItemSetChangeEvent is only fired when items are added to or removed from the container.
Andris
(Andris Lapinsh)
May 14, 2010, 5:32pm
6
This is understandable. Through ItemSetChangeEvent I know that the container has been updated. How do I choose the first entry in the table?
Risto
(Risto Yrjänä)
May 17, 2010, 7:08am
7
You might have some other problems in your code. This example seemed to work fine:
final Table table = new Table();
table.addContainerProperty("foo", String.class, null);
table.setSelectable(true);
table.addListener(new Container.ItemSetChangeListener() {
public void containerItemSetChange(ItemSetChangeEvent event)
table.select(table.firstItemId());
}
});
Button addItemButton = new Button("Add item");
addItemButton.addListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
table.addItem(Math.random()).getItemProperty("foo").setValue("bar");
}
});
Andris
(Andris Lapinsh)
May 17, 2010, 12:04pm
8
Risto, thanks, that’s the “key” that solves my problem