Is there a method removes all columns in a table

Hi there,

I have a table filled with random data&columns on event. So everytime I generate a new table, I need to clear the data and columns from the last generation. I see there is a method to clear data “removeAllItems()”, is there any for remove columns? Here is the code sequenses I used, but it is not working properly, it removes some of the column and leaves the rest. I also tried new a table, but it does not help either.


		Collection cols = tblResult.getContainerPropertyIds();
		for(int k = 0; k < cols.size(); k++)

Unfortunately you can’t remove all columns at once.
But you can simplify your code:

for(Object col: tblResult.getContainerPropertyIds())  {

Or you just create a complete new Table and add it to the layout.

Thanks for your reply! Would you please try your code, it has the same effect as mine. That is, some of the columns are not removed. I don’t understand why. it seems there is always one column left in the table.

This could be from a ConcurrentModificationException in the for-loop. So try with the “toArray()” modification as noted below:

for(Object col: tblResult.getContainerPropertyIds().toArray())  {

A second thought reveals, your problem could occur if you use generated columns in your table. In this case you have to remember the column names by yourself, because the table don’t give you a way to retrieve them.

Hi, Thanks for your reply. I surrendered. I just create a new table and attach to the screen again, that helps. BTW, I am adding the column manually.


Just a note in case anyone is using it: this doesn’t work for Grid. It will throw an error stating that datasource cannot be set to null.

Yes, the idea is that you only use one datasource per Grid instance. If you need to change enough data to switch the data source, just create a new Grid.