-
Notifications
You must be signed in to change notification settings - Fork 0
/
editor-grid-panel.html
executable file
·173 lines (149 loc) · 4.95 KB
/
editor-grid-panel.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<html>
<head>
<title>Stores</title>
<link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css" />
<style>
body{
background-color:#aeaeae;
}
#container{
background-color:#ccc;
}
</style>
<script src="extjs/adapter/ext/ext-base.js"></script>
<script src="extjs/ext-all-debug.js"></script>
<script>
Ext.BLANK_IMAGE_URL = 'extjs/resources/images/default/s.gif';
// field mappings
var recordFields = [
{name: 'id', mapping: 'id'},
{name: 'firstname', mapping: 'firstname'},
{name: 'lastname', mapping: 'lastname'},
{name: 'street', mapping: 'street'},
{name: 'city', mapping: 'city'},
{name: 'state', mapping: 'state'},
{name: 'zip', mapping: 'zip'},
{name: 'department', mapping: 'department'},
// this is for tracking new records. just a pattern...
{name: 'newRecordId', mapping: 'newRecordId'}
];
// we expect to re-use this...
var remoteProxy = new Ext.data.ScriptTagProxy( {
url : 'http://extjsinaction.com/dataQuery.php'
});
var remoteJsonStore = new Ext.data.JsonStore({
fields : recordFields,
proxy : remoteProxy,
idProperty: 'id', // ensures store tracks ids as defined by data
totalProperty : 'totalCount', // optional field for the "total" results, for pagination
root : 'records', // important: the property where the data is found
id : 'ourRemoteStore',
autoLoad : false, // tell store NOT to auto-fetch upon initialization
remoteSort : true // tell store NOt to sort locally, due to paginated results
});
// now you create the Field editors for the ColumnModel later on
// direct instantiate a TextField for re-use in the editor...
var textFieldEditor = new Ext.form.TextField();
// lazy load (config object) a Combobox field
var comboEditor = {
xtype : 'combo',
triggerAction : 'all',
displayField : 'state',
valueField : 'state',
store : {
xtype : 'jsonstore',
root : 'records',
fields : ['state'],
proxy : new Ext.data.ScriptTagProxy({
url : 'http://extjsinaction.com/getStates.php'
})
}
};
var numberFieldEditor = {
xtype : 'numberfield',
minLength : 5,
maxLength : 5
};
// now for our column model, mapping fields (in the store) to columns
// it is here we define the editors...
var columnModel = [
{
header : 'Last Name',
dataIndex : 'lastname',
sortable : true,
editor: textFieldEditor
},
{
header : 'First Name',
dataIndex : 'firstname',
sortable : true,
editor: textFieldEditor
},
{
header : 'Street Address',
dataIndex : 'street',
sortable : true,
editor: textFieldEditor
},
{
header : 'City',
dataIndex : 'city',
sortable : true,
editor: textFieldEditor
},
{
header : 'State',
dataIndex : 'state',
sortable : true,
editor: comboEditor
},
{
header : 'Zip',
dataIndex : 'zipcode',
sortable : true,
editor: numberFieldEditor
}
];
// paging toolbar for pagination, as an Xtype config object
var pagingToolbar = {
xtype : 'paging',
store : remoteJsonStore,
pageSize : 50, // will use this and the "totalCount" property from server to set up pagination counts
displayInfo : true // display current page + total pages
};
// the Grid!
var grid = {
xtype : 'editorgrid', // EditorGridPanel xtype
id : 'myEditorGrid',
columns : columnModel,
store : remoteJsonStore,
loadMask : true, // auto mask when loading and paginating
bbar : pagingToolbar,
stripRows: true,
viewConfig: {
forceFit: true
}
};
Ext.onReady(function () {
// now a container for our grid!
new Ext.Window({
height : 350,
width : 550,
border : false,
layout : 'fit',
items : grid
}).show();
// and we should tell the Store to load up since we disabled auto loading
Ext.StoreMgr.get('ourRemoteStore').load({
params : {
start : 0,
limit : 50
}
});
});
</script>
</head>
<body>
<div id="container"></div>
</body>
</html>