PDA

View Full Version : Paging in GXT



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?

jej2003
9 Sep 2009, 12:38 PM
So it seems I got the paging total to work, but the code in the example paging has something like


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.setOffset(offset);
config.set("pageSize", limit);
config.setLimit(limit);
}
if (state.containsKey("sortField")) {
config.setSortField((String)state.get("sortField"));
config.setSortDir(SortDir.valueOf((String)state.get("sortDir")));
}
loader.load(config);
}
});


but this never gets called again. Where is the appropriate place to listen for these events? I would have thought the toolBar would have handled much of this so I think I am doing something wrong. Does anyone have an example with a remote XML data source with paging?

jej2003
9 Sep 2009, 12:51 PM
nope, I lied...looks like the total is ignored. Any help on this would be appreciated.

jej2003
10 Sep 2009, 4:16 AM
So doing @total seems to have worked properly, the total count no comes up right, but whenever i hit next page on the paging tool bar it always says it's still displaying page 1 even though the correct offset is sent to the server, where does this get read from?

Arno.Nyhm
14 Sep 2009, 6:27 AM
did you know this bug info related to your problem:

http://www.extjs.com/forum/showthread.php?t=79419&highlight=BasePagingLoadResult

Arno.Nyhm
14 Sep 2009, 6:40 AM
pls point the next time to your new thread if you open a new one with the same topic...
http://www.extjs.com/forum/showthread.php?p=385146#post385146