3

I'm just trying to display some rows in a GXT grid using the code below. However the grid is only displaying it's headers. What am I doing wrong here?

public void onModuleLoad() {

    //MainScreen mainScreen = new MainScreen();
    RootPanel rootPanel = RootPanel.get("main_div");

    BeanModel u1 = new User( "firstname1", "lastname1");    
    BeanModel u2 = new User( "firstname2", "lastname2");    

    ListStore<BeanModel> store = new ListStore<BeanModel>(); 
    store.add( u1);
    store.add( u2);

    List<ColumnConfig> configList = new ArrayList<ColumnConfig>();  

    ColumnConfig column1 = new ColumnConfig();  
    column1.setId("firstname");  
    column1.setHeader("FirstName");  
    column1.setWidth(150);  
    configList.add(column1);  

    ColumnConfig column2 = new ColumnConfig();  
    column2.setId("lastname");  
    column2.setHeader("LastName");  
    column2.setWidth(150);  
    configList.add(column2);  

    ColumnModel columnModel = new ColumnModel( configList);  

    Grid<BeanModel> grid = new Grid<BeanModel>( store, columnModel);
    grid.setBorders(true);
    grid.setWidth(300);


    rootPanel.add( grid);   
}

The User object is as below:

public class User extends BeanModel {

private static final long serialVersionUID = 1L;

public User(){}

public User( String firstName, String lastName){
    set( "firstname", firstName);
    set( "lastname", lastName);
}

public String getFirstName() {
    return get("firstname");
}
public void setFirstName(String firstName) {
    set( "firstname", firstName);
}
public String getLastName() {
    return get("lastName");
}
public void setLastName(String lastName) {
    set( "lastname", lastName);
}   

}

UPDATE After I remove the headers from the column configs the data is displayed! Does anybody know what is the real problem here?

jaxvy
  • 5,040
  • 1
  • 21
  • 22

3 Answers3

2

I was able to get the grid display correctly by specifying a size to the grid.

Grid<BaseModel> grid = new Grid<BaseModel>( listStore, columnModel);
grid.setSize( 600, 300);    
grid.getView().setForceFit(true);   //Makes the vertical scrollbar
jaxvy
  • 5,040
  • 1
  • 21
  • 22
1

Why don't you try adding the model data after you have added in the column configs.

Add the model data after the grid is declared.

Blessed Geek
  • 21,058
  • 23
  • 106
  • 176
1

Set the grid height, or give it a parent with a layout that will size it. If you want a Grid that grows automatically, take a look at the autoheight grid http://www.sencha.com/examples/#autoheightgrid. There is a reason this isn't the default though: Generally you want the headers to stay put and allow the content to scroll, instead of letting the entire thing scroll the page when it gets too big.

Colin Alworth
  • 17,801
  • 2
  • 26
  • 39