I’m a little confused by your question: do you want the table to show all rows that the search returns, or do you want the table to be as high as the available space in the view?
For the former case, use Table.setPageLength(0). For the latter, set Table.setHeight(“100%”).
I tried this but it didn’t quite work for me. Perhaps I got something wrong?
When I tried it, the pagesize of the table is still 15. I can place the table on a Panel and use the Panel’s scrollbars instead of the Table’s scrollbars, but then I lose the table headings when I scroll down.
If, for example, the table is to hold 200 rows, but there is enough room to display 30 visible rows at a time, I’d like the Table’s pagesize to dynamically adjust for 30 visible rows. How do I achieve this?
Sorry, I should have been more explicit in my description.
My table is placed within a SplitPanel, so the space it has available to display rows can vary if the user moves the splitter before the table is displayed. I have a similar issue if perhaps the application runs on a different screen resolution, i.e. the number of rows that can be displayed is not always predetermined. I therefore want to be able to dynamically determine how many rows can be visible and adjust the pagelength accordingly.
I was hoping setSizeFull() or setHeight(“100%”) would work, but after calling these methods the table still only displays the default of 15 rows.
Just wondering whether there are any further thoughts on this topic. I’d like my table to set its number of rows to fill the page, but setHeight(“100%”) in various places does no good.
Matthew, I’ve found the behaviour seems to change with the level of layout nesting.
I can create, say, a VerticalLayout, add the table directly to it and set its expand ratio to occupy all the free space (setExpandRatio(table, 1.0f), and the page size becomes dynamic based on the amount of space it occupies.
However, if I add the VerticalLayout onto another previously created HorizontalLayout or VerticalLayout, then add the table, it no longer dynamically adjusts its page size.
I haven’t yet done extensive testing of this to determine exactly the conditions when it doesn’t work, but avoiding nesting so far works for me.
My situation is: I have a main window. Within this window is a tabsheet. One of the tabs contains a CustomComponent. The composition root of the CustomComponent is a VerticalLayout, and the VerticalLayout contains a table. This is the table that should be able to resize itself.
I do setSizeFull() on the CustomComponent, then setHeight(100%) on both the VerticalLayout and the table. I’ve also tried setExpandRatio(table,1.0f) on the VerticalLayout. Maybe I need to do something to the TabSheet?
Elsewhere in my application I have a SplitPanel which contains a table. I thought that the SplitPanel could adjust its height to accommodate the table, but it looks like the height of the SplitPanel needs to be set manually. Is this correct? If it is, I thought I could get the number of rows in the table (from Container.size()) and the row height, and then calculate the necessary SplitPanel height. But it doesn’t look like the API contains a function for querying a table’s row height. I tried setting row height manually with CSS as in the Book of Vaadin
Thanks very much for your help with these newbie questions. I’ve only been using Vaadin for a few days but despite these little frustrations I’m finding it to be an outstanding tool.
I didn’t realize I had to do setHeight(“100%”) and getContent.setHeight(“100%”) on the application’s main window.
It was also necessary to do setSizeFull() on the CustomComponents that were being added as tabs to the TabSheet. This is in addition to setHeight(“100%”) on the VerticalLayouts that are the composition roots for the CustomComponents.
I presume you don’t call Table.setPageLength() in this scenario and just let the component set the length based on its visible size, is that right? Very cool! Works nicely in a SplitPanel that can be user-adjusted as well as the browser height itself.
I have the same problem that the table only shown the default (15) lines.
I’ve put a VerticalLayout on the main Window, with some components and at the end a Table.
I’ve Table.setHeight(100%) but nothing… only those 15 lines…
My code is:
Window mainWindow = new Window("Test Application");
setMainWindow(mainWindow);
VerticalLayout mainLayout = new VerticalLayout();
VerticalLayout cabecalho = new VerticalLayout();
HorizontalLayout barraFerramentas = new HorizontalLayout();
cabecalho.setHeight("10px");
barraFerramentas.setHeight("20px");
Table table = new Table("Table");
table.setHeight("100%");
table=fillTable(table); // This puts some data on the table
cabecalho.addComponent(new Label("cabecalho"));
barraFerramentas.addComponent(new Label("barra"));
mainLayout.addComponent(cabecalho);
mainLayout.addComponent(barraFerramentas);
mainLayout.addComponent(table);
mainWindow.addComponent(mainLayout);
I’ve tried to put the table inside a Panel, VerticalLayout, HorizontalLayout but it allways keeps the same height.
Maybe you’re seeing the same thing I was in
this post (which I managed to solve right after I posted, argh).
The layout will split the space evenly among the components, even if some of them have fixed sizes. So you can set the sizes for each, including “100%” for the one(s) you want to expand to fill space, and then use this to tell the layout to expand it: