// use a http proxy to get the data
RequestBuilder builderContrats = new RequestBuilder(RequestBuilder.GET, theSearchUrl/* + "?" + theParam*/);
HttpProxy<String> proxyContrats = new HttpProxy<String>(builderContrats);
MyJsonPagingLoadResultReader<PagingLoadResult<ModelData>> reader = new MyJsonPagingLoadResultReader<PagingLoadResult<ModelData>>(typeContrat);
final BasePagingLoader<PagingLoadResult<ModelData>> loaderContrats = new BasePagingLoader<PagingLoadResult<ModelData>>(proxyContrats, reader);
loaderContrats.setRemoteSort(true);
// need a loader, proxy, and reader
//JsonLoadResultReader<ListLoadResult<ModelData>> readerContrats = new JsonLoadResultReader<ListLoadResult<ModelData>>(typeContrat);
//final BaseListLoader<ListLoadResult<ModelData>> loaderContrats = new BaseListLoader<ListLoadResult<ModelData>>(proxyContrats,readerContrats);
final ListStore<ModelData> storeContrats = new ListStore<ModelData>(loaderContrats);
final PagingToolBar toolBar = new PagingToolBar(50);
toolBar.bind(loaderContrats);
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
check/debug the return value of the Method basePagingLoadResult.getTotalLength(). The value must be > 50. Set the breakpoint at the method read in your JsonLoadResultReader.
I do this.
But now my Grid is filled with all the datas !
The request return 47 items : thses 47 items are in my grid and the PagingToolBar say : "1 page of 1" (i ask 10 items per page).
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
ColumnConfig column = new ColumnConfig();
column = new ColumnConfig();
column.setId("ref");
column.setHeader("Ref");
column.setAlignment(HorizontalAlignment.LEFT);
column.setWidth(410);
configs.add(column);
// use a http proxy to get the data
//MessageBox.alert("Model",theSearchUrl+"?" + theParam, null);
RequestBuilder builderContrats = new RequestBuilder(RequestBuilder.GET, theSearchUrl);
HttpProxy<String> proxyContrats = new HttpProxy<String>(builderContrats);
// need a loader, proxy, and reader
// Without Paging
//JsonLoadResultReader<ListLoadResult<ModelData>> readerContrats = new JsonLoadResultReader<ListLoadResult<ModelData>>(typeContrat);
//final BaseListLoader<ListLoadResult<ModelData>> loaderContrats = new BaseListLoader<ListLoadResult<ModelData>>(proxyContrats,readerContrats);
// With Paging
JsonLoadResultReader<PagingLoadResult<ModelData>> readerContrats =
new JsonLoadResultReader<PagingLoadResult<ModelData>>(typeContrat) {
protected ListLoadResult<ModelData> newLoadResult(Object loadConfig, List<ModelData> models) {
//PagingLoadConfig pagingConfig = (PagingLoadConfig) loadConfig;
//PagingLoadResult<ModelData> result = new BasePagingLoadResult<ModelData>(models, pagingConfig.getOffset(), pagingConfig.getLimit());
PagingLoadResult<ModelData> result;
if(loadConfig != null) {
PagingLoadConfig pagingConfig = (PagingLoadConfig) loadConfig;
result = new BasePagingLoadResult<ModelData>(models,
pagingConfig.getOffset(), pagingConfig.getLimit());
//MessageBox.alert("Model","Offset = " + String.valueOf(pagingConfig.getOffset()) + " - Limit = " + String.valueOf(pagingConfig.getLimit()), null);
} else {
//MessageBox.alert("Model","loadConfig is null", null);
result = new BasePagingLoadResult<ModelData>(models, 0,models.size());
}
final PagingLoader<PagingLoadResult<ModelData>> loaderContrats = new BasePagingLoader<PagingLoadResult<ModelData>>(proxyContrats,readerContrats);
loaderContrats.addListener(Loader.BeforeLoad, new Listener<LoadEvent>() {
public void handleEvent(LoadEvent be) {
be.<ModelData> getConfig().set("start", be.<ModelData> getConfig().get("offset"));
}
});
//loaderContrats.load(0,perPage);
final ListStore<ModelData> storeContrats = new ListStore<ModelData>(loaderContrats);
final PagingToolBar toolBar = new PagingToolBar(perPage);
toolBar.bind(loaderContrats);
ColumnModel cm = new ColumnModel(configs);
ContentPanel cp = new ContentPanel();
cp.setHeading("Your Result");
cp.setCollapsible(false);
cp.setAnimCollapse(false);
cp.setLayout(new FitLayout());
cp.setSize(700, 300);
cp.setFrame(false);
cp.setBottomComponent(toolBar);
final Grid<ModelData> grid = new Grid<ModelData>(storeContrats, cm);
grid.setAutoExpandColumn("ref");
//grid.getView().setAutoFill(true);
grid.getView().setEmptyText("Sorry - no matches. Please try some different terms.");
grid.setBorders(true);
grid.setLoadMask(true);
grid.setStateful(true);
grid.addListener(Events.Attach, new Listener<GridEvent<ModelData>>() {
public void handleEvent(GridEvent<ModelData> be) {
PagingLoadConfig config = new BasePagingLoadConfig();
config.setOffset(0);
config.setLimit(perPage);
if (state.containsKey("offset")) {
int offset = (Integer)state.get("offset");
int limit = (Integer)state.get("limit");
config.setOffset(offset);
config.setLimit(limit);
}