I need to delete data from the grid (container) and then i need refresh the rows. How I can do it?
Grid grid = new Grid();
IndexedContainer container = new I
Using Vaadin 7.4.9 is very tedious when it comes to Grids.
Removing items has to be done using container.removeItem(item)
.
Additionally refreshing a Grid is easy in Vaadin 7.7 (method addition of refreshAll
and refreshRow()
) and especially easy in Vaadin 8 (using events and a Dataprovider).
In Vaadin 7 you will have to hack it a bit by calling clearSortOrder
which automatically redraws the grid.
The following code is used when you update the UI from another Thread (i.e. not in a ValueChangeListener) however you need to enable the Vaadin-Push Addon which is a separate dependency.
getUI.access(() -> {
List sortOrders = new ArrayList<>();
grid.getSortOrder().forEach(sortOrder -> sortOrders.add(sortOrder));
grid.recalculateColumnWidths();
grid.clearSortOrder();
grid.setSortOrder(sortOrders);
getUI().push();
});
Edit: If you do the deletion with a buttonClick or ValueChangeEvent of a combobox you can simply do:
component.addValueChangeListener(e -> {
Item item = container.getItem(35);
container.removeItem(item);
container.addItem(35);
item.getItemProperty("Person5").setValue("SS");
grid.recalculateColumnWidths();
grid.clearSortOrder();
grid.refreshAllRows();
});
However be careful, your implementation has a ValueChangeListener on the container which calls container.removeItem(35)
this will result in another trigger another ValueChanged-Event which will try to remove item number 35 again. You have to use another component for the ValueChangeListener otherwise you run into an endless cycle