0

Edit

Since no one has responded to my original question I think it is worthwhile adding a description of what I am attempting to accomplish, in addition to the existing description of how I have attempted to achieve my goal:

My objective is to create a DataGrid that will resize according to any change in size of its container. This is not difficult to do, but I have an additional requirement, which is to have Panel widgets above and below the DataGrid; these two Panel widgets will contain widgets that are fixed in size (e.g., a row of buttons or text input widgets). My expectation was that a HeaderPanel would be perfect for this, but this doesn't seem to work (as can be seen in my original question, below). So ... an alternative to my original question ("why doesn't this work") is: what is the best way to implement this requirement?

My original question:

I have a DataGrid in the content area of a HeaderPanel, but the detail lines in the DataGrid are not being displayed (the DataGrid column headings are showing, however). Is there an issue with using a DataGrid in the content area of a HeaderPanel? Or is this a simple misuse of the widgets? I'm adding the HeaderPanel to the RootLayoutPanel, which should provide the necessary resize notification (I think). Here is my UiBinder code:

<ui:UiBinder
  xmlns:ui='urn:ui:com.google.gwt.uibinder'
  xmlns:g='urn:import:com.google.gwt.user.client.ui'
  xmlns:c='urn:import:com.google.gwt.user.cellview.client'>
  <g:HeaderPanel>
    <g:SimplePanel/>
    <g:ResizeLayoutPanel>
      <c:DataGrid ui:field='dataGrid'/>
    </g:ResizeLayoutPanel>
    <g:HorizontalPanel>
      <g:Button
        ui:field='addRecordButton'
        text='Add Record'/>
      <g:Label ui:field='numberOfRecordsLabel'/>
    </g:HorizontalPanel>
  </g:HeaderPanel>
</ui:UiBinder>

and here is the Java code:

public class TempGWT implements EntryPoint {

@UiField
Button                    addRecordButton;
@UiField
DataGrid<Record>          dataGrid;
@UiField
Label                     numberOfRecordsLabel;

private ArrayList<Record> _recordList;

interface TempGWTBinder extends UiBinder<Widget, TempGWT> {
}

private static class Record {
private String _field1;
}

@Override
public void onModuleLoad() {
  _recordList = new ArrayList<Record>();
  TempGWTBinder binder = GWT.create(TempGWTBinder.class);
  Widget widget = binder.createAndBindUi(this);
  Column<Record, String> field1Column = new Column<Record, String>(new TextInputCell()) {
    @Override
    public String getValue(final Record record) {
      return record._field1;
    }
  };
  dataGrid.addColumn(field1Column, "Field 1");
  RootLayoutPanel.get().add(widget);
}

@UiHandler("addRecordButton")
public void onAddRecordButtonClick(final ClickEvent event) {
  Record record = new Record();
  record._field1 = "Record " + (_recordList.size() + 1);
  _recordList.add(record);
  dataGrid.setRowData(_recordList);
  numberOfRecordsLabel.setText("Records:" + _recordList.size());
}

}

I've attempted to trace the execution and, although I'm not certain, it looks as though the following happens when I change the size of the browser window and the "resize" request is received by the DataGrid (I've skipped some of the "unimportant" methods):

  DataGrid#onResize
  HeaderPanel#forceLayout
  ScrollPanel#onResize

The DataGrid object contains a HeaderPanel, which contains the headings for the DataGrid and a ScrollPanel. I don't know whether this is the key to the problem, but the ScrollPanel in the DataGrid's HeaderPanel contains a DataGrid$TableWidget object, and TableWidget does not implement RequiresResize; the ScrollPanel#onResize method only sends the resize to its child if the child implements RequiresResize.

Andy King
  • 1,632
  • 2
  • 20
  • 29

1 Answers1

1

The Tables and Frames section of the GWT Developer's Guide makes it clear that I just needed to use a width/height of 100% for the DataGrid! Like so:

  <c:DataGrid
    ui:field='dataGrid'
    width='100%'
    height='100%'/>
Andy King
  • 1,632
  • 2
  • 20
  • 29