1. #1
    Sencha User
    Join Date
    Sep 2011
    Posts
    20
    Vote Rating
    0
    I_P is on a distinguished road

      0  

    Default Answered: Problem with Grid's data

    Answered: Problem with Grid's data


    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.

  2. Try to add
    Code:
    cp.setLayout(new FitLayout());
    Also you should size your "container" and not your "cp"

  3. #2
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,703
    Vote Rating
    107
    Answers
    60
    sven is just really nice sven is just really nice sven is just really nice sven is just really nice

      0  

    Default


    How does your Person class look like?

  4. #3
    Sencha User
    Join Date
    Sep 2011
    Posts
    20
    Vote Rating
    0
    I_P is on a distinguished road

      0  

    Default


    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.

  5. #4
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,703
    Vote Rating
    107
    Answers
    60
    sven is just really nice sven is just really nice sven is just really nice sven is just really nice

      0  

    Default


    Try to add
    Code:
    cp.setLayout(new FitLayout());
    Also you should size your "container" and not your "cp"

  6. #5
    Sencha User
    Join Date
    Sep 2011
    Posts
    20
    Vote Rating
    0
    I_P is on a distinguished road

      0  

    Default


    It helped!! Thank you very much!