Search code examples
javagwtdatagriduibinder

GWT DataGrid not shown


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.


Solution

  • 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