0

I'm trying to update my data widget from a CellTable to DataGrid and I basically thought I online a change from @UiField CellTable<T> to @UiField DataGrid<T> but thats not it.

private void init() {
        sortHandler = new ListHandler<GWTUser>(getUsers());

        dataGrid.setWidth("100%");
        dataGrid.setHeight("100%");
        dataGrid.setAutoHeaderRefreshDisabled(true);
        dataGrid.setEmptyTableWidget(emptyDb);
        dataGrid.addColumnSortHandler(sortHandler);
        dataGrid.setVisibleRangeAndClearData(dataGrid.getVisibleRange(), true);

        dataGrid.setRowCount(1, true);
        dataGrid.clearTableWidth();
        dataGrid.redraw();

        // Setup Cell Table.
        initCellTable();

        // Connect the table to the data provider.
        dataProvider.addDataDisplay(dataGrid);

    }

    private void initCellTable() {

        // userId Column
        TextColumn<GWTUser> userIdColumn = new TextColumn<GWTUser>() {

            @Override
            public String getValue(GWTUser object) {
                return object.getUserId();
            }

        };
        dataGrid.addColumn(userIdColumn, Lang.LABEL_USER_USERID);

        dataGrid.addColumnSortHandler(sortHandler);
        dataGrid.getColumnSortList().push(userIdColumn);
        dataGrid.getColumnSortList().push(userIdColumn);

    }

    @Override
    public void setUserList(List<GWTUser> users) {

            setUsers(users);

            dataGrid.setRowCount(getUsers().size(), true);
            dataGrid.setRowData(0, getUsers());
            dataGrid.setPageSize(getUsers().size());
            dataGrid.setVisibleRange(new Range(0,dataGrid.getRowCount()));
            dataGrid.redraw();

            sortHandler.setList(getUsers());


    }

uiBinder:

    <g:VerticalPanel>                               
        <g:ScrollPanel ui:field="listScrollPanel">
            <c:DataGrid styleName= ui:field='dataGrid' width="100%" height="98%"/>
        </g:ScrollPanel>

        <g:HorizontalPanel>
            <g:Button ui:field="createButton">New</g:Button>
            <g:Button ui:field="refreshButton">Refresh</g:Button>
            <g:Button ui:field="removeSelectedButton">Delete Selection</g:Button>
        </g:HorizontalPanel>

    </g:VerticalPanel>

When I change the region where my DataGrid should be with the chrome dev tool, the data with the tables is there but not shown.

as basic information: init is called by the constructor and setUserList is called in my activitiy when I get the data from a rest service. thanks for any help.

vicR
  • 789
  • 4
  • 23
  • 52
  • 1
    You'll have to set the height to an explicit value like `500px`. [Related](http://stackoverflow.com/questions/7874168/gwt-datagrid-automatic-height). – Baz Oct 01 '14 at 09:05
  • works fine thx, but now i have to redesign everything to make it dynamic again .... – vicR Oct 01 '14 at 11:41
  • Great, I've added an answer. – Baz Oct 01 '14 at 11:45

1 Answers1

1

The DataGrid requires an explicitly set height. This means that you can't use percentages (e.g. 100%), but rather have to use something like 500px.

Here is a related question:

GWT DataGrid automatic height

Community
  • 1
  • 1
Baz
  • 36,440
  • 11
  • 68
  • 94
  • I'm having a `ResizeLayoutPanel`around everything and I'm trying to resize it by `void onListContentResize(ResizeEvent event) { dataGrid.setHeight(Integer.toString(event.getHeight())); listScrollPanel.setPixelSize(event.getWidth(), event.getHeight()-80); } is this now even possible with a `CellTable` it worked. – vicR Oct 01 '14 at 11:51
  • 1
    @vicR Try `dataGrid.setHeight(Integer.toString(event.getHeight()) + "px");` – Baz Oct 01 '14 at 11:53
  • is it possible that i need to call `redraw()` after my height change ? but doesn't it cost a lot of computing time? – vicR Oct 01 '14 at 12:41
  • oh. sorry my mistake. – vicR Oct 09 '14 at 08:09