jej2003
9 Sep 2009, 12:15 PM
I am trying to get paging to work in GXT and all of my attempts seem to have failed. I can get my first page of data to load the total is always the same as the page size. What needs to be done to get this to work properly?
My XML is of the form
<Result total="500" offset="0">
<Term>...</Term>
the relevant portion of code is
ModelType type = new ModelType();
type.setRoot("Result");
type.setRecordName("Term");
type.addField("ID");
type.addField("Sign");
type.addField("Concept");
type.setTotalName("total");
// use a http proxy to get the data
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
"http://localhost/resteasy-jaxrs/ddf/term");
//ScriptTagProxy<String> proxy = new ScriptTagProxy<String>("http://localhost/resteasy-jaxrs/ddf/term");
HttpProxy<String> proxy = new HttpProxy<String>(builder);
// RpcProxy<PagingLoadResult<ModelData>> proxy = new RpcProxy<PagingLoadResult<ModelData>>() {
// @Override
// public void load(Object loadConfig, AsyncCallback<PagingLoadResult<ModelData>> callback){
//
// }
// };
// need a loader, proxy, and reader
XmlPagingLoadResultReader<PagingLoadResult<ModelData>> reader = new XmlPagingLoadResultReader<PagingLoadResult<ModelData>>(type);
// loader
final PagingLoader<PagingLoadResult<ModelData>> loader = new BasePagingLoader<PagingLoadResult<ModelData>>(proxy, reader);
loader.setRemoteSort(true);
//ListStore<ModelData> store = new ListStore<ModelData>(loader);
GroupingStore<ModelData> store = new GroupingStore<ModelData>(loader);
store.groupBy("Concept");
final PagingToolBar toolBar = new PagingToolBar(20);
toolBar.bind(loader);
List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
//columns.add(new ColumnConfig("ID", "ID", 100));
columns.add(new ColumnConfig("Sign", "Sign", 165));
columns.add(new ColumnConfig("Concept", "Concept", 100));
final ColumnModel cm = new ColumnModel(columns);
final Grid<ModelData> grid = new Grid<ModelData>(store, cm);
grid.setStateId("pagingGridExample");
grid.setStateful(true);
grid.addListener(Events.Attach, new Listener<GridEvent<ModelData>>() {
public void handleEvent(GridEvent<ModelData> be) {
PagingLoadConfig config = new BasePagingLoadConfig();
config.set("sign", "Ada*");
Map<String, Object> state = grid.getState();
if (state.containsKey("offset")) {
int offset = (Integer)state.get("offset");
int limit = (Integer)state.get("limit");
config.set("page", offset/limit + 1);
//config.set("pageSize", limit);
config.setOffset(offset);
//config.setLimit(limit);
}
if (state.containsKey("sortField")) {
config.setSortField((String)state.get("sortField"));
config.setSortDir(SortDir.valueOf((String)state.get("sortDir")));
}
loader.load(config);
}
});
GroupingView view = new GroupingView();
view.setShowGroupedColumn(false);
view.setForceFit(true);
view.setGroupRenderer(new GridGroupRenderer() {
public String render(GroupColumnData data) {
String f = cm.getColumnById(data.field).getHeader();
String l = data.models.size() == 1 ? "Item" : "Items";
return f + ": " + data.group + " (" + data.models.size() + " " + l + ")";
}
});
grid.setView(view);
grid.setLoadMask(true);
grid.setBorders(true);
how do I get it to find the total attribute?
My XML is of the form
<Result total="500" offset="0">
<Term>...</Term>
the relevant portion of code is
ModelType type = new ModelType();
type.setRoot("Result");
type.setRecordName("Term");
type.addField("ID");
type.addField("Sign");
type.addField("Concept");
type.setTotalName("total");
// use a http proxy to get the data
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
"http://localhost/resteasy-jaxrs/ddf/term");
//ScriptTagProxy<String> proxy = new ScriptTagProxy<String>("http://localhost/resteasy-jaxrs/ddf/term");
HttpProxy<String> proxy = new HttpProxy<String>(builder);
// RpcProxy<PagingLoadResult<ModelData>> proxy = new RpcProxy<PagingLoadResult<ModelData>>() {
// @Override
// public void load(Object loadConfig, AsyncCallback<PagingLoadResult<ModelData>> callback){
//
// }
// };
// need a loader, proxy, and reader
XmlPagingLoadResultReader<PagingLoadResult<ModelData>> reader = new XmlPagingLoadResultReader<PagingLoadResult<ModelData>>(type);
// loader
final PagingLoader<PagingLoadResult<ModelData>> loader = new BasePagingLoader<PagingLoadResult<ModelData>>(proxy, reader);
loader.setRemoteSort(true);
//ListStore<ModelData> store = new ListStore<ModelData>(loader);
GroupingStore<ModelData> store = new GroupingStore<ModelData>(loader);
store.groupBy("Concept");
final PagingToolBar toolBar = new PagingToolBar(20);
toolBar.bind(loader);
List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
//columns.add(new ColumnConfig("ID", "ID", 100));
columns.add(new ColumnConfig("Sign", "Sign", 165));
columns.add(new ColumnConfig("Concept", "Concept", 100));
final ColumnModel cm = new ColumnModel(columns);
final Grid<ModelData> grid = new Grid<ModelData>(store, cm);
grid.setStateId("pagingGridExample");
grid.setStateful(true);
grid.addListener(Events.Attach, new Listener<GridEvent<ModelData>>() {
public void handleEvent(GridEvent<ModelData> be) {
PagingLoadConfig config = new BasePagingLoadConfig();
config.set("sign", "Ada*");
Map<String, Object> state = grid.getState();
if (state.containsKey("offset")) {
int offset = (Integer)state.get("offset");
int limit = (Integer)state.get("limit");
config.set("page", offset/limit + 1);
//config.set("pageSize", limit);
config.setOffset(offset);
//config.setLimit(limit);
}
if (state.containsKey("sortField")) {
config.setSortField((String)state.get("sortField"));
config.setSortDir(SortDir.valueOf((String)state.get("sortDir")));
}
loader.load(config);
}
});
GroupingView view = new GroupingView();
view.setShowGroupedColumn(false);
view.setForceFit(true);
view.setGroupRenderer(new GridGroupRenderer() {
public String render(GroupColumnData data) {
String f = cm.getColumnById(data.field).getHeader();
String l = data.models.size() == 1 ? "Item" : "Items";
return f + ": " + data.group + " (" + data.models.size() + " " + l + ")";
}
});
grid.setView(view);
grid.setLoadMask(true);
grid.setBorders(true);
how do I get it to find the total attribute?