5

I have a DataGrid which I want to grow vertically (height) as I add rows to it. The widget to add to the grid should be directly underneath the DataGrid. How do I do this?

The answer to "GWT DataGrid automatic height" was too obscure (if it was one). I tried placing the DataGrid in ResizeLayoutPanel, but it only shows the datagrid header.

Joel
  • 2,601
  • 4
  • 33
  • 44
  • 3
    Might I ask why you're using a DataGrid if you don't want it fixed-sized (or sized by the environment rather than by the content)? Wouldn't your problem be solved by a CellTable? (if you want horizontal scrolling, there are solutions with CellTable too) – Thomas Broyer Jun 14 '12 at 11:34
  • 1
    I had gone with DataGrid as I liked that the headers are pinned unlike CellTable. – Joel Jun 14 '12 at 14:16
  • 1
    Yes. That's why I used DataGrid, the headers are pinnable (stay in place). CellTables cannot be pinned as far as I know. – Joel Jun 14 '12 at 15:07
  • My current "solution" is to dynamically keep resizing the DataGrid, although I'm just guessing row height, maybe there is a way to determine header and row height? – Joel Jun 14 '12 at 15:09
  • What happens if you do not resize the grid? – Ganesh Kumar Jun 15 '12 at 04:30

1 Answers1

1

For those still struggling with CellTable (auto-height, pager always under the last line) and DataGrid (fixed header but height should be fixed and the pager will stay at the same place even if you got one line of data).

Don't forget they extend the same class : AbstractCellTable

So you can adapt your code easily (Note TableType is just an enum I created):

if (tableType == TableType.CELLTABLE) {
      // CellTable
      CustomTableWidgetCellTableResource resource = GWT.create(CustomTableWidgetCellTableResource.class);
      table = new CellTable<T>(10, resource);
    } else {
      // DataGrid
      CustomTableWidgetDataGridResource resource = GWT.create(CustomTableWidgetDataGridResource.class);
      table = new DataGrid<T>(10, resource);
      table.setHeight("470px"); // Default height
    }
Michael Laffargue
  • 10,116
  • 6
  • 42
  • 76