clear table


I have a table which has a container datasource. everything works fine here. problem arises when I try one of the simplest possible actions… clear the table. i’ve tried removeallitems, nothing. then calling table.commit() afterwards. nothing. then trying to call removeallitems on my indexed container…no success here neither…then i tried to set datacontainer of the table to null, throws an exception…

im sure there must be a simple way of achieving this but i just cant seem to find it…



well i’ve solved it…

first i removed columns and headers from the table

setVisibleColumns(new Object[]{});
setColumnHeaders(new String[]{});

and then set the table’s containerdatasource to previously initialized empty indexedcontainer…

it did the trick but I still think this should have to be done much easier…

how strange. removeAllItems on eighter the container or table is the right way to do it. Sounds like a bug if you have to do that. Could you send a minimal testcase where removeAllItems doesn’t do anyting?

Which is the container initially used for the table?

Table forwards removeAllItems() to the container, where implementing it is optional - e.g. some database backed containers should not support removing items through the container. Also, the container might be emptied but without notifying the table properly about the change (this would be a bug in the container).

Well, he said he is using a IndexedContainer, which supports removeAllIItems(). Table inherits AbstractSelect which uses IndexedContainer if no container is specified. Also, Table.setContainerDataSource(null) does this:

if (newDataSource == null) {
  newDataSource = new IndexedContainer();

so it should work too.

that is correct, i could probably pass “null” as datacontainersource to the table, after i clear its columnheaders and columnorder…

but then i end up with table without headers…and that is something i don’t want. i WANT the headers to stay and the content of the table to clear… my previously mentioned trick does this: make another indexedcontainer, with no rows and keep it just for the need to clear the table. so you dont actually clear anything, you just swap filled container with an empty one.

still too much mumbo-jumbo for one simple action… could be a bug, i will probably post some more code this afternoon, too much work to do for now…


I can not believe that starting o Vaadin 15 days ago would put me to read problems unsolved from 7 years ago.

I changed a table to a Grid because the table was giving me a lot of errors in loading data, but now I am stucked since I can not remove the items (contacts) when loading a new customer

clear a table is not a problem nowday, maybe it was 7 years ago