PDA

View Full Version : Paging Grid not displaying data?



rluk
9 Jan 2011, 5:12 PM
I am a newbie of GXT and trying to set up a paging grid. The grid shows up but the data does not and wonder if any of you could help?

Thanks in advance!

public void onModuleLoad() {
RootPanel.get().add(new PagingExample());
}

public class PagingExample extends LayoutContainer {
protected void onRender(Element target, int index){
super.onRender(target, index);
final FlowLayout layout = new FlowLayout(10);
setLayout(layout);

PagingModelMemoryProxy proxy = new PagingModelMemoryProxy(TestData.getEmployees());
PagingLoader<PagingLoadResult<ModelData>> loader = new BasePagingLoader<PagingLoadResult<ModelData>>(proxy);
loader.setRemoteSort(true); ;

ListStore<Employee> employeeList = new ListStore<Employee>(loader);

final PagingToolBar toolBar = new PagingToolBar(5);
toolBar.bind(loader);
loader.load(0, 5);

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

ColumnConfig column = new ColumnConfig();
column.setId("name");
column.setHeader("Employee Name");
column.setWidth(200);
configs.add(column);

column = new ColumnConfig("department", "Department", 150);
configs.add(column);

column = new ColumnConfig("designation", "Designation", 150);
configs.add(column);

column = new ColumnConfig("salary", "Slary", 100);
configs.add(column);

column = new ColumnConfig("joiningdate", "Joining Date", 100);
column.setDateTimeFormat(DateTimeFormat.getShortDateFormat());
configs.add(column);
ColumnModel cm = new ColumnModel(configs);
Grid<Employee> grid = new Grid<Employee>(employeeList, cm);
grid.setStyleAttribute("borderTop", "none");
grid.setAutoExpandColumn("name");
grid.setBorders(true);
grid.setStripeRows(true);

ContentPanel cp = new ContentPanel();
cp.setBodyBorder(true);
cp.setHeading("Employee List");
cp.setSize(600, 300);
cp.add(grid);
cp.setBottomComponent(toolBar);
add(cp);

}

}
}

sven
10 Jan 2011, 1:26 PM
Please post your TestData.getEmployees method.

rluk
12 Jan 2011, 10:40 AM
Here is the my TestData.getEmployee()

public class TestData {

public static List<Employee> getEmployees()
{
List<Employee> employees = new ArrayList<Employee>();
DateTimeFormat f = DateTimeFormat.getFormat("yyyy-mm-dd");
employees.add(new Employee("Hollie Voss","General Administration","Executive Dir ector",150000,f.parse("2006-05-01")));
employees.add(new Employee("Emerson Milton","Information Technology","CTO",12000 0,f.parse("2007-03-01")));
employees.add(new Employee("Christina Blake","Information Technology","Project M anager",90000,f.parse("2008-08-01")));
employees.add(new Employee("Heriberto Rush","Information Technology","Senior S/W Engineer",70000,f.parse("2009-02-07")));
employees.add(new Employee("Candice Carson","Information Technology","S/W Engine er",60000,f.parse("2007-11-01")));
employees.add(new Employee("Chad Andrews","Information Technology","Senior S/W E ngineer",70000,f.parse("2008-02-01")));
employees.add(new Employee("Dirk Newman","Information Technology","S/W Engineer" ,62000,f.parse("2009-03-01")));
employees.add(new Employee("Bell Snedden","Information Technology","S/W Engineer ",73000,f.parse("2007-07-07")));
employees.add(new Employee("Benito Meeks","Marketing","General Manager",105000,f .parse("2008-02-01")));
employees.add(new Employee("Gail Horton","Marketing","Executive",55000,f.parse(" 2009-05-01")));
employees.add(new Employee("Claudio Engle","Marketing","Executive",58000,f.parse ("2008-09-03")));
employees.add(new Employee("Buster misjenou","Accounts","Executive",52000,f.pars e("2008-02-07")));

return employees;
}
}

Thanks!

sven
12 Jan 2011, 12:12 PM
And also your Employee class. I will need to have all depencies.

rluk
12 Jan 2011, 12:34 PM
Sorry..here you go:

public class Employee extends BaseModel {
private static final long serialVersionUID = 1L;

public Employee() {
}
public Employee(String name, String department, String designation,double salary, Date joiningdate) {
set("name", name);
set("department", department);
set("designation", designation);
set("salary", salary);
set("joiningdate", joiningdate);
}
public Date getJoiningdate() {
return (Date) get("joiningdate");
}
public String getName() {
return (String) get("name");
}
public String getDepartment() {
return (String) get("department");
}
public String getDesignation() {
return (String) get("designation");
}
public double getSalary() {
Double salary = (Double) get("salary");
return salary.doubleValue();
}
public String toString() {
return getName();
}
}

The toolbar shows the correct number of employees I have there ("Displaying 1-5 of 12), so I think the loader has get the values, but the data doesn't show up.

Thank you again for help.

sven
12 Jan 2011, 12:39 PM
Ok so now who have posted everything:

The issue is that you are probably not sizing. Try to add:
cp.setLayout(new FitLayout());

rluk
12 Jan 2011, 12:42 PM
I would like to add that I try with ListView as well and have similar problem. There are rows showing up, but they are empty.

ListStore<Employee> employeeList = new ListStore<Employee>();
employeeList.add(TestData.getEmployees());
ListView<Employee> lv = new ListView<Employee>();
lv.setStore(employeeList);
add(lv);


Thank you again.

sven
12 Jan 2011, 12:48 PM
lv.setDisplayProperty("name");

rluk
12 Jan 2011, 6:49 PM
Both case are working now. Thank you very much for your help!

rluk
13 Jan 2011, 7:56 AM
Ok so now who have posted everything:

The issue is that you are probably not sizing. Try to add:
cp.setLayout(new FitLayout());

Another question if you don't mind, I notice that I also need to set the contentpanel size in order for the paging grid data to show up (cp.setSize(600, 300);) is there a way that i can get the content panel to automatically fill the page?

Thanks!

rluk
13 Jan 2011, 10:10 AM
I can answer my own question again. Using setLayout(new FitLayout()); just is what I need. :)