Linked Questions

Popular Questions

DataGrid showing nothing

Asked by At

I am adding a DataGrid to a SimpleLayoutPanel in a FlexTable. I can't get any data to show up or even the headers. Anytime I call a method in the DataGrid like setHeight(), my entire FlexTable disappears and I have a blank page.

I have tried the DataGrid w/o the SimpleLayoutPanel ( userPanel in my code) and have no difference. I have tried this with a CellTable and ScrollPanel and get the same results.

public AdminViewImpl() {

    SimpleLayoutPanel contentPanel = new SimpleLayoutPanel();
    initWidget(contentPanel);
    contentPanel.setWidth("100%");
    contentPanel.setHeight("100%");

    final FlexTable adminTable = new FlexTable();
   FlexTable.FlexCellFormatter cellFormatter = adminTable.getFlexCellFormatter();
    adminTable.addStyleName("flexTable");
    adminTable.setWidth("99%");
    adminTable.setCellSpacing(5);
    adminTable.setCellPadding(3);

    cellFormatter.setHorizontalAlignment(0,0,HasHorizontalAlignment.ALIGN_CENTER);
    cellFormatter.setColSpan(0,1,2);
    adminTable.setHTML(0,0,"<h1> GRAPL AUTOMATION</h1>");
    contentPanel.add(adminTable);

    VerticalPanel buttonPanel = new VerticalPanel();

    buttonPanel.getElement().getStyle().setBorderStyle(Style.BorderStyle.SOLID);
    cellFormatter.setVerticalAlignment(0,1,HasVerticalAlignment.ALIGN_MIDDLE);
    cellFormatter.setHorizontalAlignment(0,1,HasHorizontalAlignment.ALIGN_CENTER);
      addButton = new Button("Add User");

    addButton.setStyleName("addButton");
    buttonPanel.add(addButton);


    adminTable.setWidget(0,1,buttonPanel);


    userPanel = new SimpleLayoutPanel();
    userPanel.setSize("1000px","200px");
    userPanel.getElement().getStyle().setBorderStyle(Style.BorderStyle.SOLID);
    cellFormatter.setVerticalAlignment(1,0,HasVerticalAlignment.ALIGN_MIDDLE);
    cellFormatter.setHorizontalAlignment(1,0,HasHorizontalAlignment.ALIGN_CENTER);
    cellFormatter.setColSpan(1,0,3);
    cellFormatter.setHeight(1,0,"200px");
    //userTable.setHeight("10px");
    //userTable.setAutoHeaderRefreshDisabled(true);
    // Set the message to display when the table is empty.
   // userTable.setEmptyTableWidget(new Label("Grid has no Data"));
    userPanel.add(userTable);


    adminTable.setWidget(1,0,userPanel);
   //userTable.redraw();
}

The data is loaded from the presenter into this method:

 @Override
 public void setTableData(List<User> userDetails) {
    userTable = new DataGrid<User>();

    TextColumn<User> columnUserId= new TextColumn<User>() {
        @Override
        public String getValue(User user) {
            return user.getUser_id();
        }
    };

    userTable.addColumn(columnUserId,"UserID");
    userTable.setColumnWidth(columnUserId,20,Style.Unit.PX);

    TextColumn<User> columnName = new TextColumn<User>() {
        @Override
        public String getValue(User user) {
            return user.getName();
        }
    };

    userTable.addColumn(columnName,"Name");
    //userTable.setColumnWidth(columnName,60,Style.Unit.PX);
    TextColumn<User> columnRole = new TextColumn<User>() {
        @Override
        public String getValue(User user) {
            return user.getRole();
        }
    };

    userTable.addColumn(columnRole,"Role");
    TextColumn<User> columnIsActive = new TextColumn<User>() {
        @Override
        public String getValue(User user) {
            return user.getIsActive();
        }
    };

    userTable.addColumn(columnIsActive,"Active");
    TextColumn<User> columnProduct = new TextColumn<User>() {
        @Override
        public String getValue(User user) {
            return user.getProduct();
        }
    };

    userTable.addColumn(columnProduct, "Product");
    userTable.setSelectionModel(selectionModel);


    userTable.setRowCount(userDetails.size());
    userTable.setRowData(0,userDetails);
    //userTable.redraw();



}

Related Questions