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.core.EventObject;
11: import com.gwtext.client.data.*;
12: import com.gwtext.client.widgets.PagingToolbar;
13: import com.gwtext.client.widgets.Panel;
14: import com.gwtext.client.widgets.ToolTip;
15: import com.gwtext.client.widgets.form.Field;
16: import com.gwtext.client.widgets.form.NumberField;
17: import com.gwtext.client.widgets.form.event.FieldListenerAdapter;
18: import com.gwtext.client.widgets.grid.GridPanel;
19: import com.gwtext.sample.showcase2.client.SampleData;
20: import com.gwtext.sample.showcase2.client.SampleGrid;
21: import com.gwtext.sample.showcase2.client.ShowcasePanel;
22: import com.gwtextux.client.data.PagingMemoryProxy;
23:
24: public class LocalPagingSample extends ShowcasePanel {
25:
26: public String getSourceUrl() {
27: return "source/grid/LocalPagingSample.java.html";
28: }
29:
30: public Panel getViewPanel() {
31: if (panel == null) {
32: panel = new Panel();
33:
34: PagingMemoryProxy proxy = new PagingMemoryProxy(SampleData
35: .getCompanyDataLarge());
36: RecordDef recordDef = new RecordDef(new FieldDef[] {
37: new StringFieldDef("company"),
38: new FloatFieldDef("price"),
39: new FloatFieldDef("change"),
40: new FloatFieldDef("pctChange"),
41: new DateFieldDef("lastChanged", "n/j h:ia"),
42: new StringFieldDef("symbol"),
43: new StringFieldDef("industry") });
44:
45: ArrayReader reader = new ArrayReader(recordDef);
46: final Store store = new Store(proxy, reader, true);
47:
48: final GridPanel grid = new SampleGrid();
49: grid.setStore(store);
50: grid.setWidth(600);
51: grid.setHeight(250);
52: grid.setTitle("Grid that pages Local / In-Memory data");
53: grid.setAutoExpandColumn("pctChange");
54:
55: final PagingToolbar pagingToolbar = new PagingToolbar(store);
56: pagingToolbar.setPageSize(5);
57: pagingToolbar.setDisplayInfo(true);
58: pagingToolbar
59: .setDisplayMsg("Displaying companies {0} - {1} of {2}");
60: pagingToolbar.setEmptyMsg("No records to display");
61:
62: NumberField pageSizeField = new NumberField();
63: pageSizeField.setWidth(40);
64: pageSizeField.setSelectOnFocus(true);
65: pageSizeField.addListener(new FieldListenerAdapter() {
66: public void onSpecialKey(Field field, EventObject e) {
67: if (e.getKey() == EventObject.ENTER) {
68: int pageSize = Integer.parseInt(field
69: .getValueAsString());
70: pagingToolbar.setPageSize(pageSize);
71: }
72: }
73: });
74:
75: ToolTip toolTip = new ToolTip("Enter page size");
76: toolTip.applyTo(pageSizeField);
77:
78: pagingToolbar.addField(pageSizeField);
79: grid.setBottomToolbar(pagingToolbar);
80: store.load(0, 5);
81:
82: panel.add(grid);
83: }
84:
85: return panel;
86: }
87:
88: public String getIntro() {
89: return "This example demonstrates loading a Grid with local array data and local paging. It also demonstrates how to change "
90: + "the page size dymanically. Enter a value in number field on the Paging Toolbar and hit Enter.";
91: }
92: }
|