Shrink table to content size?

I have a table which has a IndexedContainer as a datasource.
The table lists the IndexedContainer as it should, but the table height always get bigger than the actual content of the table… How on earth can I get the table to shrink to the height of the content ONLY?
I think I have tried everything, but the damn table still gets higher with an empty space in the bottom of the table…

Please help me, I need the help quite fast… :confused:

The following works for me (BeanItemContainer as opposed to IndexedContainer though).

Table with unlimited row count (non paged):

table.setPageLength(0);

Table with limited row count (0…n, paged):

// feed table data ...
table.setPageLength(Math.min(actualRowCount, myRowsPerPageLimit);

In case of further difficulties you may want to try some trick like this:

table.removeAllItems();
table.setPageLength(0);
// feed table data ...
table.setPageLength(Math.min(actualRowCount, myRowsPerPageLimit);

Thanks for a fast answer :slight_smile:
That worked pretty good.
I’m interested in the table.setPageLength(Math.min(actualRowCount, myRowsPerPageLimit) code…
How do I achieve the actualRowCount?
It’s perfect if the table e.g. contains 2 items and the size of the table then will be 2 items and if you add more items the table increas in size up to the row-limit… But how do I actually achieve this?

Thanks in advance!

Exactly what you described is achievable. I do that in my solution.

If you know the underlaying ItemContainer content changes, you can act accordingly.

int actualRowCount = container.size();
table.setPageLength(Math.min(actualRowCount, myRowsPerPageLimit);

That way table height grows dynamically up to myRowsPerPageLimit then shows vertical scrollbar.