Height mode
First you need to switch the height mode. Instead of having CSS-oriented height, you need line-oriented height.
myGrid.setHeightMode( HeightMode.ROW );
Then you can set the number of rows to display. You can specify fractional strings because the argument number-of-rows is double.
this.setHeightByRows( myDouble );
Avoid null lines
So, to show that all rows pass a double number with the number of rows in your database containing Grid support. But check for zero, as the grid does not tolerate any rows. If you do not have data in your container, specify an arbitrary number of empty lines.
int size = this.getContainerDataSource().size(); double rows = ( size > 0 ) ? size : myDefaultRowCount;
Two line error
In my own project, I came across an unpleasant error in Vaadin 7.4.2, where setting the number of lines from two (range from 2.0d to 2.7d) leads to high processor load and delays in minutes, because the page partially loads, but never ends. I cannot reproduce in the sample application, but I cannot determine any other reason in my own application. As a workaround, my code just uses 3.0d (or 2.8d ) instead of any 2.0d .
if ( rows == 2.0d ) { rows = 2.8d; // Workaround for weird bug. }
Class subclass
Here is a subclass of Grid that adds a listener for any change in the rowset. The listener resets the grid height to display all rows of fresh data.
package com.example; import com.vaadin.data.Container; import com.vaadin.shared.ui.grid.HeightMode; public class GridAllRowsTall extends Grid { static double defaultRowsCount = 3.0d;
source share