PDA

View Full Version : JSON paging grid



sanechek
20 Aug 2009, 6:22 AM
Hello.

I have a problem with paging JSON grid in next code:



public void onModuleLoad() {
List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
columns.add(new ColumnConfig("date_time", "Date", 100));
columns.add(new ColumnConfig("phone_number", "Phone", 150));

ModelType type = new ModelType();
type.setTotalName("total");
type.setRoot("result");
type.addField("date_time", "date_time");
type.addField("phone_number", "phone_number");

RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, "/ajax/events/all");
HttpProxy<String> proxy = new HttpProxy<String>(builder);

JsonPagingLoadResultReader<PagingLoadResult<ModelData>> reader =
new JsonPagingLoadResultReader<PagingLoadResult<ModelData>>(type);
BasePagingLoader<PagingLoadResult<ModelData>> loader =
new BasePagingLoader<PagingLoadResult<ModelData>>(proxy, reader);

PagingToolBar toolBar = new PagingToolBar(10);
toolBar.bind(loader);

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

Grid<ModelData> grid = new Grid<ModelData>(store, new ColumnModel(columns));

ContentPanel panel = new ContentPanel();
panel.setSize(450, 300);
panel.setLayout(new FitLayout());
panel.add(grid);
panel.setBottomComponent(toolBar);

loader.load(0, 10);

RootPanel.get().add(panel);
}
It is loaded the next page when i click "Next" button on paging tool bar. But the tool bar stays on the first page anywhere, so if i click "Next" again it loads data with offset=10 all the time. Saying in other words the PagingToolBar stays on the first page all the time. What am i doing wrong?

sanechek
21 Aug 2009, 2:03 AM
I solved it. I wrote own MyJsonPagingLoadResultReader class instead of native JsonPagingLoadResultReader:


public class MyJsonPagingLoadResultReader<D> extends JsonLoadResultReader<D> {

public MyJsonPagingLoadResultReader(ModelType modelType) {
super(modelType);
}

@Override
protected BasePagingLoadResult<ModelData> newLoadResult(Object loadConfig, List<ModelData> models) {
PagingLoadConfig config = (PagingLoadConfig) loadConfig;

return new BasePagingLoadResult<ModelData>(models,
config.getOffset(), -1);
}
}

It's looks like the bug in native JsonPagingLoadResultReader class. Because it returns instance of BasePagingLoadResult without offset:


return new BasePagingLoadResult<ModelData>(models);