PDA

View Full Version : Problem with Grid's data



I_P
13 Sep 2011, 4:26 AM
Hello, I'm trying to make a grid:


protected void initialize()
{
LayoutContainer container = new LayoutContainer();
container.setLayout(new FitLayout());


ContentPanel cp = new ContentPanel();
cp.setHeading("Test");
cp.setSize(800, 600);


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

ColumnConfig firstNameColumn= new ColumnConfig("firstname","FirstName",200);
columns.add(firstNameColumn);


ColumnConfig lastNameColumn= new ColumnConfig("lastname","LastName",200);
columns.add(lastNameColumn);


ColumnModel columnmodel=new ColumnModel(columns);


ListStore<Person> ls=new ListStore<Person>();
List<Person> lp=getPersons();
ls.add(lp);

Grid<Person> grid = new Grid<Person>(ls,columnmodel);
grid.setBorders(true);

cp.add(grid);

container.add(cp, new FitData(50));
}



private List<Person> getPersons()
{
List<Person> p=new ArrayList<Person>();
Person person;
person=new Person();
person.setFirstName("FirstName");
person.setLastName("LastName");
p.add(person);
person=new Person();
person.setFirstName("FirstName2");
person.setLastName("LastName2");
p.add(person);
return p;
}

Class Person extends BaseModel.
Problem is that columns headers and data isn't shown together. I mean,
when I start application,there are shown only names of columns of grid, and no data. It may be a bit strange,but when I write: grid.setHideHeaders(true), data without headers is shown then. I'm new,so I don't know what problem may be in. I'll be very pleased if you could help me.

sven
13 Sep 2011, 4:28 AM
How does your Person class look like?

I_P
13 Sep 2011, 4:35 AM
public class Person extends BaseModel{




public Person() {
}

public Person(String firstname, String lastname)
{
setFirstName(firstname);
setLastName(lastname);
}


public String getFirstName() {
return get("firstname");
}


public String getLastName() {
return get("lastname");
}


public void setFirstName(String firstname) {
set("firstname", firstname);
}


public void setLastName(String lastname) {
set("lastname", lastname);
}

public String toString()
{
return getFirstName()+" "+getLastName();
}
}

toString method and constructor with parameters have been added later,first it was without them,but result was the same.

sven
13 Sep 2011, 4:39 AM
Try to add
cp.setLayout(new FitLayout()); Also you should size your "container" and not your "cp"

I_P
13 Sep 2011, 4:45 AM
It helped!! Thank you very much! :)