PDA

View Full Version : paging grid with json



helmishariff
11 Jul 2009, 1:24 AM
No problem with json grid but how to make paging grid with json. I get "loading" when try add paging toolbar to grid.

helmishariff
11 Jul 2009, 1:42 AM
My test code

List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
columns.add(new ColumnConfig("Sender", "Sender", 100));
columns.add(new ColumnConfig("Email", "Email", 165));
columns.add(new ColumnConfig("Phone", "Phone", 100));
columns.add(new ColumnConfig("State", "State", 50));
columns.add(new ColumnConfig("Zip", "Zip Code", 65));

// create the column model
ColumnModel cm = new ColumnModel(columns);

// defines the xml structure
ModelType type = new ModelType();
type.setRoot("record");
type.addField("Sender", "name");
type.addField("Email", "email");
type.addField("Phone", "phone");
type.addField("State", "state");
type.addField("Zip", "zip");

// use a http proxy to get the data
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
GWT.getHostPageBaseURL() + "data/data.json");
HttpProxy<String> proxy = new HttpProxy<String>(builder);

// need a loader, proxy, and reader
JsonLoadResultReader<ListLoadResult<ModelData>> reader = new JsonLoadResultReader<ListLoadResult<ModelData>>(
type);


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

loader.setRemoteSort(true);

ListStore<ModelData> store = new ListStore<ModelData>(loader);
final Grid<ModelData> grid = new Grid<ModelData>(store, cm);
grid.setBorders(true);
grid.setLoadMask(true);
grid.getView().setEmptyText("Please hit the load button." + GWT.getHostPageBaseURL());
grid.setAutoExpandColumn("Sender");


final PagingToolBar toolBar = new PagingToolBar(50);
toolBar.bind(loader);

ContentPanel panel = new ContentPanel();
panel.setFrame(true);
panel.setCollapsible(true);
panel.setAnimCollapse(false);
panel.setButtonAlign(HorizontalAlignment.CENTER);
//panel.setIcon(Examples.ICONS.table());
panel.setHeading("JSON Table Demo");
panel.setLayout(new FitLayout());
panel.add(grid);
panel.setSize(575, 350);

// add buttons
Button load = new Button("Load JSON", new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce) {
PagingLoadConfig config = new BasePagingLoadConfig();
config.setOffset(0);
config.setLimit(50);

loader.load(config);
}
});