PDA

View Full Version : Json Paging Grid is showing all result in a single page



rluk
7 Mar 2011, 11:09 AM
I am having a problem with my json paging grid, somehow it's showing all the result instead of the pagesize limit. Like if I have 10 records in total and the pagesize limit is 5, instead of showing only 5, it is showing all 10, but the toolbar would show "Displaying 1-5 of 10". Could someone give me an idea of how to make this work? Thanks!

public void onRender(ElementParent, int index){

super.onRender(parent,index);
setLayout(new FitLayout());

RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, "test/testing");

ModelType type = new ModelType();
type.setRoot("employee");
type.addField("EmployeeID", "EmployeeID");

HttpProxy<PagingLoadResult<ModelData>> proxy = new HttpProxy<PagingLoadResult<ModelData>> (builder);

JsonPagingLoadResultReader<PagingLoadResult<ModelData>> reader = new JsonPagingLoadResultReader<PagingLoadResult<ModelData>> (type);

final PagingLoader<PagingLoadResult<ModelData>> loader = new BasePagingLoader<PagingLoadResult<ModelData>> (proxy, reader);

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

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

List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
configs.add(new ColumnConfig("EmployeeID", "EmployeeID", 100));

ColumnModel cm = new ColumnModel(configs);

Grid<ModelData> grid = new Grid<ModelData> (employeeList, cm);
grid.setBoarders(true);
grid.setColumnLines(true);
grid.setColumnReordering(true);

ContentPanel cp = new ContentPanel();
cp.setLayout(new FitLayout());
cp.setBottomComponent(toolBar);

cp.add(grid);
add(cp);
}

the json looks like this:

{
"employee":
[
{""EmployeeID": 10},
{""EmployeeID": 11},
{""EmployeeID": 12},
{""EmployeeID": 13},
{""EmployeeID": 14},
{""EmployeeID": 15},
{""EmployeeID": 16},
{""EmployeeID": 17},
{""EmployeeID": 18},
{""EmployeeID": 19},
{""EmployeeID": 20}
]
}

sven
7 Mar 2011, 11:14 PM
Probably your server returns all 10 records, you need to only return the requested size, starting from the offset which is also requested

rluk
8 Mar 2011, 7:06 AM
Thank you for your reply, you are right that the server returned 10 records. But when I made the server only return 5 records in json, the UI now display only a total 5 records and "Displaying 1-5 of 5". Or did I misunderstand what you were saying?