I've tried both Grid.setUndefined()
and Grid.setHeight("-1px")
and neither works. They should both be doing the same but if my grid only has say 3 items then the bottom of the grid is empty and the height is significantly taller than 3 rows.
Asked
Active
Viewed 3,234 times
0

Stephane Grenier
- 15,527
- 38
- 117
- 192
-
Are you adding Grid component with expanding? – Dawid Fieluba Dec 04 '17 at 15:07
3 Answers
3
Try setHeightByRows
method (Java doc).

Steffen Harbich
- 2,639
- 2
- 37
- 71
-
That's exactly what I did but the last row was a bit truncated. However it's good enough for now. – Stephane Grenier Dec 13 '17 at 04:40
1
Here is my proposition for workaround:
grid.getDataProvider().addDataProviderListener( dataProviderEvent ->
grid.setHeightByRows( grid.getDataProvider().size( new Query() ) )
);

Dawid Fieluba
- 1,271
- 14
- 34
-
Your solution work great, But you should check the size of your datas. It should be more than zero rows, otherwise it will return error. – Mankeomorakort Jan 28 '19 at 10:42
1
Set the grid HeightMode to UNDEFINED:
grid.setHeightMode(HeightMode.UNDEFINED);
-
4Welcome to Stack Overflow! While this code could solve the problem, it is best to add elaboration and explain how it works for people who might not understand this piece of code. – Papershine Apr 25 '18 at 10:24