27 |
jpm |
1 |
/*
|
|
|
2 |
* Ext JS Library 2.0.2
|
|
|
3 |
* Copyright(c) 2006-2008, Ext JS, LLC.
|
|
|
4 |
* licensing@extjs.com
|
|
|
5 |
*
|
|
|
6 |
* http://extjs.com/license
|
|
|
7 |
*/
|
|
|
8 |
|
|
|
9 |
/**
|
|
|
10 |
* @class Ext.grid.GridView
|
|
|
11 |
* @extends Ext.util.Observable
|
|
|
12 |
* <p>This class encapsulates the user interface of an {@link Ext.grid.GridPanel}.
|
|
|
13 |
* Methods of this class may be used to access user interface elements to enable
|
|
|
14 |
* special display effects. Do not change the DOM structure of the user interface.</p>
|
|
|
15 |
* <p>This class does not provide ways to manipulate the underlying data. The data
|
|
|
16 |
* model of a Grid is held in an {@link Ext.data.Store}.</p>
|
|
|
17 |
* @constructor
|
|
|
18 |
* @param {Object} config
|
|
|
19 |
*/
|
|
|
20 |
Ext.grid.GridView = function(config){
|
|
|
21 |
Ext.apply(this, config);
|
|
|
22 |
// These events are only used internally by the grid components
|
|
|
23 |
this.addEvents(
|
|
|
24 |
/**
|
|
|
25 |
* @event beforerowremoved
|
|
|
26 |
* Internal UI Event. Fired before a row is removed.
|
|
|
27 |
* @param {Ext.grid.GridView} view
|
|
|
28 |
* @param {Number} rowIndex The index of the row to be removed.
|
|
|
29 |
* @param {Ext.data.Record} record The Record to be removed
|
|
|
30 |
*/
|
|
|
31 |
"beforerowremoved",
|
|
|
32 |
/**
|
|
|
33 |
* @event beforerowsinserted
|
|
|
34 |
* Internal UI Event. Fired before rows are inserted.
|
|
|
35 |
* @param {Ext.grid.GridView} view
|
|
|
36 |
* @param {Number} firstRow The index of the first row to be inserted.
|
|
|
37 |
* @param {Number} lastRow The index of the last row to be inserted.
|
|
|
38 |
*/
|
|
|
39 |
"beforerowsinserted",
|
|
|
40 |
/**
|
|
|
41 |
* @event beforerefresh
|
|
|
42 |
* Internal UI Event. Fired before the view is refreshed.
|
|
|
43 |
* @param {Ext.grid.GridView} view
|
|
|
44 |
*/
|
|
|
45 |
"beforerefresh",
|
|
|
46 |
/**
|
|
|
47 |
* @event rowremoved
|
|
|
48 |
* Internal UI Event. Fired after a row is removed.
|
|
|
49 |
* @param {Ext.grid.GridView} view
|
|
|
50 |
* @param {Number} rowIndex The index of the row that was removed.
|
|
|
51 |
* @param {Ext.data.Record} record The Record that was removed
|
|
|
52 |
*/
|
|
|
53 |
"rowremoved",
|
|
|
54 |
/**
|
|
|
55 |
* @event rowsinserted
|
|
|
56 |
* Internal UI Event. Fired after rows are inserted.
|
|
|
57 |
* @param {Ext.grid.GridView} view
|
|
|
58 |
* @param {Number} firstRow The index of the first inserted.
|
|
|
59 |
* @param {Number} lastRow The index of the last row inserted.
|
|
|
60 |
*/
|
|
|
61 |
"rowsinserted",
|
|
|
62 |
/**
|
|
|
63 |
* @event rowupdated
|
|
|
64 |
* Internal UI Event. Fired after a row has been updated.
|
|
|
65 |
* @param {Ext.grid.GridView} view
|
|
|
66 |
* @param {Number} firstRow The index of the row updated.
|
|
|
67 |
* @param {Ext.data.record} record The Record backing the row updated.
|
|
|
68 |
*/
|
|
|
69 |
"rowupdated",
|
|
|
70 |
/**
|
|
|
71 |
* @event refresh
|
|
|
72 |
* Internal UI Event. Fired after the GridView's body has been refreshed.
|
|
|
73 |
* @param {Ext.grid.GridView} view
|
|
|
74 |
*/
|
|
|
75 |
"refresh"
|
|
|
76 |
);
|
|
|
77 |
Ext.grid.GridView.superclass.constructor.call(this);
|
|
|
78 |
};
|
|
|
79 |
|
|
|
80 |
Ext.extend(Ext.grid.GridView, Ext.util.Observable, {
|
|
|
81 |
/**
|
|
|
82 |
* Override this function to apply custom CSS classes to rows during rendering. You can also supply custom
|
|
|
83 |
* parameters to the row template for the current row to customize how it is rendered using the <b>rowParams</b>
|
|
|
84 |
* parameter. This function should return the CSS class name (or empty string '' for none) that will be added
|
|
|
85 |
* to the row's wrapping div. To apply multiple class names, simply return them space-delimited within the string
|
|
|
86 |
* (e.g., 'my-class another-class').
|
|
|
87 |
* @param {Record} record The {@link Ext.data.Record} corresponding to the current row
|
|
|
88 |
* @param {Number} index The row index
|
|
|
89 |
* @param {Object} rowParams A config object that is passed to the row template during rendering that allows
|
|
|
90 |
* customization of various aspects of a body row, if applicable. Note that this object will only be applied if
|
|
|
91 |
* {@link #enableRowBody} = true, otherwise it will be ignored. The object may contain any of these properties:<ul>
|
|
|
92 |
* <li><code>body</code> : String <div class="sub-desc">An HTML fragment to be rendered as the cell's body content (defaults to '').</div></li>
|
|
|
93 |
* <li><code>bodyStyle</code> : String <div class="sub-desc">A CSS style string that will be applied to the row's TR style attribute (defaults to '').</div></li>
|
|
|
94 |
* <li><code>cols</code> : Number <div class="sub-desc">The column count to apply to the body row's TD colspan attribute (defaults to the current
|
|
|
95 |
* column count of the grid).</div></li>
|
|
|
96 |
* </ul>
|
|
|
97 |
* @param {Store} store The {@link Ext.data.Store} this grid is bound to
|
|
|
98 |
* @method getRowClass
|
|
|
99 |
* @return {String} a CSS class name to add to the row.
|
|
|
100 |
*/
|
|
|
101 |
/**
|
|
|
102 |
* @cfg {Boolean} enableRowBody True to add a second TR element per row that can be used to provide a row body
|
|
|
103 |
* that spans beneath the data row. Use the {@link #getRowClass} method's rowParams config to customize the row body.
|
|
|
104 |
*/
|
|
|
105 |
/**
|
|
|
106 |
* @cfg {String} emptyText Default text to display in the grid body when no rows are available (defaults to '').
|
|
|
107 |
*/
|
|
|
108 |
/**
|
|
|
109 |
* The amount of space to reserve for the scrollbar (defaults to 19 pixels)
|
|
|
110 |
* @type Number
|
|
|
111 |
*/
|
|
|
112 |
scrollOffset: 19,
|
|
|
113 |
/**
|
|
|
114 |
* @cfg {Boolean} autoFill True to auto expand the columns to fit the grid <b>when the grid is created</b>.
|
|
|
115 |
*/
|
|
|
116 |
autoFill: false,
|
|
|
117 |
/**
|
|
|
118 |
* @cfg {Boolean} forceFit True to auto expand/contract the size of the columns to fit the grid width and prevent horizontal scrolling.
|
|
|
119 |
*/
|
|
|
120 |
forceFit: false,
|
|
|
121 |
/**
|
|
|
122 |
* The CSS classes applied to a header when it is sorted. (defaults to ["sort-asc", "sort-desc"])
|
|
|
123 |
* @type Array
|
|
|
124 |
*/
|
|
|
125 |
sortClasses : ["sort-asc", "sort-desc"],
|
|
|
126 |
/**
|
|
|
127 |
* The text displayed in the "Sort Ascending" menu item
|
|
|
128 |
* @type String
|
|
|
129 |
*/
|
|
|
130 |
sortAscText : "Sort Ascending",
|
|
|
131 |
/**
|
|
|
132 |
* The text displayed in the "Sort Descending" menu item
|
|
|
133 |
* @type String
|
|
|
134 |
*/
|
|
|
135 |
sortDescText : "Sort Descending",
|
|
|
136 |
/**
|
|
|
137 |
* The text displayed in the "Columns" menu item
|
|
|
138 |
* @type String
|
|
|
139 |
*/
|
|
|
140 |
columnsText : "Columns",
|
|
|
141 |
|
|
|
142 |
// private
|
|
|
143 |
borderWidth: 2,
|
|
|
144 |
|
|
|
145 |
/* -------------------------------- UI Specific ----------------------------- */
|
|
|
146 |
|
|
|
147 |
// private
|
|
|
148 |
initTemplates : function(){
|
|
|
149 |
var ts = this.templates || {};
|
|
|
150 |
if(!ts.master){
|
|
|
151 |
ts.master = new Ext.Template(
|
|
|
152 |
'<div class="x-grid3" hidefocus="true">',
|
|
|
153 |
'<div class="x-grid3-viewport">',
|
|
|
154 |
'<div class="x-grid3-header"><div class="x-grid3-header-inner"><div class="x-grid3-header-offset">{header}</div></div><div class="x-clear"></div></div>',
|
|
|
155 |
'<div class="x-grid3-scroller"><div class="x-grid3-body">{body}</div><a href="#" class="x-grid3-focus" tabIndex="-1"></a></div>',
|
|
|
156 |
"</div>",
|
|
|
157 |
'<div class="x-grid3-resize-marker"> </div>',
|
|
|
158 |
'<div class="x-grid3-resize-proxy"> </div>',
|
|
|
159 |
"</div>"
|
|
|
160 |
);
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
if(!ts.header){
|
|
|
164 |
ts.header = new Ext.Template(
|
|
|
165 |
'<table border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
|
|
|
166 |
'<thead><tr class="x-grid3-hd-row">{cells}</tr></thead>',
|
|
|
167 |
"</table>"
|
|
|
168 |
);
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
if(!ts.hcell){
|
|
|
172 |
ts.hcell = new Ext.Template(
|
|
|
173 |
'<td class="x-grid3-hd x-grid3-cell x-grid3-td-{id}" style="{style}"><div {tooltip} {attr} class="x-grid3-hd-inner x-grid3-hd-{id}" unselectable="on" style="{istyle}">', this.grid.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '',
|
|
|
174 |
'{value}<img class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
|
|
|
175 |
"</div></td>"
|
|
|
176 |
);
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
if(!ts.body){
|
|
|
180 |
ts.body = new Ext.Template('{rows}');
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
if(!ts.row){
|
|
|
184 |
ts.row = new Ext.Template(
|
|
|
185 |
'<div class="x-grid3-row {alt}" style="{tstyle}"><table class="x-grid3-row-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
|
|
|
186 |
'<tbody><tr>{cells}</tr>',
|
|
|
187 |
(this.enableRowBody ? '<tr class="x-grid3-row-body-tr" style="{bodyStyle}"><td colspan="{cols}" class="x-grid3-body-cell" tabIndex="0" hidefocus="on"><div class="x-grid3-row-body">{body}</div></td></tr>' : ''),
|
|
|
188 |
'</tbody></table></div>'
|
|
|
189 |
);
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
if(!ts.cell){
|
|
|
193 |
ts.cell = new Ext.Template(
|
|
|
194 |
'<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} {css}" style="{style}" tabIndex="0" {cellAttr}>',
|
|
|
195 |
'<div class="x-grid3-cell-inner x-grid3-col-{id}" unselectable="on" {attr}>{value}</div>',
|
|
|
196 |
"</td>"
|
|
|
197 |
);
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
for(var k in ts){
|
|
|
201 |
var t = ts[k];
|
|
|
202 |
if(t && typeof t.compile == 'function' && !t.compiled){
|
|
|
203 |
t.disableFormats = true;
|
|
|
204 |
t.compile();
|
|
|
205 |
}
|
|
|
206 |
}
|
|
|
207 |
|
|
|
208 |
this.templates = ts;
|
|
|
209 |
|
|
|
210 |
this.tdClass = 'x-grid3-cell';
|
|
|
211 |
this.cellSelector = 'td.x-grid3-cell';
|
|
|
212 |
this.hdCls = 'x-grid3-hd';
|
|
|
213 |
this.rowSelector = 'div.x-grid3-row';
|
|
|
214 |
this.colRe = new RegExp("x-grid3-td-([^\\s]+)", "");
|
|
|
215 |
},
|
|
|
216 |
|
|
|
217 |
// private
|
|
|
218 |
fly : function(el){
|
|
|
219 |
if(!this._flyweight){
|
|
|
220 |
this._flyweight = new Ext.Element.Flyweight(document.body);
|
|
|
221 |
}
|
|
|
222 |
this._flyweight.dom = el;
|
|
|
223 |
return this._flyweight;
|
|
|
224 |
},
|
|
|
225 |
|
|
|
226 |
// private
|
|
|
227 |
getEditorParent : function(ed){
|
|
|
228 |
return this.scroller.dom;
|
|
|
229 |
},
|
|
|
230 |
|
|
|
231 |
// private
|
|
|
232 |
initElements : function(){
|
|
|
233 |
var E = Ext.Element;
|
|
|
234 |
|
|
|
235 |
var el = this.grid.getGridEl().dom.firstChild;
|
|
|
236 |
var cs = el.childNodes;
|
|
|
237 |
|
|
|
238 |
this.el = new E(el);
|
|
|
239 |
|
|
|
240 |
this.mainWrap = new E(cs[0]);
|
|
|
241 |
this.mainHd = new E(this.mainWrap.dom.firstChild);
|
|
|
242 |
|
|
|
243 |
if(this.grid.hideHeaders){
|
|
|
244 |
this.mainHd.setDisplayed(false);
|
|
|
245 |
}
|
|
|
246 |
|
|
|
247 |
this.innerHd = this.mainHd.dom.firstChild;
|
|
|
248 |
this.scroller = new E(this.mainWrap.dom.childNodes[1]);
|
|
|
249 |
if(this.forceFit){
|
|
|
250 |
this.scroller.setStyle('overflow-x', 'hidden');
|
|
|
251 |
}
|
|
|
252 |
this.mainBody = new E(this.scroller.dom.firstChild);
|
|
|
253 |
|
|
|
254 |
this.focusEl = new E(this.scroller.dom.childNodes[1]);
|
|
|
255 |
this.focusEl.swallowEvent("click", true);
|
|
|
256 |
|
|
|
257 |
this.resizeMarker = new E(cs[1]);
|
|
|
258 |
this.resizeProxy = new E(cs[2]);
|
|
|
259 |
},
|
|
|
260 |
|
|
|
261 |
// private
|
|
|
262 |
getRows : function(){
|
|
|
263 |
return this.hasRows() ? this.mainBody.dom.childNodes : [];
|
|
|
264 |
},
|
|
|
265 |
|
|
|
266 |
// finder methods, used with delegation
|
|
|
267 |
|
|
|
268 |
// private
|
|
|
269 |
findCell : function(el){
|
|
|
270 |
if(!el){
|
|
|
271 |
return false;
|
|
|
272 |
}
|
|
|
273 |
return this.fly(el).findParent(this.cellSelector, 3);
|
|
|
274 |
},
|
|
|
275 |
|
|
|
276 |
// private
|
|
|
277 |
findCellIndex : function(el, requiredCls){
|
|
|
278 |
var cell = this.findCell(el);
|
|
|
279 |
if(cell && (!requiredCls || this.fly(cell).hasClass(requiredCls))){
|
|
|
280 |
return this.getCellIndex(cell);
|
|
|
281 |
}
|
|
|
282 |
return false;
|
|
|
283 |
},
|
|
|
284 |
|
|
|
285 |
// private
|
|
|
286 |
getCellIndex : function(el){
|
|
|
287 |
if(el){
|
|
|
288 |
var m = el.className.match(this.colRe);
|
|
|
289 |
if(m && m[1]){
|
|
|
290 |
return this.cm.getIndexById(m[1]);
|
|
|
291 |
}
|
|
|
292 |
}
|
|
|
293 |
return false;
|
|
|
294 |
},
|
|
|
295 |
|
|
|
296 |
// private
|
|
|
297 |
findHeaderCell : function(el){
|
|
|
298 |
var cell = this.findCell(el);
|
|
|
299 |
return cell && this.fly(cell).hasClass(this.hdCls) ? cell : null;
|
|
|
300 |
},
|
|
|
301 |
|
|
|
302 |
// private
|
|
|
303 |
findHeaderIndex : function(el){
|
|
|
304 |
return this.findCellIndex(el, this.hdCls);
|
|
|
305 |
},
|
|
|
306 |
|
|
|
307 |
// private
|
|
|
308 |
findRow : function(el){
|
|
|
309 |
if(!el){
|
|
|
310 |
return false;
|
|
|
311 |
}
|
|
|
312 |
return this.fly(el).findParent(this.rowSelector, 10);
|
|
|
313 |
},
|
|
|
314 |
|
|
|
315 |
// private
|
|
|
316 |
findRowIndex : function(el){
|
|
|
317 |
var r = this.findRow(el);
|
|
|
318 |
return r ? r.rowIndex : false;
|
|
|
319 |
},
|
|
|
320 |
|
|
|
321 |
// getter methods for fetching elements dynamically in the grid
|
|
|
322 |
|
|
|
323 |
/**
|
|
|
324 |
* Return the <TR> HtmlElement which represents a Grid row for the specified index.
|
|
|
325 |
* @param {Number} index The row index
|
|
|
326 |
* @return {HtmlElement} The <TR> element.
|
|
|
327 |
*/
|
|
|
328 |
getRow : function(row){
|
|
|
329 |
return this.getRows()[row];
|
|
|
330 |
},
|
|
|
331 |
|
|
|
332 |
/**
|
|
|
333 |
* Returns the grid's <TD> HtmlElement at the specified coordinates.
|
|
|
334 |
* @param {Number} row The row index in which to find the cell.
|
|
|
335 |
* @param {Number} col The column index of the cell.
|
|
|
336 |
* @return {HtmlElement} The <TD> at the specified coordinates.
|
|
|
337 |
*/
|
|
|
338 |
getCell : function(row, col){
|
|
|
339 |
return this.getRow(row).getElementsByTagName('td')[col];
|
|
|
340 |
},
|
|
|
341 |
|
|
|
342 |
/**
|
|
|
343 |
* Return the <TD> HtmlElement which represents the Grid's header cell for the specified column index.
|
|
|
344 |
* @param {Number} index The column index
|
|
|
345 |
* @return {HtmlElement} The <TD> element.
|
|
|
346 |
*/
|
|
|
347 |
getHeaderCell : function(index){
|
|
|
348 |
return this.mainHd.dom.getElementsByTagName('td')[index];
|
|
|
349 |
},
|
|
|
350 |
|
|
|
351 |
// manipulating elements
|
|
|
352 |
|
|
|
353 |
// private - use getRowClass to apply custom row classes
|
|
|
354 |
addRowClass : function(row, cls){
|
|
|
355 |
var r = this.getRow(row);
|
|
|
356 |
if(r){
|
|
|
357 |
this.fly(r).addClass(cls);
|
|
|
358 |
}
|
|
|
359 |
},
|
|
|
360 |
|
|
|
361 |
// private
|
|
|
362 |
removeRowClass : function(row, cls){
|
|
|
363 |
var r = this.getRow(row);
|
|
|
364 |
if(r){
|
|
|
365 |
this.fly(r).removeClass(cls);
|
|
|
366 |
}
|
|
|
367 |
},
|
|
|
368 |
|
|
|
369 |
// private
|
|
|
370 |
removeRow : function(row){
|
|
|
371 |
Ext.removeNode(this.getRow(row));
|
|
|
372 |
},
|
|
|
373 |
|
|
|
374 |
// private
|
|
|
375 |
removeRows : function(firstRow, lastRow){
|
|
|
376 |
var bd = this.mainBody.dom;
|
|
|
377 |
for(var rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){
|
|
|
378 |
Ext.removeNode(bd.childNodes[firstRow]);
|
|
|
379 |
}
|
|
|
380 |
},
|
|
|
381 |
|
|
|
382 |
// scrolling stuff
|
|
|
383 |
|
|
|
384 |
// private
|
|
|
385 |
getScrollState : function(){
|
|
|
386 |
var sb = this.scroller.dom;
|
|
|
387 |
return {left: sb.scrollLeft, top: sb.scrollTop};
|
|
|
388 |
},
|
|
|
389 |
|
|
|
390 |
// private
|
|
|
391 |
restoreScroll : function(state){
|
|
|
392 |
var sb = this.scroller.dom;
|
|
|
393 |
sb.scrollLeft = state.left;
|
|
|
394 |
sb.scrollTop = state.top;
|
|
|
395 |
},
|
|
|
396 |
|
|
|
397 |
/**
|
|
|
398 |
* Scrolls the grid to the top
|
|
|
399 |
*/
|
|
|
400 |
scrollToTop : function(){
|
|
|
401 |
this.scroller.dom.scrollTop = 0;
|
|
|
402 |
this.scroller.dom.scrollLeft = 0;
|
|
|
403 |
},
|
|
|
404 |
|
|
|
405 |
// private
|
|
|
406 |
syncScroll : function(){
|
|
|
407 |
this.syncHeaderScroll();
|
|
|
408 |
var mb = this.scroller.dom;
|
|
|
409 |
this.grid.fireEvent("bodyscroll", mb.scrollLeft, mb.scrollTop);
|
|
|
410 |
},
|
|
|
411 |
|
|
|
412 |
// private
|
|
|
413 |
syncHeaderScroll : function(){
|
|
|
414 |
var mb = this.scroller.dom;
|
|
|
415 |
this.innerHd.scrollLeft = mb.scrollLeft;
|
|
|
416 |
this.innerHd.scrollLeft = mb.scrollLeft; // second time for IE (1/2 time first fails, other browsers ignore)
|
|
|
417 |
},
|
|
|
418 |
|
|
|
419 |
// private
|
|
|
420 |
updateSortIcon : function(col, dir){
|
|
|
421 |
var sc = this.sortClasses;
|
|
|
422 |
var hds = this.mainHd.select('td').removeClass(sc);
|
|
|
423 |
hds.item(col).addClass(sc[dir == "DESC" ? 1 : 0]);
|
|
|
424 |
},
|
|
|
425 |
|
|
|
426 |
// private
|
|
|
427 |
updateAllColumnWidths : function(){
|
|
|
428 |
var tw = this.getTotalWidth();
|
|
|
429 |
var clen = this.cm.getColumnCount();
|
|
|
430 |
var ws = [];
|
|
|
431 |
for(var i = 0; i < clen; i++){
|
|
|
432 |
ws[i] = this.getColumnWidth(i);
|
|
|
433 |
}
|
|
|
434 |
|
|
|
435 |
this.innerHd.firstChild.firstChild.style.width = tw;
|
|
|
436 |
|
|
|
437 |
for(var i = 0; i < clen; i++){
|
|
|
438 |
var hd = this.getHeaderCell(i);
|
|
|
439 |
hd.style.width = ws[i];
|
|
|
440 |
}
|
|
|
441 |
|
|
|
442 |
var ns = this.getRows();
|
|
|
443 |
for(var i = 0, len = ns.length; i < len; i++){
|
|
|
444 |
ns[i].style.width = tw;
|
|
|
445 |
ns[i].firstChild.style.width = tw;
|
|
|
446 |
var row = ns[i].firstChild.rows[0];
|
|
|
447 |
for(var j = 0; j < clen; j++){
|
|
|
448 |
row.childNodes[j].style.width = ws[j];
|
|
|
449 |
}
|
|
|
450 |
}
|
|
|
451 |
|
|
|
452 |
this.onAllColumnWidthsUpdated(ws, tw);
|
|
|
453 |
},
|
|
|
454 |
|
|
|
455 |
// private
|
|
|
456 |
updateColumnWidth : function(col, width){
|
|
|
457 |
var w = this.getColumnWidth(col);
|
|
|
458 |
var tw = this.getTotalWidth();
|
|
|
459 |
|
|
|
460 |
this.innerHd.firstChild.firstChild.style.width = tw;
|
|
|
461 |
var hd = this.getHeaderCell(col);
|
|
|
462 |
hd.style.width = w;
|
|
|
463 |
|
|
|
464 |
var ns = this.getRows();
|
|
|
465 |
for(var i = 0, len = ns.length; i < len; i++){
|
|
|
466 |
ns[i].style.width = tw;
|
|
|
467 |
ns[i].firstChild.style.width = tw;
|
|
|
468 |
ns[i].firstChild.rows[0].childNodes[col].style.width = w;
|
|
|
469 |
}
|
|
|
470 |
|
|
|
471 |
this.onColumnWidthUpdated(col, w, tw);
|
|
|
472 |
},
|
|
|
473 |
|
|
|
474 |
// private
|
|
|
475 |
updateColumnHidden : function(col, hidden){
|
|
|
476 |
var tw = this.getTotalWidth();
|
|
|
477 |
|
|
|
478 |
this.innerHd.firstChild.firstChild.style.width = tw;
|
|
|
479 |
|
|
|
480 |
var display = hidden ? 'none' : '';
|
|
|
481 |
|
|
|
482 |
var hd = this.getHeaderCell(col);
|
|
|
483 |
hd.style.display = display;
|
|
|
484 |
|
|
|
485 |
var ns = this.getRows();
|
|
|
486 |
for(var i = 0, len = ns.length; i < len; i++){
|
|
|
487 |
ns[i].style.width = tw;
|
|
|
488 |
ns[i].firstChild.style.width = tw;
|
|
|
489 |
ns[i].firstChild.rows[0].childNodes[col].style.display = display;
|
|
|
490 |
}
|
|
|
491 |
|
|
|
492 |
this.onColumnHiddenUpdated(col, hidden, tw);
|
|
|
493 |
|
|
|
494 |
delete this.lastViewWidth; // force recalc
|
|
|
495 |
this.layout();
|
|
|
496 |
},
|
|
|
497 |
|
|
|
498 |
// private
|
|
|
499 |
doRender : function(cs, rs, ds, startRow, colCount, stripe){
|
|
|
500 |
var ts = this.templates, ct = ts.cell, rt = ts.row, last = colCount-1;
|
|
|
501 |
var tstyle = 'width:'+this.getTotalWidth()+';';
|
|
|
502 |
// buffers
|
|
|
503 |
var buf = [], cb, c, p = {}, rp = {tstyle: tstyle}, r;
|
|
|
504 |
for(var j = 0, len = rs.length; j < len; j++){
|
|
|
505 |
r = rs[j]; cb = [];
|
|
|
506 |
var rowIndex = (j+startRow);
|
|
|
507 |
for(var i = 0; i < colCount; i++){
|
|
|
508 |
c = cs[i];
|
|
|
509 |
p.id = c.id;
|
|
|
510 |
p.css = i == 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
|
|
|
511 |
p.attr = p.cellAttr = "";
|
|
|
512 |
p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
|
|
|
513 |
p.style = c.style;
|
|
|
514 |
if(p.value == undefined || p.value === "") p.value = " ";
|
|
|
515 |
if(r.dirty && typeof r.modified[c.name] !== 'undefined'){
|
|
|
516 |
p.css += ' x-grid3-dirty-cell';
|
|
|
517 |
}
|
|
|
518 |
cb[cb.length] = ct.apply(p);
|
|
|
519 |
}
|
|
|
520 |
var alt = [];
|
|
|
521 |
if(stripe && ((rowIndex+1) % 2 == 0)){
|
|
|
522 |
alt[0] = "x-grid3-row-alt";
|
|
|
523 |
}
|
|
|
524 |
if(r.dirty){
|
|
|
525 |
alt[1] = " x-grid3-dirty-row";
|
|
|
526 |
}
|
|
|
527 |
rp.cols = colCount;
|
|
|
528 |
if(this.getRowClass){
|
|
|
529 |
alt[2] = this.getRowClass(r, rowIndex, rp, ds);
|
|
|
530 |
}
|
|
|
531 |
rp.alt = alt.join(" ");
|
|
|
532 |
rp.cells = cb.join("");
|
|
|
533 |
buf[buf.length] = rt.apply(rp);
|
|
|
534 |
}
|
|
|
535 |
return buf.join("");
|
|
|
536 |
},
|
|
|
537 |
|
|
|
538 |
// private
|
|
|
539 |
processRows : function(startRow, skipStripe){
|
|
|
540 |
if(this.ds.getCount() < 1){
|
|
|
541 |
return;
|
|
|
542 |
}
|
|
|
543 |
skipStripe = skipStripe || !this.grid.stripeRows;
|
|
|
544 |
startRow = startRow || 0;
|
|
|
545 |
var rows = this.getRows();
|
|
|
546 |
var cls = ' x-grid3-row-alt ';
|
|
|
547 |
for(var i = startRow, len = rows.length; i < len; i++){
|
|
|
548 |
var row = rows[i];
|
|
|
549 |
row.rowIndex = i;
|
|
|
550 |
if(!skipStripe){
|
|
|
551 |
var isAlt = ((i+1) % 2 == 0);
|
|
|
552 |
var hasAlt = (' '+row.className + ' ').indexOf(cls) != -1;
|
|
|
553 |
if(isAlt == hasAlt){
|
|
|
554 |
continue;
|
|
|
555 |
}
|
|
|
556 |
if(isAlt){
|
|
|
557 |
row.className += " x-grid3-row-alt";
|
|
|
558 |
}else{
|
|
|
559 |
row.className = row.className.replace("x-grid3-row-alt", "");
|
|
|
560 |
}
|
|
|
561 |
}
|
|
|
562 |
}
|
|
|
563 |
},
|
|
|
564 |
|
|
|
565 |
// private
|
|
|
566 |
renderUI : function(){
|
|
|
567 |
|
|
|
568 |
var header = this.renderHeaders();
|
|
|
569 |
var body = this.templates.body.apply({rows:''});
|
|
|
570 |
|
|
|
571 |
|
|
|
572 |
var html = this.templates.master.apply({
|
|
|
573 |
body: body,
|
|
|
574 |
header: header
|
|
|
575 |
});
|
|
|
576 |
|
|
|
577 |
var g = this.grid;
|
|
|
578 |
|
|
|
579 |
g.getGridEl().dom.innerHTML = html;
|
|
|
580 |
|
|
|
581 |
this.initElements();
|
|
|
582 |
|
|
|
583 |
|
|
|
584 |
this.mainBody.dom.innerHTML = this.renderRows();
|
|
|
585 |
this.processRows(0, true);
|
|
|
586 |
|
|
|
587 |
|
|
|
588 |
// get mousedowns early
|
|
|
589 |
Ext.fly(this.innerHd).on("click", this.handleHdDown, this);
|
|
|
590 |
this.mainHd.on("mouseover", this.handleHdOver, this);
|
|
|
591 |
this.mainHd.on("mouseout", this.handleHdOut, this);
|
|
|
592 |
this.mainHd.on("mousemove", this.handleHdMove, this);
|
|
|
593 |
|
|
|
594 |
this.scroller.on('scroll', this.syncScroll, this);
|
|
|
595 |
if(g.enableColumnResize !== false){
|
|
|
596 |
this.splitone = new Ext.grid.GridView.SplitDragZone(g, this.mainHd.dom);
|
|
|
597 |
}
|
|
|
598 |
|
|
|
599 |
if(g.enableColumnMove){
|
|
|
600 |
this.columnDrag = new Ext.grid.GridView.ColumnDragZone(g, this.innerHd);
|
|
|
601 |
this.columnDrop = new Ext.grid.HeaderDropZone(g, this.mainHd.dom);
|
|
|
602 |
}
|
|
|
603 |
|
|
|
604 |
if(g.enableHdMenu !== false){
|
|
|
605 |
if(g.enableColumnHide !== false){
|
|
|
606 |
this.colMenu = new Ext.menu.Menu({id:g.id + "-hcols-menu"});
|
|
|
607 |
this.colMenu.on("beforeshow", this.beforeColMenuShow, this);
|
|
|
608 |
this.colMenu.on("itemclick", this.handleHdMenuClick, this);
|
|
|
609 |
}
|
|
|
610 |
this.hmenu = new Ext.menu.Menu({id: g.id + "-hctx"});
|
|
|
611 |
this.hmenu.add(
|
|
|
612 |
{id:"asc", text: this.sortAscText, cls: "xg-hmenu-sort-asc"},
|
|
|
613 |
{id:"desc", text: this.sortDescText, cls: "xg-hmenu-sort-desc"}
|
|
|
614 |
);
|
|
|
615 |
if(g.enableColumnHide !== false){
|
|
|
616 |
this.hmenu.add('-',
|
|
|
617 |
{id:"columns", text: this.columnsText, menu: this.colMenu, iconCls: 'x-cols-icon'}
|
|
|
618 |
);
|
|
|
619 |
}
|
|
|
620 |
this.hmenu.on("itemclick", this.handleHdMenuClick, this);
|
|
|
621 |
|
|
|
622 |
//g.on("headercontextmenu", this.handleHdCtx, this);
|
|
|
623 |
}
|
|
|
624 |
|
|
|
625 |
if(g.enableDragDrop || g.enableDrag){
|
|
|
626 |
var dd = new Ext.grid.GridDragZone(g, {
|
|
|
627 |
ddGroup : g.ddGroup || 'GridDD'
|
|
|
628 |
});
|
|
|
629 |
}
|
|
|
630 |
|
|
|
631 |
this.updateHeaderSortState();
|
|
|
632 |
|
|
|
633 |
},
|
|
|
634 |
|
|
|
635 |
// private
|
|
|
636 |
layout : function(){
|
|
|
637 |
if(!this.mainBody){
|
|
|
638 |
return; // not rendered
|
|
|
639 |
}
|
|
|
640 |
var g = this.grid;
|
|
|
641 |
var c = g.getGridEl(), cm = this.cm,
|
|
|
642 |
expandCol = g.autoExpandColumn,
|
|
|
643 |
gv = this;
|
|
|
644 |
|
|
|
645 |
var csize = c.getSize(true);
|
|
|
646 |
var vw = csize.width;
|
|
|
647 |
|
|
|
648 |
if(vw < 20 || csize.height < 20){ // display: none?
|
|
|
649 |
return;
|
|
|
650 |
}
|
|
|
651 |
|
|
|
652 |
if(g.autoHeight){
|
|
|
653 |
this.scroller.dom.style.overflow = 'visible';
|
|
|
654 |
}else{
|
|
|
655 |
this.el.setSize(csize.width, csize.height);
|
|
|
656 |
|
|
|
657 |
var hdHeight = this.mainHd.getHeight();
|
|
|
658 |
var vh = csize.height - (hdHeight);
|
|
|
659 |
|
|
|
660 |
this.scroller.setSize(vw, vh);
|
|
|
661 |
if(this.innerHd){
|
|
|
662 |
this.innerHd.style.width = (vw)+'px';
|
|
|
663 |
}
|
|
|
664 |
}
|
|
|
665 |
if(this.forceFit){
|
|
|
666 |
if(this.lastViewWidth != vw){
|
|
|
667 |
this.fitColumns(false, false);
|
|
|
668 |
this.lastViewWidth = vw;
|
|
|
669 |
}
|
|
|
670 |
}else {
|
|
|
671 |
this.autoExpand();
|
|
|
672 |
this.syncHeaderScroll();
|
|
|
673 |
}
|
|
|
674 |
this.onLayout(vw, vh);
|
|
|
675 |
},
|
|
|
676 |
|
|
|
677 |
// template functions for subclasses and plugins
|
|
|
678 |
// these functions include precalculated values
|
|
|
679 |
onLayout : function(vw, vh){
|
|
|
680 |
// do nothing
|
|
|
681 |
},
|
|
|
682 |
|
|
|
683 |
onColumnWidthUpdated : function(col, w, tw){
|
|
|
684 |
// template method
|
|
|
685 |
},
|
|
|
686 |
|
|
|
687 |
onAllColumnWidthsUpdated : function(ws, tw){
|
|
|
688 |
// template method
|
|
|
689 |
},
|
|
|
690 |
|
|
|
691 |
onColumnHiddenUpdated : function(col, hidden, tw){
|
|
|
692 |
// template method
|
|
|
693 |
},
|
|
|
694 |
|
|
|
695 |
updateColumnText : function(col, text){
|
|
|
696 |
// template method
|
|
|
697 |
},
|
|
|
698 |
|
|
|
699 |
afterMove : function(colIndex){
|
|
|
700 |
// template method
|
|
|
701 |
},
|
|
|
702 |
|
|
|
703 |
/* ----------------------------------- Core Specific -------------------------------------------*/
|
|
|
704 |
// private
|
|
|
705 |
init: function(grid){
|
|
|
706 |
this.grid = grid;
|
|
|
707 |
|
|
|
708 |
this.initTemplates();
|
|
|
709 |
this.initData(grid.store, grid.colModel);
|
|
|
710 |
this.initUI(grid);
|
|
|
711 |
},
|
|
|
712 |
|
|
|
713 |
// private
|
|
|
714 |
getColumnId : function(index){
|
|
|
715 |
return this.cm.getColumnId(index);
|
|
|
716 |
},
|
|
|
717 |
|
|
|
718 |
// private
|
|
|
719 |
renderHeaders : function(){
|
|
|
720 |
var cm = this.cm, ts = this.templates;
|
|
|
721 |
var ct = ts.hcell;
|
|
|
722 |
|
|
|
723 |
var cb = [], sb = [], p = {};
|
|
|
724 |
|
|
|
725 |
for(var i = 0, len = cm.getColumnCount(); i < len; i++){
|
|
|
726 |
p.id = cm.getColumnId(i);
|
|
|
727 |
p.value = cm.getColumnHeader(i) || "";
|
|
|
728 |
p.style = this.getColumnStyle(i, true);
|
|
|
729 |
p.tooltip = this.getColumnTooltip(i);
|
|
|
730 |
if(cm.config[i].align == 'right'){
|
|
|
731 |
p.istyle = 'padding-right:16px';
|
|
|
732 |
} else {
|
|
|
733 |
delete p.istyle;
|
|
|
734 |
}
|
|
|
735 |
cb[cb.length] = ct.apply(p);
|
|
|
736 |
}
|
|
|
737 |
return ts.header.apply({cells: cb.join(""), tstyle:'width:'+this.getTotalWidth()+';'});
|
|
|
738 |
},
|
|
|
739 |
|
|
|
740 |
// private
|
|
|
741 |
getColumnTooltip : function(i){
|
|
|
742 |
var tt = this.cm.getColumnTooltip(i);
|
|
|
743 |
if(tt){
|
|
|
744 |
if(Ext.QuickTips.isEnabled()){
|
|
|
745 |
return 'ext:qtip="'+tt+'"';
|
|
|
746 |
}else{
|
|
|
747 |
return 'title="'+tt+'"';
|
|
|
748 |
}
|
|
|
749 |
}
|
|
|
750 |
return "";
|
|
|
751 |
},
|
|
|
752 |
|
|
|
753 |
// private
|
|
|
754 |
beforeUpdate : function(){
|
|
|
755 |
this.grid.stopEditing(true);
|
|
|
756 |
},
|
|
|
757 |
|
|
|
758 |
// private
|
|
|
759 |
updateHeaders : function(){
|
|
|
760 |
this.innerHd.firstChild.innerHTML = this.renderHeaders();
|
|
|
761 |
},
|
|
|
762 |
|
|
|
763 |
/**
|
|
|
764 |
* Focuses the specified row.
|
|
|
765 |
* @param {Number} row The row index
|
|
|
766 |
*/
|
|
|
767 |
focusRow : function(row){
|
|
|
768 |
this.focusCell(row, 0, false);
|
|
|
769 |
},
|
|
|
770 |
|
|
|
771 |
/**
|
|
|
772 |
* Focuses the specified cell.
|
|
|
773 |
* @param {Number} row The row index
|
|
|
774 |
* @param {Number} col The column index
|
|
|
775 |
*/
|
|
|
776 |
focusCell : function(row, col, hscroll){
|
|
|
777 |
var xy = this.ensureVisible(row, col, hscroll);
|
|
|
778 |
this.focusEl.setXY(xy);
|
|
|
779 |
if(Ext.isGecko){
|
|
|
780 |
this.focusEl.focus();
|
|
|
781 |
}else{
|
|
|
782 |
this.focusEl.focus.defer(1, this.focusEl);
|
|
|
783 |
}
|
|
|
784 |
},
|
|
|
785 |
|
|
|
786 |
// private
|
|
|
787 |
ensureVisible : function(row, col, hscroll){
|
|
|
788 |
if(typeof row != "number"){
|
|
|
789 |
row = row.rowIndex;
|
|
|
790 |
}
|
|
|
791 |
if(!this.ds){
|
|
|
792 |
return;
|
|
|
793 |
}
|
|
|
794 |
if(row < 0 || row >= this.ds.getCount()){
|
|
|
795 |
return;
|
|
|
796 |
}
|
|
|
797 |
col = (col !== undefined ? col : 0);
|
|
|
798 |
|
|
|
799 |
var rowEl = this.getRow(row), cellEl;
|
|
|
800 |
if(!(hscroll === false && col === 0)){
|
|
|
801 |
while(this.cm.isHidden(col)){
|
|
|
802 |
col++;
|
|
|
803 |
}
|
|
|
804 |
cellEl = this.getCell(row, col);
|
|
|
805 |
}
|
|
|
806 |
if(!rowEl){
|
|
|
807 |
return;
|
|
|
808 |
}
|
|
|
809 |
|
|
|
810 |
var c = this.scroller.dom;
|
|
|
811 |
|
|
|
812 |
var ctop = 0;
|
|
|
813 |
var p = rowEl, stop = this.el.dom;
|
|
|
814 |
while(p && p != stop){
|
|
|
815 |
ctop += p.offsetTop;
|
|
|
816 |
p = p.offsetParent;
|
|
|
817 |
}
|
|
|
818 |
ctop -= this.mainHd.dom.offsetHeight;
|
|
|
819 |
|
|
|
820 |
var cbot = ctop + rowEl.offsetHeight;
|
|
|
821 |
|
|
|
822 |
var ch = c.clientHeight;
|
|
|
823 |
var stop = parseInt(c.scrollTop, 10);
|
|
|
824 |
var sbot = stop + ch;
|
|
|
825 |
|
|
|
826 |
if(ctop < stop){
|
|
|
827 |
c.scrollTop = ctop;
|
|
|
828 |
}else if(cbot > sbot){
|
|
|
829 |
c.scrollTop = cbot-ch;
|
|
|
830 |
}
|
|
|
831 |
|
|
|
832 |
if(hscroll !== false){
|
|
|
833 |
var cleft = parseInt(cellEl.offsetLeft, 10);
|
|
|
834 |
var cright = cleft + cellEl.offsetWidth;
|
|
|
835 |
|
|
|
836 |
var sleft = parseInt(c.scrollLeft, 10);
|
|
|
837 |
var sright = sleft + c.clientWidth;
|
|
|
838 |
if(cleft < sleft){
|
|
|
839 |
c.scrollLeft = cleft;
|
|
|
840 |
}else if(cright > sright){
|
|
|
841 |
c.scrollLeft = cright-c.clientWidth;
|
|
|
842 |
}
|
|
|
843 |
}
|
|
|
844 |
return cellEl ? Ext.fly(cellEl).getXY() : [c.scrollLeft, Ext.fly(rowEl).getY()];
|
|
|
845 |
},
|
|
|
846 |
|
|
|
847 |
// private
|
|
|
848 |
insertRows : function(dm, firstRow, lastRow, isUpdate){
|
|
|
849 |
if(!isUpdate && firstRow === 0 && lastRow == dm.getCount()-1){
|
|
|
850 |
this.refresh();
|
|
|
851 |
}else{
|
|
|
852 |
if(!isUpdate){
|
|
|
853 |
this.fireEvent("beforerowsinserted", this, firstRow, lastRow);
|
|
|
854 |
}
|
|
|
855 |
var html = this.renderRows(firstRow, lastRow);
|
|
|
856 |
var before = this.getRow(firstRow);
|
|
|
857 |
if(before){
|
|
|
858 |
Ext.DomHelper.insertHtml('beforeBegin', before, html);
|
|
|
859 |
}else{
|
|
|
860 |
Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html);
|
|
|
861 |
}
|
|
|
862 |
if(!isUpdate){
|
|
|
863 |
this.fireEvent("rowsinserted", this, firstRow, lastRow);
|
|
|
864 |
this.processRows(firstRow);
|
|
|
865 |
}
|
|
|
866 |
}
|
|
|
867 |
},
|
|
|
868 |
|
|
|
869 |
// private
|
|
|
870 |
deleteRows : function(dm, firstRow, lastRow){
|
|
|
871 |
if(dm.getRowCount()<1){
|
|
|
872 |
this.refresh();
|
|
|
873 |
}else{
|
|
|
874 |
this.fireEvent("beforerowsdeleted", this, firstRow, lastRow);
|
|
|
875 |
|
|
|
876 |
this.removeRows(firstRow, lastRow);
|
|
|
877 |
|
|
|
878 |
this.processRows(firstRow);
|
|
|
879 |
this.fireEvent("rowsdeleted", this, firstRow, lastRow);
|
|
|
880 |
}
|
|
|
881 |
},
|
|
|
882 |
|
|
|
883 |
// private
|
|
|
884 |
getColumnStyle : function(col, isHeader){
|
|
|
885 |
var style = !isHeader ? (this.cm.config[col].css || '') : '';
|
|
|
886 |
style += 'width:'+this.getColumnWidth(col)+';';
|
|
|
887 |
if(this.cm.isHidden(col)){
|
|
|
888 |
style += 'display:none;';
|
|
|
889 |
}
|
|
|
890 |
var align = this.cm.config[col].align;
|
|
|
891 |
if(align){
|
|
|
892 |
style += 'text-align:'+align+';';
|
|
|
893 |
}
|
|
|
894 |
return style;
|
|
|
895 |
},
|
|
|
896 |
|
|
|
897 |
// private
|
|
|
898 |
getColumnWidth : function(col){
|
|
|
899 |
var w = this.cm.getColumnWidth(col);
|
|
|
900 |
if(typeof w == 'number'){
|
|
|
901 |
return (Ext.isBorderBox ? w : (w-this.borderWidth > 0 ? w-this.borderWidth:0)) + 'px';
|
|
|
902 |
}
|
|
|
903 |
return w;
|
|
|
904 |
},
|
|
|
905 |
|
|
|
906 |
// private
|
|
|
907 |
getTotalWidth : function(){
|
|
|
908 |
return this.cm.getTotalWidth()+'px';
|
|
|
909 |
},
|
|
|
910 |
|
|
|
911 |
// private
|
|
|
912 |
fitColumns : function(preventRefresh, onlyExpand, omitColumn){
|
|
|
913 |
var cm = this.cm, leftOver, dist, i;
|
|
|
914 |
var tw = cm.getTotalWidth(false);
|
|
|
915 |
var aw = this.grid.getGridEl().getWidth(true)-this.scrollOffset;
|
|
|
916 |
|
|
|
917 |
if(aw < 20){ // not initialized, so don't screw up the default widths
|
|
|
918 |
return;
|
|
|
919 |
}
|
|
|
920 |
var extra = aw - tw;
|
|
|
921 |
|
|
|
922 |
if(extra === 0){
|
|
|
923 |
return false;
|
|
|
924 |
}
|
|
|
925 |
|
|
|
926 |
var vc = cm.getColumnCount(true);
|
|
|
927 |
var ac = vc-(typeof omitColumn == 'number' ? 1 : 0);
|
|
|
928 |
if(ac === 0){
|
|
|
929 |
ac = 1;
|
|
|
930 |
omitColumn = undefined;
|
|
|
931 |
}
|
|
|
932 |
var colCount = cm.getColumnCount();
|
|
|
933 |
var cols = [];
|
|
|
934 |
var extraCol = 0;
|
|
|
935 |
var width = 0;
|
|
|
936 |
var w;
|
|
|
937 |
for (i = 0; i < colCount; i++){
|
|
|
938 |
if(!cm.isHidden(i) && !cm.isFixed(i) && i !== omitColumn){
|
|
|
939 |
w = cm.getColumnWidth(i);
|
|
|
940 |
cols.push(i);
|
|
|
941 |
extraCol = i;
|
|
|
942 |
cols.push(w);
|
|
|
943 |
width += w;
|
|
|
944 |
}
|
|
|
945 |
}
|
|
|
946 |
var frac = (aw - cm.getTotalWidth())/width;
|
|
|
947 |
while (cols.length){
|
|
|
948 |
w = cols.pop();
|
|
|
949 |
i = cols.pop();
|
|
|
950 |
cm.setColumnWidth(i, Math.max(this.grid.minColumnWidth, Math.floor(w + w*frac)), true);
|
|
|
951 |
}
|
|
|
952 |
|
|
|
953 |
if((tw = cm.getTotalWidth(false)) > aw){
|
|
|
954 |
var adjustCol = ac != vc ? omitColumn : extraCol;
|
|
|
955 |
cm.setColumnWidth(adjustCol, Math.max(1,
|
|
|
956 |
cm.getColumnWidth(adjustCol)- (tw-aw)), true);
|
|
|
957 |
}
|
|
|
958 |
|
|
|
959 |
if(preventRefresh !== true){
|
|
|
960 |
this.updateAllColumnWidths();
|
|
|
961 |
}
|
|
|
962 |
|
|
|
963 |
|
|
|
964 |
return true;
|
|
|
965 |
},
|
|
|
966 |
|
|
|
967 |
// private
|
|
|
968 |
autoExpand : function(preventUpdate){
|
|
|
969 |
var g = this.grid, cm = this.cm;
|
|
|
970 |
if(!this.userResized && g.autoExpandColumn){
|
|
|
971 |
var tw = cm.getTotalWidth(false);
|
|
|
972 |
var aw = this.grid.getGridEl().getWidth(true)-this.scrollOffset;
|
|
|
973 |
if(tw != aw){
|
|
|
974 |
var ci = cm.getIndexById(g.autoExpandColumn);
|
|
|
975 |
var currentWidth = cm.getColumnWidth(ci);
|
|
|
976 |
var cw = Math.min(Math.max(((aw-tw)+currentWidth), g.autoExpandMin), g.autoExpandMax);
|
|
|
977 |
if(cw != currentWidth){
|
|
|
978 |
cm.setColumnWidth(ci, cw, true);
|
|
|
979 |
if(preventUpdate !== true){
|
|
|
980 |
this.updateColumnWidth(ci, cw);
|
|
|
981 |
}
|
|
|
982 |
}
|
|
|
983 |
}
|
|
|
984 |
}
|
|
|
985 |
},
|
|
|
986 |
|
|
|
987 |
// private
|
|
|
988 |
getColumnData : function(){
|
|
|
989 |
// build a map for all the columns
|
|
|
990 |
var cs = [], cm = this.cm, colCount = cm.getColumnCount();
|
|
|
991 |
for(var i = 0; i < colCount; i++){
|
|
|
992 |
var name = cm.getDataIndex(i);
|
|
|
993 |
cs[i] = {
|
|
|
994 |
name : (typeof name == 'undefined' ? this.ds.fields.get(i).name : name),
|
|
|
995 |
renderer : cm.getRenderer(i),
|
|
|
996 |
id : cm.getColumnId(i),
|
|
|
997 |
style : this.getColumnStyle(i)
|
|
|
998 |
};
|
|
|
999 |
}
|
|
|
1000 |
return cs;
|
|
|
1001 |
},
|
|
|
1002 |
|
|
|
1003 |
// private
|
|
|
1004 |
renderRows : function(startRow, endRow){
|
|
|
1005 |
// pull in all the crap needed to render rows
|
|
|
1006 |
var g = this.grid, cm = g.colModel, ds = g.store, stripe = g.stripeRows;
|
|
|
1007 |
var colCount = cm.getColumnCount();
|
|
|
1008 |
|
|
|
1009 |
if(ds.getCount() < 1){
|
|
|
1010 |
return "";
|
|
|
1011 |
}
|
|
|
1012 |
|
|
|
1013 |
var cs = this.getColumnData();
|
|
|
1014 |
|
|
|
1015 |
startRow = startRow || 0;
|
|
|
1016 |
endRow = typeof endRow == "undefined"? ds.getCount()-1 : endRow;
|
|
|
1017 |
|
|
|
1018 |
// records to render
|
|
|
1019 |
var rs = ds.getRange(startRow, endRow);
|
|
|
1020 |
|
|
|
1021 |
return this.doRender(cs, rs, ds, startRow, colCount, stripe);
|
|
|
1022 |
},
|
|
|
1023 |
|
|
|
1024 |
// private
|
|
|
1025 |
renderBody : function(){
|
|
|
1026 |
var markup = this.renderRows();
|
|
|
1027 |
return this.templates.body.apply({rows: markup});
|
|
|
1028 |
},
|
|
|
1029 |
|
|
|
1030 |
// private
|
|
|
1031 |
refreshRow : function(record){
|
|
|
1032 |
var ds = this.ds, index;
|
|
|
1033 |
if(typeof record == 'number'){
|
|
|
1034 |
index = record;
|
|
|
1035 |
record = ds.getAt(index);
|
|
|
1036 |
}else{
|
|
|
1037 |
index = ds.indexOf(record);
|
|
|
1038 |
}
|
|
|
1039 |
var cls = [];
|
|
|
1040 |
this.insertRows(ds, index, index, true);
|
|
|
1041 |
this.getRow(index).rowIndex = index;
|
|
|
1042 |
this.onRemove(ds, record, index+1, true);
|
|
|
1043 |
this.fireEvent("rowupdated", this, index, record);
|
|
|
1044 |
},
|
|
|
1045 |
|
|
|
1046 |
/**
|
|
|
1047 |
* Refreshs the grid UI
|
|
|
1048 |
* @param {Boolean} headersToo (optional) True to also refresh the headers
|
|
|
1049 |
*/
|
|
|
1050 |
refresh : function(headersToo){
|
|
|
1051 |
this.fireEvent("beforerefresh", this);
|
|
|
1052 |
this.grid.stopEditing(true);
|
|
|
1053 |
|
|
|
1054 |
var result = this.renderBody();
|
|
|
1055 |
this.mainBody.update(result);
|
|
|
1056 |
|
|
|
1057 |
if(headersToo === true){
|
|
|
1058 |
this.updateHeaders();
|
|
|
1059 |
this.updateHeaderSortState();
|
|
|
1060 |
}
|
|
|
1061 |
this.processRows(0, true);
|
|
|
1062 |
this.layout();
|
|
|
1063 |
this.applyEmptyText();
|
|
|
1064 |
this.fireEvent("refresh", this);
|
|
|
1065 |
},
|
|
|
1066 |
|
|
|
1067 |
// private
|
|
|
1068 |
applyEmptyText : function(){
|
|
|
1069 |
if(this.emptyText && !this.hasRows()){
|
|
|
1070 |
this.mainBody.update('<div class="x-grid-empty">' + this.emptyText + '</div>');
|
|
|
1071 |
}
|
|
|
1072 |
},
|
|
|
1073 |
|
|
|
1074 |
// private
|
|
|
1075 |
updateHeaderSortState : function(){
|
|
|
1076 |
var state = this.ds.getSortState();
|
|
|
1077 |
if(!state){
|
|
|
1078 |
return;
|
|
|
1079 |
}
|
|
|
1080 |
if(!this.sortState || (this.sortState.field != state.field || this.sortState.direction != state.direction)){
|
|
|
1081 |
this.grid.fireEvent('sortchange', this.grid, state);
|
|
|
1082 |
}
|
|
|
1083 |
this.sortState = state;
|
|
|
1084 |
var sortColumn = this.cm.findColumnIndex(state.field);
|
|
|
1085 |
if(sortColumn != -1){
|
|
|
1086 |
var sortDir = state.direction;
|
|
|
1087 |
this.updateSortIcon(sortColumn, sortDir);
|
|
|
1088 |
}
|
|
|
1089 |
},
|
|
|
1090 |
|
|
|
1091 |
// private
|
|
|
1092 |
destroy : function(){
|
|
|
1093 |
if(this.colMenu){
|
|
|
1094 |
this.colMenu.removeAll();
|
|
|
1095 |
Ext.menu.MenuMgr.unregister(this.colMenu);
|
|
|
1096 |
this.colMenu.getEl().remove();
|
|
|
1097 |
delete this.colMenu;
|
|
|
1098 |
}
|
|
|
1099 |
if(this.hmenu){
|
|
|
1100 |
this.hmenu.removeAll();
|
|
|
1101 |
Ext.menu.MenuMgr.unregister(this.hmenu);
|
|
|
1102 |
this.hmenu.getEl().remove();
|
|
|
1103 |
delete this.hmenu;
|
|
|
1104 |
}
|
|
|
1105 |
if(this.grid.enableColumnMove){
|
|
|
1106 |
var dds = Ext.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id];
|
|
|
1107 |
if(dds){
|
|
|
1108 |
for(var dd in dds){
|
|
|
1109 |
if(!dds[dd].config.isTarget && dds[dd].dragElId){
|
|
|
1110 |
var elid = dds[dd].dragElId;
|
|
|
1111 |
dds[dd].unreg();
|
|
|
1112 |
Ext.get(elid).remove();
|
|
|
1113 |
} else if(dds[dd].config.isTarget){
|
|
|
1114 |
dds[dd].proxyTop.remove();
|
|
|
1115 |
dds[dd].proxyBottom.remove();
|
|
|
1116 |
dds[dd].unreg();
|
|
|
1117 |
}
|
|
|
1118 |
if(Ext.dd.DDM.locationCache[dd]){
|
|
|
1119 |
delete Ext.dd.DDM.locationCache[dd];
|
|
|
1120 |
}
|
|
|
1121 |
}
|
|
|
1122 |
delete Ext.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id];
|
|
|
1123 |
}
|
|
|
1124 |
}
|
|
|
1125 |
|
|
|
1126 |
Ext.destroy(this.resizeMarker, this.resizeProxy);
|
|
|
1127 |
|
|
|
1128 |
this.initData(null, null);
|
|
|
1129 |
Ext.EventManager.removeResizeListener(this.onWindowResize, this);
|
|
|
1130 |
},
|
|
|
1131 |
|
|
|
1132 |
// private
|
|
|
1133 |
onDenyColumnHide : function(){
|
|
|
1134 |
|
|
|
1135 |
},
|
|
|
1136 |
|
|
|
1137 |
// private
|
|
|
1138 |
render : function(){
|
|
|
1139 |
|
|
|
1140 |
var cm = this.cm;
|
|
|
1141 |
var colCount = cm.getColumnCount();
|
|
|
1142 |
|
|
|
1143 |
if(this.autoFill){
|
|
|
1144 |
this.fitColumns(true, true);
|
|
|
1145 |
}else if(this.forceFit){
|
|
|
1146 |
this.fitColumns(true, false);
|
|
|
1147 |
}else if(this.grid.autoExpandColumn){
|
|
|
1148 |
this.autoExpand(true);
|
|
|
1149 |
}
|
|
|
1150 |
|
|
|
1151 |
this.renderUI();
|
|
|
1152 |
},
|
|
|
1153 |
|
|
|
1154 |
/* --------------------------------- Model Events and Handlers --------------------------------*/
|
|
|
1155 |
// private
|
|
|
1156 |
initData : function(ds, cm){
|
|
|
1157 |
if(this.ds){
|
|
|
1158 |
this.ds.un("load", this.onLoad, this);
|
|
|
1159 |
this.ds.un("datachanged", this.onDataChange, this);
|
|
|
1160 |
this.ds.un("add", this.onAdd, this);
|
|
|
1161 |
this.ds.un("remove", this.onRemove, this);
|
|
|
1162 |
this.ds.un("update", this.onUpdate, this);
|
|
|
1163 |
this.ds.un("clear", this.onClear, this);
|
|
|
1164 |
}
|
|
|
1165 |
if(ds){
|
|
|
1166 |
ds.on("load", this.onLoad, this);
|
|
|
1167 |
ds.on("datachanged", this.onDataChange, this);
|
|
|
1168 |
ds.on("add", this.onAdd, this);
|
|
|
1169 |
ds.on("remove", this.onRemove, this);
|
|
|
1170 |
ds.on("update", this.onUpdate, this);
|
|
|
1171 |
ds.on("clear", this.onClear, this);
|
|
|
1172 |
}
|
|
|
1173 |
this.ds = ds;
|
|
|
1174 |
|
|
|
1175 |
if(this.cm){
|
|
|
1176 |
this.cm.un("configchange", this.onColConfigChange, this);
|
|
|
1177 |
this.cm.un("widthchange", this.onColWidthChange, this);
|
|
|
1178 |
this.cm.un("headerchange", this.onHeaderChange, this);
|
|
|
1179 |
this.cm.un("hiddenchange", this.onHiddenChange, this);
|
|
|
1180 |
this.cm.un("columnmoved", this.onColumnMove, this);
|
|
|
1181 |
this.cm.un("columnlockchange", this.onColumnLock, this);
|
|
|
1182 |
}
|
|
|
1183 |
if(cm){
|
|
|
1184 |
cm.on("configchange", this.onColConfigChange, this);
|
|
|
1185 |
cm.on("widthchange", this.onColWidthChange, this);
|
|
|
1186 |
cm.on("headerchange", this.onHeaderChange, this);
|
|
|
1187 |
cm.on("hiddenchange", this.onHiddenChange, this);
|
|
|
1188 |
cm.on("columnmoved", this.onColumnMove, this);
|
|
|
1189 |
cm.on("columnlockchange", this.onColumnLock, this);
|
|
|
1190 |
}
|
|
|
1191 |
this.cm = cm;
|
|
|
1192 |
},
|
|
|
1193 |
|
|
|
1194 |
// private
|
|
|
1195 |
onDataChange : function(){
|
|
|
1196 |
this.refresh();
|
|
|
1197 |
this.updateHeaderSortState();
|
|
|
1198 |
},
|
|
|
1199 |
|
|
|
1200 |
// private
|
|
|
1201 |
onClear : function(){
|
|
|
1202 |
this.refresh();
|
|
|
1203 |
},
|
|
|
1204 |
|
|
|
1205 |
// private
|
|
|
1206 |
onUpdate : function(ds, record){
|
|
|
1207 |
this.refreshRow(record);
|
|
|
1208 |
},
|
|
|
1209 |
|
|
|
1210 |
// private
|
|
|
1211 |
onAdd : function(ds, records, index){
|
|
|
1212 |
this.insertRows(ds, index, index + (records.length-1));
|
|
|
1213 |
},
|
|
|
1214 |
|
|
|
1215 |
// private
|
|
|
1216 |
onRemove : function(ds, record, index, isUpdate){
|
|
|
1217 |
if(isUpdate !== true){
|
|
|
1218 |
this.fireEvent("beforerowremoved", this, index, record);
|
|
|
1219 |
}
|
|
|
1220 |
this.removeRow(index);
|
|
|
1221 |
if(isUpdate !== true){
|
|
|
1222 |
this.processRows(index);
|
|
|
1223 |
this.applyEmptyText();
|
|
|
1224 |
this.fireEvent("rowremoved", this, index, record);
|
|
|
1225 |
}
|
|
|
1226 |
},
|
|
|
1227 |
|
|
|
1228 |
// private
|
|
|
1229 |
onLoad : function(){
|
|
|
1230 |
this.scrollToTop();
|
|
|
1231 |
},
|
|
|
1232 |
|
|
|
1233 |
// private
|
|
|
1234 |
onColWidthChange : function(cm, col, width){
|
|
|
1235 |
this.updateColumnWidth(col, width);
|
|
|
1236 |
},
|
|
|
1237 |
|
|
|
1238 |
// private
|
|
|
1239 |
onHeaderChange : function(cm, col, text){
|
|
|
1240 |
this.updateHeaders();
|
|
|
1241 |
},
|
|
|
1242 |
|
|
|
1243 |
// private
|
|
|
1244 |
onHiddenChange : function(cm, col, hidden){
|
|
|
1245 |
this.updateColumnHidden(col, hidden);
|
|
|
1246 |
},
|
|
|
1247 |
|
|
|
1248 |
// private
|
|
|
1249 |
onColumnMove : function(cm, oldIndex, newIndex){
|
|
|
1250 |
this.indexMap = null;
|
|
|
1251 |
var s = this.getScrollState();
|
|
|
1252 |
this.refresh(true);
|
|
|
1253 |
this.restoreScroll(s);
|
|
|
1254 |
this.afterMove(newIndex);
|
|
|
1255 |
},
|
|
|
1256 |
|
|
|
1257 |
// private
|
|
|
1258 |
onColConfigChange : function(){
|
|
|
1259 |
delete this.lastViewWidth;
|
|
|
1260 |
this.indexMap = null;
|
|
|
1261 |
this.refresh(true);
|
|
|
1262 |
},
|
|
|
1263 |
|
|
|
1264 |
/* -------------------- UI Events and Handlers ------------------------------ */
|
|
|
1265 |
// private
|
|
|
1266 |
initUI : function(grid){
|
|
|
1267 |
grid.on("headerclick", this.onHeaderClick, this);
|
|
|
1268 |
|
|
|
1269 |
if(grid.trackMouseOver){
|
|
|
1270 |
grid.on("mouseover", this.onRowOver, this);
|
|
|
1271 |
grid.on("mouseout", this.onRowOut, this);
|
|
|
1272 |
}
|
|
|
1273 |
},
|
|
|
1274 |
|
|
|
1275 |
// private
|
|
|
1276 |
initEvents : function(){
|
|
|
1277 |
|
|
|
1278 |
},
|
|
|
1279 |
|
|
|
1280 |
// private
|
|
|
1281 |
onHeaderClick : function(g, index){
|
|
|
1282 |
if(this.headersDisabled || !this.cm.isSortable(index)){
|
|
|
1283 |
return;
|
|
|
1284 |
}
|
|
|
1285 |
g.stopEditing(true);
|
|
|
1286 |
g.store.sort(this.cm.getDataIndex(index));
|
|
|
1287 |
},
|
|
|
1288 |
|
|
|
1289 |
// private
|
|
|
1290 |
onRowOver : function(e, t){
|
|
|
1291 |
var row;
|
|
|
1292 |
if((row = this.findRowIndex(t)) !== false){
|
|
|
1293 |
this.addRowClass(row, "x-grid3-row-over");
|
|
|
1294 |
}
|
|
|
1295 |
},
|
|
|
1296 |
|
|
|
1297 |
// private
|
|
|
1298 |
onRowOut : function(e, t){
|
|
|
1299 |
var row;
|
|
|
1300 |
if((row = this.findRowIndex(t)) !== false && row !== this.findRowIndex(e.getRelatedTarget())){
|
|
|
1301 |
this.removeRowClass(row, "x-grid3-row-over");
|
|
|
1302 |
}
|
|
|
1303 |
},
|
|
|
1304 |
|
|
|
1305 |
// private
|
|
|
1306 |
handleWheel : function(e){
|
|
|
1307 |
e.stopPropagation();
|
|
|
1308 |
},
|
|
|
1309 |
|
|
|
1310 |
// private
|
|
|
1311 |
onRowSelect : function(row){
|
|
|
1312 |
this.addRowClass(row, "x-grid3-row-selected");
|
|
|
1313 |
},
|
|
|
1314 |
|
|
|
1315 |
// private
|
|
|
1316 |
onRowDeselect : function(row){
|
|
|
1317 |
this.removeRowClass(row, "x-grid3-row-selected");
|
|
|
1318 |
},
|
|
|
1319 |
|
|
|
1320 |
// private
|
|
|
1321 |
onCellSelect : function(row, col){
|
|
|
1322 |
var cell = this.getCell(row, col);
|
|
|
1323 |
if(cell){
|
|
|
1324 |
this.fly(cell).addClass("x-grid3-cell-selected");
|
|
|
1325 |
}
|
|
|
1326 |
},
|
|
|
1327 |
|
|
|
1328 |
// private
|
|
|
1329 |
onCellDeselect : function(row, col){
|
|
|
1330 |
var cell = this.getCell(row, col);
|
|
|
1331 |
if(cell){
|
|
|
1332 |
this.fly(cell).removeClass("x-grid3-cell-selected");
|
|
|
1333 |
}
|
|
|
1334 |
},
|
|
|
1335 |
|
|
|
1336 |
// private
|
|
|
1337 |
onColumnSplitterMoved : function(i, w){
|
|
|
1338 |
this.userResized = true;
|
|
|
1339 |
var cm = this.grid.colModel;
|
|
|
1340 |
cm.setColumnWidth(i, w, true);
|
|
|
1341 |
|
|
|
1342 |
if(this.forceFit){
|
|
|
1343 |
this.fitColumns(true, false, i);
|
|
|
1344 |
this.updateAllColumnWidths();
|
|
|
1345 |
}else{
|
|
|
1346 |
this.updateColumnWidth(i, w);
|
|
|
1347 |
}
|
|
|
1348 |
|
|
|
1349 |
this.grid.fireEvent("columnresize", i, w);
|
|
|
1350 |
},
|
|
|
1351 |
|
|
|
1352 |
// private
|
|
|
1353 |
handleHdMenuClick : function(item){
|
|
|
1354 |
var index = this.hdCtxIndex;
|
|
|
1355 |
var cm = this.cm, ds = this.ds;
|
|
|
1356 |
switch(item.id){
|
|
|
1357 |
case "asc":
|
|
|
1358 |
ds.sort(cm.getDataIndex(index), "ASC");
|
|
|
1359 |
break;
|
|
|
1360 |
case "desc":
|
|
|
1361 |
ds.sort(cm.getDataIndex(index), "DESC");
|
|
|
1362 |
break;
|
|
|
1363 |
default:
|
|
|
1364 |
index = cm.getIndexById(item.id.substr(4));
|
|
|
1365 |
if(index != -1){
|
|
|
1366 |
if(item.checked && cm.getColumnsBy(this.isHideableColumn, this).length <= 1){
|
|
|
1367 |
this.onDenyColumnHide();
|
|
|
1368 |
return false;
|
|
|
1369 |
}
|
|
|
1370 |
cm.setHidden(index, item.checked);
|
|
|
1371 |
}
|
|
|
1372 |
}
|
|
|
1373 |
return true;
|
|
|
1374 |
},
|
|
|
1375 |
|
|
|
1376 |
// private
|
|
|
1377 |
isHideableColumn : function(c){
|
|
|
1378 |
return !c.hidden && !c.fixed;
|
|
|
1379 |
},
|
|
|
1380 |
|
|
|
1381 |
// private
|
|
|
1382 |
beforeColMenuShow : function(){
|
|
|
1383 |
var cm = this.cm, colCount = cm.getColumnCount();
|
|
|
1384 |
this.colMenu.removeAll();
|
|
|
1385 |
for(var i = 0; i < colCount; i++){
|
|
|
1386 |
if(cm.config[i].fixed !== true && cm.config[i].hideable !== false){
|
|
|
1387 |
this.colMenu.add(new Ext.menu.CheckItem({
|
|
|
1388 |
id: "col-"+cm.getColumnId(i),
|
|
|
1389 |
text: cm.getColumnHeader(i),
|
|
|
1390 |
checked: !cm.isHidden(i),
|
|
|
1391 |
hideOnClick:false,
|
|
|
1392 |
disabled: cm.config[i].hideable === false
|
|
|
1393 |
}));
|
|
|
1394 |
}
|
|
|
1395 |
}
|
|
|
1396 |
},
|
|
|
1397 |
|
|
|
1398 |
// private
|
|
|
1399 |
handleHdDown : function(e, t){
|
|
|
1400 |
if(Ext.fly(t).hasClass('x-grid3-hd-btn')){
|
|
|
1401 |
e.stopEvent();
|
|
|
1402 |
var hd = this.findHeaderCell(t);
|
|
|
1403 |
Ext.fly(hd).addClass('x-grid3-hd-menu-open');
|
|
|
1404 |
var index = this.getCellIndex(hd);
|
|
|
1405 |
this.hdCtxIndex = index;
|
|
|
1406 |
var ms = this.hmenu.items, cm = this.cm;
|
|
|
1407 |
ms.get("asc").setDisabled(!cm.isSortable(index));
|
|
|
1408 |
ms.get("desc").setDisabled(!cm.isSortable(index));
|
|
|
1409 |
this.hmenu.on("hide", function(){
|
|
|
1410 |
Ext.fly(hd).removeClass('x-grid3-hd-menu-open');
|
|
|
1411 |
}, this, {single:true});
|
|
|
1412 |
this.hmenu.show(t, "tl-bl?");
|
|
|
1413 |
}
|
|
|
1414 |
},
|
|
|
1415 |
|
|
|
1416 |
// private
|
|
|
1417 |
handleHdOver : function(e, t){
|
|
|
1418 |
var hd = this.findHeaderCell(t);
|
|
|
1419 |
if(hd && !this.headersDisabled){
|
|
|
1420 |
this.activeHd = hd;
|
|
|
1421 |
this.activeHdIndex = this.getCellIndex(hd);
|
|
|
1422 |
var fly = this.fly(hd);
|
|
|
1423 |
this.activeHdRegion = fly.getRegion();
|
|
|
1424 |
if(!this.cm.isMenuDisabled(this.activeHdIndex)){
|
|
|
1425 |
fly.addClass("x-grid3-hd-over");
|
|
|
1426 |
this.activeHdBtn = fly.child('.x-grid3-hd-btn');
|
|
|
1427 |
if(this.activeHdBtn){
|
|
|
1428 |
this.activeHdBtn.dom.style.height = (hd.firstChild.offsetHeight-1)+'px';
|
|
|
1429 |
}
|
|
|
1430 |
}
|
|
|
1431 |
}
|
|
|
1432 |
},
|
|
|
1433 |
|
|
|
1434 |
// private
|
|
|
1435 |
handleHdMove : function(e, t){
|
|
|
1436 |
if(this.activeHd && !this.headersDisabled){
|
|
|
1437 |
var hw = this.splitHandleWidth || 5;
|
|
|
1438 |
var r = this.activeHdRegion;
|
|
|
1439 |
var x = e.getPageX();
|
|
|
1440 |
var ss = this.activeHd.style;
|
|
|
1441 |
if(x - r.left <= hw && this.cm.isResizable(this.activeHdIndex-1)){
|
|
|
1442 |
ss.cursor = Ext.isAir ? 'move' : Ext.isSafari ? 'e-resize' : 'col-resize'; // col-resize not always supported
|
|
|
1443 |
}else if(r.right - x <= (!this.activeHdBtn ? hw : 2) && this.cm.isResizable(this.activeHdIndex)){
|
|
|
1444 |
ss.cursor = Ext.isAir ? 'move' : Ext.isSafari ? 'w-resize' : 'col-resize';
|
|
|
1445 |
}else{
|
|
|
1446 |
ss.cursor = '';
|
|
|
1447 |
}
|
|
|
1448 |
}
|
|
|
1449 |
},
|
|
|
1450 |
|
|
|
1451 |
// private
|
|
|
1452 |
handleHdOut : function(e, t){
|
|
|
1453 |
var hd = this.findHeaderCell(t);
|
|
|
1454 |
if(hd && (!Ext.isIE || !e.within(hd, true))){
|
|
|
1455 |
this.activeHd = null;
|
|
|
1456 |
this.fly(hd).removeClass("x-grid3-hd-over");
|
|
|
1457 |
hd.style.cursor = '';
|
|
|
1458 |
}
|
|
|
1459 |
},
|
|
|
1460 |
|
|
|
1461 |
// private
|
|
|
1462 |
hasRows : function(){
|
|
|
1463 |
var fc = this.mainBody.dom.firstChild;
|
|
|
1464 |
return fc && fc.className != 'x-grid-empty';
|
|
|
1465 |
},
|
|
|
1466 |
|
|
|
1467 |
// back compat
|
|
|
1468 |
bind : function(d, c){
|
|
|
1469 |
this.initData(d, c);
|
|
|
1470 |
}
|
|
|
1471 |
});
|
|
|
1472 |
|
|
|
1473 |
|
|
|
1474 |
// private
|
|
|
1475 |
// This is a support class used internally by the Grid components
|
|
|
1476 |
Ext.grid.GridView.SplitDragZone = function(grid, hd){
|
|
|
1477 |
this.grid = grid;
|
|
|
1478 |
this.view = grid.getView();
|
|
|
1479 |
this.marker = this.view.resizeMarker;
|
|
|
1480 |
this.proxy = this.view.resizeProxy;
|
|
|
1481 |
Ext.grid.GridView.SplitDragZone.superclass.constructor.call(this, hd,
|
|
|
1482 |
"gridSplitters" + this.grid.getGridEl().id, {
|
|
|
1483 |
dragElId : Ext.id(this.proxy.dom), resizeFrame:false
|
|
|
1484 |
});
|
|
|
1485 |
this.scroll = false;
|
|
|
1486 |
this.hw = this.view.splitHandleWidth || 5;
|
|
|
1487 |
};
|
|
|
1488 |
Ext.extend(Ext.grid.GridView.SplitDragZone, Ext.dd.DDProxy, {
|
|
|
1489 |
|
|
|
1490 |
b4StartDrag : function(x, y){
|
|
|
1491 |
this.view.headersDisabled = true;
|
|
|
1492 |
var h = this.view.mainWrap.getHeight();
|
|
|
1493 |
this.marker.setHeight(h);
|
|
|
1494 |
this.marker.show();
|
|
|
1495 |
this.marker.alignTo(this.view.getHeaderCell(this.cellIndex), 'tl-tl', [-2, 0]);
|
|
|
1496 |
this.proxy.setHeight(h);
|
|
|
1497 |
var w = this.cm.getColumnWidth(this.cellIndex);
|
|
|
1498 |
var minw = Math.max(w-this.grid.minColumnWidth, 0);
|
|
|
1499 |
this.resetConstraints();
|
|
|
1500 |
this.setXConstraint(minw, 1000);
|
|
|
1501 |
this.setYConstraint(0, 0);
|
|
|
1502 |
this.minX = x - minw;
|
|
|
1503 |
this.maxX = x + 1000;
|
|
|
1504 |
this.startPos = x;
|
|
|
1505 |
Ext.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
|
|
|
1506 |
},
|
|
|
1507 |
|
|
|
1508 |
|
|
|
1509 |
handleMouseDown : function(e){
|
|
|
1510 |
var t = this.view.findHeaderCell(e.getTarget());
|
|
|
1511 |
if(t){
|
|
|
1512 |
var xy = this.view.fly(t).getXY(), x = xy[0], y = xy[1];
|
|
|
1513 |
var exy = e.getXY(), ex = exy[0], ey = exy[1];
|
|
|
1514 |
var w = t.offsetWidth, adjust = false;
|
|
|
1515 |
if((ex - x) <= this.hw){
|
|
|
1516 |
adjust = -1;
|
|
|
1517 |
}else if((x+w) - ex <= this.hw){
|
|
|
1518 |
adjust = 0;
|
|
|
1519 |
}
|
|
|
1520 |
if(adjust !== false){
|
|
|
1521 |
this.cm = this.grid.colModel;
|
|
|
1522 |
var ci = this.view.getCellIndex(t);
|
|
|
1523 |
if(adjust == -1){
|
|
|
1524 |
if (ci + adjust < 0) {
|
|
|
1525 |
return;
|
|
|
1526 |
}
|
|
|
1527 |
while(this.cm.isHidden(ci+adjust)){
|
|
|
1528 |
--adjust;
|
|
|
1529 |
if(ci+adjust < 0){
|
|
|
1530 |
return;
|
|
|
1531 |
}
|
|
|
1532 |
}
|
|
|
1533 |
}
|
|
|
1534 |
this.cellIndex = ci+adjust;
|
|
|
1535 |
this.split = t.dom;
|
|
|
1536 |
if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
|
|
|
1537 |
Ext.grid.GridView.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
|
|
|
1538 |
}
|
|
|
1539 |
}else if(this.view.columnDrag){
|
|
|
1540 |
this.view.columnDrag.callHandleMouseDown(e);
|
|
|
1541 |
}
|
|
|
1542 |
}
|
|
|
1543 |
},
|
|
|
1544 |
|
|
|
1545 |
endDrag : function(e){
|
|
|
1546 |
this.marker.hide();
|
|
|
1547 |
var v = this.view;
|
|
|
1548 |
var endX = Math.max(this.minX, e.getPageX());
|
|
|
1549 |
var diff = endX - this.startPos;
|
|
|
1550 |
v.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
|
|
|
1551 |
setTimeout(function(){
|
|
|
1552 |
v.headersDisabled = false;
|
|
|
1553 |
}, 50);
|
|
|
1554 |
},
|
|
|
1555 |
|
|
|
1556 |
autoOffset : function(){
|
|
|
1557 |
this.setDelta(0,0);
|
|
|
1558 |
}
|
|
|
1559 |
});
|