01: /*
02: * GWT-Ext Widget Library
03: * Copyright(c) 2007-2008, GWT-Ext.
04: * licensing@gwt-ext.com
05: *
06: * http://www.gwt-ext.com/license
07: */
08: package com.gwtext.sample.showcase2.client.grid;
09:
10: import com.gwtext.client.data.*;
11: import com.gwtext.client.widgets.Panel;
12: import com.gwtext.client.widgets.grid.ColumnConfig;
13: import com.gwtext.client.widgets.grid.ColumnModel;
14: import com.gwtext.client.widgets.grid.GridPanel;
15: import com.gwtext.sample.showcase2.client.ShowcasePanel;
16:
17: public class JsonGridSample extends ShowcasePanel {
18:
19: public String getSourceUrl() {
20: return "source/grid/JsonGridSample.java.html";
21: }
22:
23: public String getJsonDataUrl() {
24: return "source/grid/JsonGridSample.json.html";
25: }
26:
27: public Panel getViewPanel() {
28: if (panel == null) {
29: panel = new Panel();
30:
31: HttpProxy dataProxy = new HttpProxy("data/countries.json");
32: final RecordDef recordDef = new RecordDef(new FieldDef[] {
33: new StringFieldDef("abbr", "abbr"),
34: new StringFieldDef("name", "name"),
35: new IntegerFieldDef("area", "area"),
36: new IntegerFieldDef("population", "population"), });
37: JsonReader reader = new JsonReader(recordDef);
38: reader.setRoot("data");
39: reader.setTotalProperty("totalCount");
40:
41: final Store store = new Store(dataProxy, reader, true);
42: store.load();
43:
44: ColumnModel columnModel = new ColumnModel(
45: new ColumnConfig[] {
46: new ColumnConfig("Abbreviation", "abbr",
47: 100, true),
48: new ColumnConfig("Country", "name", 75,
49: true),
50: new ColumnConfig("Area", "area", 75, true),
51: new ColumnConfig("Population",
52: "population", 75, true) });
53:
54: GridPanel grid = new GridPanel();
55: grid.setStore(store);
56: grid.setColumnModel(columnModel);
57: grid.setWidth(375);
58: grid.setHeight(350);
59: grid.setTitle("Json Grid");
60: grid.setFrame(true);
61: grid.stripeRows(true);
62: grid.setIconCls("grid-icon");
63:
64: panel.add(grid);
65: }
66: return panel;
67: }
68:
69: public String getIntro() {
70: return "This example shows how to create a grid from remote Json data.";
71: }
72: }
|