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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
/*
Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
Available via Academic Free License >= 2.1 OR the modified BSD license.
see: http://dojotoolkit.org/license for details
*/
dojo._xdResourceLoaded(function(dojo, dijit, dojox){
return {depends: [["provide", "dojox.grid.EnhancedGrid"],
["require", "dojox.grid.DataGrid"],
["require", "dojox.grid.enhanced._PluginManager"],
["requireLocalization", "dojox.grid.enhanced", "EnhancedGrid", null, "ROOT,ar,ca,cs,da,de,el,es,fi,fr,he,hu,it,ja,kk,ko,nb,nl,pl,pt,pt-pt,ro,ru,sk,sl,sv,th,tr,zh,zh-tw", "ROOT,ar,ca,cs,da,de,el,es,fi,fr,he,hu,it,ja,kk,ko,nb,nl,pl,pt,pt-pt,ro,ru,sk,sl,sv,th,tr,zh,zh-tw"],
["provide", "dojox.grid.enhanced.DataSelection"],
["require", "dojox.grid.enhanced.plugins._SelectionPreserver"]],
defineResource: function(dojo, dijit, dojox){if(!dojo._hasResource["dojox.grid.EnhancedGrid"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.grid.EnhancedGrid"] = true;
dojo.provide("dojox.grid.EnhancedGrid");
dojo.require("dojox.grid.DataGrid");
dojo.require("dojox.grid.enhanced._PluginManager");
;
dojo.experimental("dojox.grid.EnhancedGrid");
dojo.declare("dojox.grid.EnhancedGrid", dojox.grid.DataGrid, {
// summary:
// Provides enhanced features based on DataGrid
//
// description:
// EnhancedGrid features are implemented as plugins that could be loaded on demand.
// Explicit dojo.require() is needed to use these feature plugins.
//
// example:
// A quick sample to use EnhancedGrid features:
//
// Step 1. Load EnhancedGrid and required features
// | <script type="text/javascript">
// | dojo.require("dojox.grid.EnhancedGrid");
// | dojo.require("dojox.grid.enhanced.plugins.DnD");
// | dojo.require("dojox.grid.enhanced.plugins.Menu");
// | dojo.require("dojox.grid.enhanced.plugins.NestedSorting");
// | dojo.require("dojox.grid.enhanced.plugins.IndirectSelection");
// | </script>
//
// Step 2. Use EnhancedGrid
// - Via HTML markup
// | <div dojoType="dojox.grid.EnhancedGrid" ...
// | plugins="{nestedSorting: true, dnd: true, indirectSelection: true,
// | menus:{headerMenu:"headerMenuId", rowMenu:"rowMenuId", cellMenu:"cellMenuId",
// | selectedRegionMenu:"selectedRegionMenuId"}}">
// | ...
// | </div>
//
// - Or via JavaScript
// | <script type="text/javascript">
// | var grid = new dojox.grid.EnhancedGrid({plugins : {nestedSorting: true, dnd: true, indirectSelection: true,
// | menus:{headerMenu:"headerMenuId", rowMenu:"rowMenuId", cellMenu:"cellMenuId",selectedRegionMenu:"selectedRegionMenuId"}},
// | ... }, dojo.byId('gridDiv'));
// | grid.startup();
// | </script>
//
//
// Plugin Support
// [Note: Plugin support is still experimental]
//
// You can either customize the default plugins or add new ones, more details please see
// - dojox.grid.enhanced._PluginManager
// - dojox.grid.enhanced._Plugin
// - dojox.grid.enhanced.plugins.*
//plugins: Object
// Plugin properties, e.g. {nestedSorting: true, dnd: true, ...}
plugins: null,
//pluginMgr: Object
// Singleton plugin manager
pluginMgr: null,
//keepSelection: Boolean
// Whether keep selection after sort, filter, pagination etc.
keepSelection: false,
//_pluginMgrClass: Object
// Default plugin manager class
_pluginMgrClass: dojox.grid.enhanced._PluginManager,
postMixInProperties: function(){
//load nls bundle
this._nls = dojo.i18n.getLocalization("dojox.grid.enhanced", "EnhancedGrid", this.lang);
this.inherited(arguments);
},
postCreate: function(){
//create plugin manager
this.pluginMgr = new this._pluginMgrClass(this);
this.pluginMgr.preInit();
this.inherited(arguments);
this.pluginMgr.postInit();
},
plugin: function(/*String*/name){
// summary:
// An easier way for getting a plugin, e.g. grid.plugin('dnd')
return this.pluginMgr.getPlugin(name);
},
startup: function(){
this.inherited(arguments);
this.pluginMgr.startup();
},
createSelection: function(){
this.selection = new dojox.grid.enhanced.DataSelection(this);
},
canSort: function(colIndex, field){
// summary:
// Overwritten
return true;
},
doKeyEvent: function(e){
// summary:
// Overwritten, see _Grid.doKeyEvent()
var view = this.focus.focusView;
view.content.decorateEvent(e);
if(!e.cell){ view.header.decorateEvent(e); }
this.inherited(arguments);
},
doApplyCellEdit: function(inValue, inRowIndex, inAttrName){
// summary:
// Overwritten, see DataGrid.doApplyCellEdit()
if(!inAttrName){
this.invalidated[inRowIndex] = true;
return;
}
this.inherited(arguments);
},
mixin: function(target, source){
var props = {};
for(var p in source){
if(p == '_inherited' || p == 'declaredClass' || p == 'constructor' ||
source['privates'] && source['privates'][p]){
continue;
}
props[p] = source[p];
}
dojo.mixin(target, props);
},
_copyAttr: function(idx, attr){
// summary:
// Overwritten, see DataGrid._copyAttr()
// Fix cell TAB navigation for single click editing
if(!attr){ return; }
return this.inherited(arguments);
},
_getHeaderHeight: function(){
// summary:
// Overwritten, see _Grid._getHeaderHeight()
// Should include borders/margins of this.viewsHeaderNode
this.inherited(arguments);
return dojo.marginBox(this.viewsHeaderNode).h;
},
_fetch: function(start, isRender){
// summary:
// Overwritten, see DataGrid._fetch()
if(this.items){
return this.inherited(arguments);
}
start = start || 0;
if(this.store && !this._pending_requests[start]){
if(!this._isLoaded && !this._isLoading){
this._isLoading = true;
this.showMessage(this.loadingMessage);
}
this._pending_requests[start] = true;
try{
var req = {
start: start,
count: this.rowsPerPage,
query: this.query,
sort: this.getSortProps(),
queryOptions: this.queryOptions,
isRender: isRender,
onBegin: dojo.hitch(this, "_onFetchBegin"),
onComplete: dojo.hitch(this, "_onFetchComplete"),
onError: dojo.hitch(this, "_onFetchError")
};
this._storeLayerFetch(req);
}catch(e){
this._onFetchError(e, {start: start, count: this.rowsPerPage});
}
}
return 0;
},
_storeLayerFetch: function(req){
// summary:
// Extracted fetch specifically for store layer use
this.store.fetch(req);
},
getCellByField: function(field){
return dojo.filter(this.layout.cells, function(cell){
return cell.field == field;
})[0];
},
onMouseUp: function(e){ },
createView: function(){
// summary
// Overwrite: rewrite getCellX of view.header
var view = this.inherited(arguments);
if(dojo.isMoz){
var ascendDom = function(inNode, inWhile){
for(var n = inNode; n && inWhile(n); n = n.parentNode){}
return n;
};//copied from dojox.grid._Builder
var makeNotTagName = function(inTagName){
var name = inTagName.toUpperCase();
return function(node){ return node.tagName != name; };
};//copied from dojox.grid._Builder
var func = view.header.getCellX;
view.header.getCellX = function(e){
var x = func.call(view.header, e);
var n = ascendDom(e.target, makeNotTagName("th"));
if(n && n !== e.target && dojo.isDescendant(e.target, n)){ x += n.firstChild.offsetLeft; }
return x;
};
}
return view;
},
destroy: function(){
// summary:
// Destroy all resources
delete this._nls;
this.selection.destroy();
this.pluginMgr.destroy();
this.inherited(arguments);
}
});
dojo.provide("dojox.grid.enhanced.DataSelection");
dojo.require("dojox.grid.enhanced.plugins._SelectionPreserver");//default loaded plugin
dojo.declare("dojox.grid.enhanced.DataSelection", dojox.grid.DataSelection, {
constructor: function(grid){
if(grid.keepSelection){
this.preserver = new dojox.grid.enhanced.plugins._SelectionPreserver(this);
}
},
_range: function(inFrom, inTo){
this.grid._selectingRange = true;
this.inherited(arguments);
this.grid._selectingRange = false;
this.onChanged();
},
deselectAll: function(inItemOrIndex){
this.grid._selectingRange = true;
this.inherited(arguments);
this.grid._selectingRange = false;
this.onChanged();
},
destroy: function(){
if(this.preserver){
this.preserver.destroy();
}
}
});
dojox.grid.EnhancedGrid.markupFactory = function(props, node, ctor, cellFunc){
return dojox.grid._Grid.markupFactory(props, node, ctor,
dojo.partial(dojox.grid.DataGrid.cell_markupFactory, cellFunc));
};
dojox.grid.EnhancedGrid.registerPlugin = function(clazz, props){
dojox.grid.enhanced._PluginManager.registerPlugin(clazz, props);
};
}
}};});
|