1

I have a Datagrid which I am placing inside a FlowPanel. However, this datagrid is not visible unless I explicitly set its size by doing datagrid.setSize("100%", "250px").

I want the datagrid's width to be 100% but I want its height to change according to the number of rows in it. When is only do datagrid.setWidth("100%") the datagrid is still not visible. How do overcome this problem?

awareeye
  • 3,051
  • 3
  • 22
  • 22

2 Answers2

2

DataGrid needs to either have an explicit size or be put into a LayoutPanel and you must ensure an unbroken chain of LayoutPanels up to the RoutLayoutPanel.

Here are some possible solutions:

  • Use CellTable instead of DataGrid.
  • Calculate the required height (numer of rows * row height) and available size (getOffsetHeight on the FlowPanel) and manually set the height accordingly.
Ümit
  • 17,379
  • 7
  • 55
  • 74
  • I went with using a CellTable. Is there a way to make the header of CellTable static so that only the rows scroll just like in DataGrid. Is there a way to do that with the CellTable? – awareeye Jul 05 '13 at 06:45
  • Unfortunately the `CellTable` can't do that. That's what the `DataGrid` was made for. – Ümit Jul 05 '13 at 07:37
0

Set the width and height both to 100%. If that stretches things, try setting the height of rows to a specific number (from CSS, preferably), that should create rows of a fixed sized, with potentially empty space under it.

Marconius
  • 683
  • 1
  • 5
  • 13