Reset table start itemid to 1 after table.removeAllitem()?

I’m using vaading 7 to show my data from remote server.
There are many different data sources, which have various data with same format.
The data from one data source will be listed in a vaadin table, which has been chosen.
When I changed the datasource, I hope the data in table could be refreshed.
To implement that, I called the “table.removeAllItem()” and “table.addItem()” to add new items into the table.
Unfortunately it seems that the new itemid by using “table.additem()” in table will not be started with 1, but the next number of table.size() before I called removeAllItem().
Is there any idea to reset the start itemid of table?

Do you know what data has changed in the remote data source? Would it be possible to only update part of the data rather than repopulating the whole container?

For example, let’s assume you have a field called “name” and you know the name of item “4” has changed, then you could do something like this

table.getItem(4).getItemProperty("name").setValue(newName); That updates the name of only one item.

If you need to rebuild the whole container every time, then you have a couple of options. One is to simply create a completely new container instance. Table uses internally an IndexedContainer, so creating a new IndexedContainer instances and setting it to the table as its container data source does exactly the same thing.

Another altnernative is to use a different way to add items. table.addItem() returns an object which is the
item id
. The item id is just an incremented integer, as you noticed. Instead of using addItem() without arguments, you can use table.addItem() which returns the item instance. In the latter, you have full control of the item ids yourself. If you want the index to start from 1, then you can simply do something like this

for(int i=1; i <= myDataSource.length(); i++) {
   Item item = container.addItem(i);

Excellent. That’s what I want. Thank you for nice help.
It seems that by using

Item item = container.addItem(i); is more efficient than creating a new container, which must init addContainerProperty again.

I have just read the addItem() code from Class IndexedContainer, which is the default implement of Container. addItem() takes a private int nextGeneratedItemId as the new item id. That means, I can’t manually reset this id to 1 and must use addItem(1) instead right?

That’s correct, there’s no method/setter for resetting/setting the value of nextGeneratedItemId, it’s purely an internal variable.

Thanks. I learned much about it.