1 | /*! |
---|
2 | * Ext JS Library 3.4.0 |
---|
3 | * Copyright(c) 2006-2011 Sencha Inc. |
---|
4 | * licensing@sencha.com |
---|
5 | * http://www.sencha.com/license |
---|
6 | */ |
---|
7 | /** |
---|
8 | * @class Ext.grid.GridPanel |
---|
9 | * @extends Ext.Panel |
---|
10 | * <p>This class represents the primary interface of a component based grid control to represent data |
---|
11 | * in a tabular format of rows and columns. The GridPanel is composed of the following:</p> |
---|
12 | * <div class="mdetail-params"><ul> |
---|
13 | * <li><b>{@link Ext.data.Store Store}</b> : The Model holding the data records (rows) |
---|
14 | * <div class="sub-desc"></div></li> |
---|
15 | * <li><b>{@link Ext.grid.ColumnModel Column model}</b> : Column makeup |
---|
16 | * <div class="sub-desc"></div></li> |
---|
17 | * <li><b>{@link Ext.grid.GridView View}</b> : Encapsulates the user interface |
---|
18 | * <div class="sub-desc"></div></li> |
---|
19 | * <li><b>{@link Ext.grid.AbstractSelectionModel selection model}</b> : Selection behavior |
---|
20 | * <div class="sub-desc"></div></li> |
---|
21 | * </ul></div> |
---|
22 | * <p>Example usage:</p> |
---|
23 | * <pre><code> |
---|
24 | var grid = new Ext.grid.GridPanel({ |
---|
25 | {@link #store}: new {@link Ext.data.Store}({ |
---|
26 | {@link Ext.data.Store#autoDestroy autoDestroy}: true, |
---|
27 | {@link Ext.data.Store#reader reader}: reader, |
---|
28 | {@link Ext.data.Store#data data}: xg.dummyData |
---|
29 | }), |
---|
30 | {@link #colModel}: new {@link Ext.grid.ColumnModel}({ |
---|
31 | {@link Ext.grid.ColumnModel#defaults defaults}: { |
---|
32 | width: 120, |
---|
33 | sortable: true |
---|
34 | }, |
---|
35 | {@link Ext.grid.ColumnModel#columns columns}: [ |
---|
36 | {id: 'company', header: 'Company', width: 200, sortable: true, dataIndex: 'company'}, |
---|
37 | {header: 'Price', renderer: Ext.util.Format.usMoney, dataIndex: 'price'}, |
---|
38 | {header: 'Change', dataIndex: 'change'}, |
---|
39 | {header: '% Change', dataIndex: 'pctChange'}, |
---|
40 | // instead of specifying renderer: Ext.util.Format.dateRenderer('m/d/Y') use xtype |
---|
41 | { |
---|
42 | header: 'Last Updated', width: 135, dataIndex: 'lastChange', |
---|
43 | xtype: 'datecolumn', format: 'M d, Y' |
---|
44 | } |
---|
45 | ] |
---|
46 | }), |
---|
47 | {@link #viewConfig}: { |
---|
48 | {@link Ext.grid.GridView#forceFit forceFit}: true, |
---|
49 | |
---|
50 | // Return CSS class to apply to rows depending upon data values |
---|
51 | {@link Ext.grid.GridView#getRowClass getRowClass}: function(record, index) { |
---|
52 | var c = record.{@link Ext.data.Record#get get}('change'); |
---|
53 | if (c < 0) { |
---|
54 | return 'price-fall'; |
---|
55 | } else if (c > 0) { |
---|
56 | return 'price-rise'; |
---|
57 | } |
---|
58 | } |
---|
59 | }, |
---|
60 | {@link #sm}: new Ext.grid.RowSelectionModel({singleSelect:true}), |
---|
61 | width: 600, |
---|
62 | height: 300, |
---|
63 | frame: true, |
---|
64 | title: 'Framed with Row Selection and Horizontal Scrolling', |
---|
65 | iconCls: 'icon-grid' |
---|
66 | }); |
---|
67 | * </code></pre> |
---|
68 | * <p><b><u>Notes:</u></b></p> |
---|
69 | * <div class="mdetail-params"><ul> |
---|
70 | * <li>Although this class inherits many configuration options from base classes, some of them |
---|
71 | * (such as autoScroll, autoWidth, layout, items, etc) are not used by this class, and will |
---|
72 | * have no effect.</li> |
---|
73 | * <li>A grid <b>requires</b> a width in which to scroll its columns, and a height in which to |
---|
74 | * scroll its rows. These dimensions can either be set explicitly through the |
---|
75 | * <tt>{@link Ext.BoxComponent#height height}</tt> and <tt>{@link Ext.BoxComponent#width width}</tt> |
---|
76 | * configuration options or implicitly set by using the grid as a child item of a |
---|
77 | * {@link Ext.Container Container} which will have a {@link Ext.Container#layout layout manager} |
---|
78 | * provide the sizing of its child items (for example the Container of the Grid may specify |
---|
79 | * <tt>{@link Ext.Container#layout layout}:'fit'</tt>).</li> |
---|
80 | * <li>To access the data in a Grid, it is necessary to use the data model encapsulated |
---|
81 | * by the {@link #store Store}. See the {@link #cellclick} event for more details.</li> |
---|
82 | * </ul></div> |
---|
83 | * @constructor |
---|
84 | * @param {Object} config The config object |
---|
85 | * @xtype grid |
---|
86 | */ |
---|
87 | Ext.grid.GridPanel = Ext.extend(Ext.Panel, { |
---|
88 | /** |
---|
89 | * @cfg {String} autoExpandColumn |
---|
90 | * <p>The <tt>{@link Ext.grid.Column#id id}</tt> of a {@link Ext.grid.Column column} in |
---|
91 | * this grid that should expand to fill unused space. This value specified here can not |
---|
92 | * be <tt>0</tt>.</p> |
---|
93 | * <br><p><b>Note</b>: If the Grid's {@link Ext.grid.GridView view} is configured with |
---|
94 | * <tt>{@link Ext.grid.GridView#forceFit forceFit}=true</tt> the <tt>autoExpandColumn</tt> |
---|
95 | * is ignored. See {@link Ext.grid.Column}.<tt>{@link Ext.grid.Column#width width}</tt> |
---|
96 | * for additional details.</p> |
---|
97 | * <p>See <tt>{@link #autoExpandMax}</tt> and <tt>{@link #autoExpandMin}</tt> also.</p> |
---|
98 | */ |
---|
99 | autoExpandColumn : false, |
---|
100 | |
---|
101 | /** |
---|
102 | * @cfg {Number} autoExpandMax The maximum width the <tt>{@link #autoExpandColumn}</tt> |
---|
103 | * can have (if enabled). Defaults to <tt>1000</tt>. |
---|
104 | */ |
---|
105 | autoExpandMax : 1000, |
---|
106 | |
---|
107 | /** |
---|
108 | * @cfg {Number} autoExpandMin The minimum width the <tt>{@link #autoExpandColumn}</tt> |
---|
109 | * can have (if enabled). Defaults to <tt>50</tt>. |
---|
110 | */ |
---|
111 | autoExpandMin : 50, |
---|
112 | |
---|
113 | /** |
---|
114 | * @cfg {Boolean} columnLines <tt>true</tt> to add css for column separation lines. |
---|
115 | * Default is <tt>false</tt>. |
---|
116 | */ |
---|
117 | columnLines : false, |
---|
118 | |
---|
119 | /** |
---|
120 | * @cfg {Object} cm Shorthand for <tt>{@link #colModel}</tt>. |
---|
121 | */ |
---|
122 | /** |
---|
123 | * @cfg {Object} colModel The {@link Ext.grid.ColumnModel} to use when rendering the grid (required). |
---|
124 | */ |
---|
125 | /** |
---|
126 | * @cfg {Array} columns An array of {@link Ext.grid.Column columns} to auto create a |
---|
127 | * {@link Ext.grid.ColumnModel}. The ColumnModel may be explicitly created via the |
---|
128 | * <tt>{@link #colModel}</tt> configuration property. |
---|
129 | */ |
---|
130 | /** |
---|
131 | * @cfg {String} ddGroup The DD group this GridPanel belongs to. Defaults to <tt>'GridDD'</tt> if not specified. |
---|
132 | */ |
---|
133 | /** |
---|
134 | * @cfg {String} ddText |
---|
135 | * Configures the text in the drag proxy. Defaults to: |
---|
136 | * <pre><code> |
---|
137 | * ddText : '{0} selected row{1}' |
---|
138 | * </code></pre> |
---|
139 | * <tt>{0}</tt> is replaced with the number of selected rows. |
---|
140 | */ |
---|
141 | ddText : '{0} selected row{1}', |
---|
142 | |
---|
143 | /** |
---|
144 | * @cfg {Boolean} deferRowRender <P>Defaults to <tt>true</tt> to enable deferred row rendering.</p> |
---|
145 | * <p>This allows the GridPanel to be initially rendered empty, with the expensive update of the row |
---|
146 | * structure deferred so that layouts with GridPanels appear more quickly.</p> |
---|
147 | */ |
---|
148 | deferRowRender : true, |
---|
149 | |
---|
150 | /** |
---|
151 | * @cfg {Boolean} disableSelection <p><tt>true</tt> to disable selections in the grid. Defaults to <tt>false</tt>.</p> |
---|
152 | * <p>Ignored if a {@link #selModel SelectionModel} is specified.</p> |
---|
153 | */ |
---|
154 | /** |
---|
155 | * @cfg {Boolean} enableColumnResize <tt>false</tt> to turn off column resizing for the whole grid. Defaults to <tt>true</tt>. |
---|
156 | */ |
---|
157 | /** |
---|
158 | * @cfg {Boolean} enableColumnHide |
---|
159 | * Defaults to <tt>true</tt> to enable {@link Ext.grid.Column#hidden hiding of columns} |
---|
160 | * with the {@link #enableHdMenu header menu}. |
---|
161 | */ |
---|
162 | enableColumnHide : true, |
---|
163 | |
---|
164 | /** |
---|
165 | * @cfg {Boolean} enableColumnMove Defaults to <tt>true</tt> to enable drag and drop reorder of columns. <tt>false</tt> |
---|
166 | * to turn off column reordering via drag drop. |
---|
167 | */ |
---|
168 | enableColumnMove : true, |
---|
169 | |
---|
170 | /** |
---|
171 | * @cfg {Boolean} enableDragDrop <p>Enables dragging of the selected rows of the GridPanel. Defaults to <tt>false</tt>.</p> |
---|
172 | * <p>Setting this to <b><tt>true</tt></b> causes this GridPanel's {@link #getView GridView} to |
---|
173 | * create an instance of {@link Ext.grid.GridDragZone}. <b>Note</b>: this is available only <b>after</b> |
---|
174 | * the Grid has been rendered as the GridView's <tt>{@link Ext.grid.GridView#dragZone dragZone}</tt> |
---|
175 | * property.</p> |
---|
176 | * <p>A cooperating {@link Ext.dd.DropZone DropZone} must be created who's implementations of |
---|
177 | * {@link Ext.dd.DropZone#onNodeEnter onNodeEnter}, {@link Ext.dd.DropZone#onNodeOver onNodeOver}, |
---|
178 | * {@link Ext.dd.DropZone#onNodeOut onNodeOut} and {@link Ext.dd.DropZone#onNodeDrop onNodeDrop} are able |
---|
179 | * to process the {@link Ext.grid.GridDragZone#getDragData data} which is provided.</p> |
---|
180 | */ |
---|
181 | enableDragDrop : false, |
---|
182 | |
---|
183 | /** |
---|
184 | * @cfg {Boolean} enableHdMenu Defaults to <tt>true</tt> to enable the drop down button for menu in the headers. |
---|
185 | */ |
---|
186 | enableHdMenu : true, |
---|
187 | |
---|
188 | /** |
---|
189 | * @cfg {Boolean} hideHeaders True to hide the grid's header. Defaults to <code>false</code>. |
---|
190 | */ |
---|
191 | /** |
---|
192 | * @cfg {Object} loadMask An {@link Ext.LoadMask} config or true to mask the grid while |
---|
193 | * loading. Defaults to <code>false</code>. |
---|
194 | */ |
---|
195 | loadMask : false, |
---|
196 | |
---|
197 | /** |
---|
198 | * @cfg {Number} maxHeight Sets the maximum height of the grid - ignored if <tt>autoHeight</tt> is not on. |
---|
199 | */ |
---|
200 | /** |
---|
201 | * @cfg {Number} minColumnWidth The minimum width a column can be resized to. Defaults to <tt>25</tt>. |
---|
202 | */ |
---|
203 | minColumnWidth : 25, |
---|
204 | |
---|
205 | /** |
---|
206 | * @cfg {Object} sm Shorthand for <tt>{@link #selModel}</tt>. |
---|
207 | */ |
---|
208 | /** |
---|
209 | * @cfg {Object} selModel Any subclass of {@link Ext.grid.AbstractSelectionModel} that will provide |
---|
210 | * the selection model for the grid (defaults to {@link Ext.grid.RowSelectionModel} if not specified). |
---|
211 | */ |
---|
212 | /** |
---|
213 | * @cfg {Ext.data.Store} store The {@link Ext.data.Store} the grid should use as its data source (required). |
---|
214 | */ |
---|
215 | /** |
---|
216 | * @cfg {Boolean} stripeRows <tt>true</tt> to stripe the rows. Default is <tt>false</tt>. |
---|
217 | * <p>This causes the CSS class <tt><b>x-grid3-row-alt</b></tt> to be added to alternate rows of |
---|
218 | * the grid. A default CSS rule is provided which sets a background colour, but you can override this |
---|
219 | * with a rule which either overrides the <b>background-color</b> style using the '!important' |
---|
220 | * modifier, or which uses a CSS selector of higher specificity.</p> |
---|
221 | */ |
---|
222 | stripeRows : false, |
---|
223 | |
---|
224 | /** |
---|
225 | * @cfg {Boolean} trackMouseOver True to highlight rows when the mouse is over. Default is <tt>true</tt> |
---|
226 | * for GridPanel, but <tt>false</tt> for EditorGridPanel. |
---|
227 | */ |
---|
228 | trackMouseOver : true, |
---|
229 | |
---|
230 | /** |
---|
231 | * @cfg {Array} stateEvents |
---|
232 | * An array of events that, when fired, should trigger this component to save its state. |
---|
233 | * Defaults to:<pre><code> |
---|
234 | * stateEvents: ['columnmove', 'columnresize', 'sortchange', 'groupchange'] |
---|
235 | * </code></pre> |
---|
236 | * <p>These can be any types of events supported by this component, including browser or |
---|
237 | * custom events (e.g., <tt>['click', 'customerchange']</tt>).</p> |
---|
238 | * <p>See {@link Ext.Component#stateful} for an explanation of saving and restoring |
---|
239 | * Component state.</p> |
---|
240 | */ |
---|
241 | stateEvents : ['columnmove', 'columnresize', 'sortchange', 'groupchange'], |
---|
242 | |
---|
243 | /** |
---|
244 | * @cfg {Object} view The {@link Ext.grid.GridView} used by the grid. This can be set |
---|
245 | * before a call to {@link Ext.Component#render render()}. |
---|
246 | */ |
---|
247 | view : null, |
---|
248 | |
---|
249 | /** |
---|
250 | * @cfg {Array} bubbleEvents |
---|
251 | * <p>An array of events that, when fired, should be bubbled to any parent container. |
---|
252 | * See {@link Ext.util.Observable#enableBubble}. |
---|
253 | * Defaults to <tt>[]</tt>. |
---|
254 | */ |
---|
255 | bubbleEvents: [], |
---|
256 | |
---|
257 | /** |
---|
258 | * @cfg {Object} viewConfig A config object that will be applied to the grid's UI view. Any of |
---|
259 | * the config options available for {@link Ext.grid.GridView} can be specified here. This option |
---|
260 | * is ignored if <tt>{@link #view}</tt> is specified. |
---|
261 | */ |
---|
262 | |
---|
263 | // private |
---|
264 | rendered : false, |
---|
265 | |
---|
266 | // private |
---|
267 | viewReady : false, |
---|
268 | |
---|
269 | // private |
---|
270 | initComponent : function() { |
---|
271 | Ext.grid.GridPanel.superclass.initComponent.call(this); |
---|
272 | |
---|
273 | if (this.columnLines) { |
---|
274 | this.cls = (this.cls || '') + ' x-grid-with-col-lines'; |
---|
275 | } |
---|
276 | // override any provided value since it isn't valid |
---|
277 | // and is causing too many bug reports ;) |
---|
278 | this.autoScroll = false; |
---|
279 | this.autoWidth = false; |
---|
280 | |
---|
281 | if(Ext.isArray(this.columns)){ |
---|
282 | this.colModel = new Ext.grid.ColumnModel(this.columns); |
---|
283 | delete this.columns; |
---|
284 | } |
---|
285 | |
---|
286 | // check and correct shorthanded configs |
---|
287 | if(this.ds){ |
---|
288 | this.store = this.ds; |
---|
289 | delete this.ds; |
---|
290 | } |
---|
291 | if(this.cm){ |
---|
292 | this.colModel = this.cm; |
---|
293 | delete this.cm; |
---|
294 | } |
---|
295 | if(this.sm){ |
---|
296 | this.selModel = this.sm; |
---|
297 | delete this.sm; |
---|
298 | } |
---|
299 | this.store = Ext.StoreMgr.lookup(this.store); |
---|
300 | |
---|
301 | this.addEvents( |
---|
302 | // raw events |
---|
303 | /** |
---|
304 | * @event click |
---|
305 | * The raw click event for the entire grid. |
---|
306 | * @param {Ext.EventObject} e |
---|
307 | */ |
---|
308 | 'click', |
---|
309 | /** |
---|
310 | * @event dblclick |
---|
311 | * The raw dblclick event for the entire grid. |
---|
312 | * @param {Ext.EventObject} e |
---|
313 | */ |
---|
314 | 'dblclick', |
---|
315 | /** |
---|
316 | * @event contextmenu |
---|
317 | * The raw contextmenu event for the entire grid. |
---|
318 | * @param {Ext.EventObject} e |
---|
319 | */ |
---|
320 | 'contextmenu', |
---|
321 | /** |
---|
322 | * @event mousedown |
---|
323 | * The raw mousedown event for the entire grid. |
---|
324 | * @param {Ext.EventObject} e |
---|
325 | */ |
---|
326 | 'mousedown', |
---|
327 | /** |
---|
328 | * @event mouseup |
---|
329 | * The raw mouseup event for the entire grid. |
---|
330 | * @param {Ext.EventObject} e |
---|
331 | */ |
---|
332 | 'mouseup', |
---|
333 | /** |
---|
334 | * @event mouseover |
---|
335 | * The raw mouseover event for the entire grid. |
---|
336 | * @param {Ext.EventObject} e |
---|
337 | */ |
---|
338 | 'mouseover', |
---|
339 | /** |
---|
340 | * @event mouseout |
---|
341 | * The raw mouseout event for the entire grid. |
---|
342 | * @param {Ext.EventObject} e |
---|
343 | */ |
---|
344 | 'mouseout', |
---|
345 | /** |
---|
346 | * @event keypress |
---|
347 | * The raw keypress event for the entire grid. |
---|
348 | * @param {Ext.EventObject} e |
---|
349 | */ |
---|
350 | 'keypress', |
---|
351 | /** |
---|
352 | * @event keydown |
---|
353 | * The raw keydown event for the entire grid. |
---|
354 | * @param {Ext.EventObject} e |
---|
355 | */ |
---|
356 | 'keydown', |
---|
357 | |
---|
358 | // custom events |
---|
359 | /** |
---|
360 | * @event cellmousedown |
---|
361 | * Fires before a cell is clicked |
---|
362 | * @param {Grid} this |
---|
363 | * @param {Number} rowIndex |
---|
364 | * @param {Number} columnIndex |
---|
365 | * @param {Ext.EventObject} e |
---|
366 | */ |
---|
367 | 'cellmousedown', |
---|
368 | /** |
---|
369 | * @event rowmousedown |
---|
370 | * Fires before a row is clicked |
---|
371 | * @param {Grid} this |
---|
372 | * @param {Number} rowIndex |
---|
373 | * @param {Ext.EventObject} e |
---|
374 | */ |
---|
375 | 'rowmousedown', |
---|
376 | /** |
---|
377 | * @event headermousedown |
---|
378 | * Fires before a header is clicked |
---|
379 | * @param {Grid} this |
---|
380 | * @param {Number} columnIndex |
---|
381 | * @param {Ext.EventObject} e |
---|
382 | */ |
---|
383 | 'headermousedown', |
---|
384 | |
---|
385 | /** |
---|
386 | * @event groupmousedown |
---|
387 | * Fires before a group header is clicked. <b>Only applies for grids with a {@link Ext.grid.GroupingView GroupingView}</b>. |
---|
388 | * @param {Grid} this |
---|
389 | * @param {String} groupField |
---|
390 | * @param {String} groupValue |
---|
391 | * @param {Ext.EventObject} e |
---|
392 | */ |
---|
393 | 'groupmousedown', |
---|
394 | |
---|
395 | /** |
---|
396 | * @event rowbodymousedown |
---|
397 | * Fires before the row body is clicked. <b>Only applies for grids with {@link Ext.grid.GridView#enableRowBody enableRowBody} configured.</b> |
---|
398 | * @param {Grid} this |
---|
399 | * @param {Number} rowIndex |
---|
400 | * @param {Ext.EventObject} e |
---|
401 | */ |
---|
402 | 'rowbodymousedown', |
---|
403 | |
---|
404 | /** |
---|
405 | * @event containermousedown |
---|
406 | * Fires before the container is clicked. The container consists of any part of the grid body that is not covered by a row. |
---|
407 | * @param {Grid} this |
---|
408 | * @param {Ext.EventObject} e |
---|
409 | */ |
---|
410 | 'containermousedown', |
---|
411 | |
---|
412 | /** |
---|
413 | * @event cellclick |
---|
414 | * Fires when a cell is clicked. |
---|
415 | * The data for the cell is drawn from the {@link Ext.data.Record Record} |
---|
416 | * for this row. To access the data in the listener function use the |
---|
417 | * following technique: |
---|
418 | * <pre><code> |
---|
419 | function(grid, rowIndex, columnIndex, e) { |
---|
420 | var record = grid.getStore().getAt(rowIndex); // Get the Record |
---|
421 | var fieldName = grid.getColumnModel().getDataIndex(columnIndex); // Get field name |
---|
422 | var data = record.get(fieldName); |
---|
423 | } |
---|
424 | </code></pre> |
---|
425 | * @param {Grid} this |
---|
426 | * @param {Number} rowIndex |
---|
427 | * @param {Number} columnIndex |
---|
428 | * @param {Ext.EventObject} e |
---|
429 | */ |
---|
430 | 'cellclick', |
---|
431 | /** |
---|
432 | * @event celldblclick |
---|
433 | * Fires when a cell is double clicked |
---|
434 | * @param {Grid} this |
---|
435 | * @param {Number} rowIndex |
---|
436 | * @param {Number} columnIndex |
---|
437 | * @param {Ext.EventObject} e |
---|
438 | */ |
---|
439 | 'celldblclick', |
---|
440 | /** |
---|
441 | * @event rowclick |
---|
442 | * Fires when a row is clicked |
---|
443 | * @param {Grid} this |
---|
444 | * @param {Number} rowIndex |
---|
445 | * @param {Ext.EventObject} e |
---|
446 | */ |
---|
447 | 'rowclick', |
---|
448 | /** |
---|
449 | * @event rowdblclick |
---|
450 | * Fires when a row is double clicked |
---|
451 | * @param {Grid} this |
---|
452 | * @param {Number} rowIndex |
---|
453 | * @param {Ext.EventObject} e |
---|
454 | */ |
---|
455 | 'rowdblclick', |
---|
456 | /** |
---|
457 | * @event headerclick |
---|
458 | * Fires when a header is clicked |
---|
459 | * @param {Grid} this |
---|
460 | * @param {Number} columnIndex |
---|
461 | * @param {Ext.EventObject} e |
---|
462 | */ |
---|
463 | 'headerclick', |
---|
464 | /** |
---|
465 | * @event headerdblclick |
---|
466 | * Fires when a header cell is double clicked |
---|
467 | * @param {Grid} this |
---|
468 | * @param {Number} columnIndex |
---|
469 | * @param {Ext.EventObject} e |
---|
470 | */ |
---|
471 | 'headerdblclick', |
---|
472 | /** |
---|
473 | * @event groupclick |
---|
474 | * Fires when group header is clicked. <b>Only applies for grids with a {@link Ext.grid.GroupingView GroupingView}</b>. |
---|
475 | * @param {Grid} this |
---|
476 | * @param {String} groupField |
---|
477 | * @param {String} groupValue |
---|
478 | * @param {Ext.EventObject} e |
---|
479 | */ |
---|
480 | 'groupclick', |
---|
481 | /** |
---|
482 | * @event groupdblclick |
---|
483 | * Fires when group header is double clicked. <b>Only applies for grids with a {@link Ext.grid.GroupingView GroupingView}</b>. |
---|
484 | * @param {Grid} this |
---|
485 | * @param {String} groupField |
---|
486 | * @param {String} groupValue |
---|
487 | * @param {Ext.EventObject} e |
---|
488 | */ |
---|
489 | 'groupdblclick', |
---|
490 | /** |
---|
491 | * @event containerclick |
---|
492 | * Fires when the container is clicked. The container consists of any part of the grid body that is not covered by a row. |
---|
493 | * @param {Grid} this |
---|
494 | * @param {Ext.EventObject} e |
---|
495 | */ |
---|
496 | 'containerclick', |
---|
497 | /** |
---|
498 | * @event containerdblclick |
---|
499 | * Fires when the container is double clicked. The container consists of any part of the grid body that is not covered by a row. |
---|
500 | * @param {Grid} this |
---|
501 | * @param {Ext.EventObject} e |
---|
502 | */ |
---|
503 | 'containerdblclick', |
---|
504 | |
---|
505 | /** |
---|
506 | * @event rowbodyclick |
---|
507 | * Fires when the row body is clicked. <b>Only applies for grids with {@link Ext.grid.GridView#enableRowBody enableRowBody} configured.</b> |
---|
508 | * @param {Grid} this |
---|
509 | * @param {Number} rowIndex |
---|
510 | * @param {Ext.EventObject} e |
---|
511 | */ |
---|
512 | 'rowbodyclick', |
---|
513 | /** |
---|
514 | * @event rowbodydblclick |
---|
515 | * Fires when the row body is double clicked. <b>Only applies for grids with {@link Ext.grid.GridView#enableRowBody enableRowBody} configured.</b> |
---|
516 | * @param {Grid} this |
---|
517 | * @param {Number} rowIndex |
---|
518 | * @param {Ext.EventObject} e |
---|
519 | */ |
---|
520 | 'rowbodydblclick', |
---|
521 | |
---|
522 | /** |
---|
523 | * @event rowcontextmenu |
---|
524 | * Fires when a row is right clicked |
---|
525 | * @param {Grid} this |
---|
526 | * @param {Number} rowIndex |
---|
527 | * @param {Ext.EventObject} e |
---|
528 | */ |
---|
529 | 'rowcontextmenu', |
---|
530 | /** |
---|
531 | * @event cellcontextmenu |
---|
532 | * Fires when a cell is right clicked |
---|
533 | * @param {Grid} this |
---|
534 | * @param {Number} rowIndex |
---|
535 | * @param {Number} cellIndex |
---|
536 | * @param {Ext.EventObject} e |
---|
537 | */ |
---|
538 | 'cellcontextmenu', |
---|
539 | /** |
---|
540 | * @event headercontextmenu |
---|
541 | * Fires when a header is right clicked |
---|
542 | * @param {Grid} this |
---|
543 | * @param {Number} columnIndex |
---|
544 | * @param {Ext.EventObject} e |
---|
545 | */ |
---|
546 | 'headercontextmenu', |
---|
547 | /** |
---|
548 | * @event groupcontextmenu |
---|
549 | * Fires when group header is right clicked. <b>Only applies for grids with a {@link Ext.grid.GroupingView GroupingView}</b>. |
---|
550 | * @param {Grid} this |
---|
551 | * @param {String} groupField |
---|
552 | * @param {String} groupValue |
---|
553 | * @param {Ext.EventObject} e |
---|
554 | */ |
---|
555 | 'groupcontextmenu', |
---|
556 | /** |
---|
557 | * @event containercontextmenu |
---|
558 | * Fires when the container is right clicked. The container consists of any part of the grid body that is not covered by a row. |
---|
559 | * @param {Grid} this |
---|
560 | * @param {Ext.EventObject} e |
---|
561 | */ |
---|
562 | 'containercontextmenu', |
---|
563 | /** |
---|
564 | * @event rowbodycontextmenu |
---|
565 | * Fires when the row body is right clicked. <b>Only applies for grids with {@link Ext.grid.GridView#enableRowBody enableRowBody} configured.</b> |
---|
566 | * @param {Grid} this |
---|
567 | * @param {Number} rowIndex |
---|
568 | * @param {Ext.EventObject} e |
---|
569 | */ |
---|
570 | 'rowbodycontextmenu', |
---|
571 | /** |
---|
572 | * @event bodyscroll |
---|
573 | * Fires when the body element is scrolled |
---|
574 | * @param {Number} scrollLeft |
---|
575 | * @param {Number} scrollTop |
---|
576 | */ |
---|
577 | 'bodyscroll', |
---|
578 | /** |
---|
579 | * @event columnresize |
---|
580 | * Fires when the user resizes a column |
---|
581 | * @param {Number} columnIndex |
---|
582 | * @param {Number} newSize |
---|
583 | */ |
---|
584 | 'columnresize', |
---|
585 | /** |
---|
586 | * @event columnmove |
---|
587 | * Fires when the user moves a column |
---|
588 | * @param {Number} oldIndex |
---|
589 | * @param {Number} newIndex |
---|
590 | */ |
---|
591 | 'columnmove', |
---|
592 | /** |
---|
593 | * @event sortchange |
---|
594 | * Fires when the grid's store sort changes |
---|
595 | * @param {Grid} this |
---|
596 | * @param {Object} sortInfo An object with the keys field and direction |
---|
597 | */ |
---|
598 | 'sortchange', |
---|
599 | /** |
---|
600 | * @event groupchange |
---|
601 | * Fires when the grid's grouping changes (only applies for grids with a {@link Ext.grid.GroupingView GroupingView}) |
---|
602 | * @param {Grid} this |
---|
603 | * @param {String} groupField A string with the grouping field, null if the store is not grouped. |
---|
604 | */ |
---|
605 | 'groupchange', |
---|
606 | /** |
---|
607 | * @event reconfigure |
---|
608 | * Fires when the grid is reconfigured with a new store and/or column model. |
---|
609 | * @param {Grid} this |
---|
610 | * @param {Ext.data.Store} store The new store |
---|
611 | * @param {Ext.grid.ColumnModel} colModel The new column model |
---|
612 | */ |
---|
613 | 'reconfigure', |
---|
614 | /** |
---|
615 | * @event viewready |
---|
616 | * Fires when the grid view is available (use this for selecting a default row). |
---|
617 | * @param {Grid} this |
---|
618 | */ |
---|
619 | 'viewready' |
---|
620 | ); |
---|
621 | }, |
---|
622 | |
---|
623 | // private |
---|
624 | onRender : function(ct, position){ |
---|
625 | Ext.grid.GridPanel.superclass.onRender.apply(this, arguments); |
---|
626 | |
---|
627 | var c = this.getGridEl(); |
---|
628 | |
---|
629 | this.el.addClass('x-grid-panel'); |
---|
630 | |
---|
631 | this.mon(c, { |
---|
632 | scope: this, |
---|
633 | mousedown: this.onMouseDown, |
---|
634 | click: this.onClick, |
---|
635 | dblclick: this.onDblClick, |
---|
636 | contextmenu: this.onContextMenu |
---|
637 | }); |
---|
638 | |
---|
639 | this.relayEvents(c, ['mousedown','mouseup','mouseover','mouseout','keypress', 'keydown']); |
---|
640 | |
---|
641 | var view = this.getView(); |
---|
642 | view.init(this); |
---|
643 | view.render(); |
---|
644 | this.getSelectionModel().init(this); |
---|
645 | }, |
---|
646 | |
---|
647 | // private |
---|
648 | initEvents : function(){ |
---|
649 | Ext.grid.GridPanel.superclass.initEvents.call(this); |
---|
650 | |
---|
651 | if(this.loadMask){ |
---|
652 | this.loadMask = new Ext.LoadMask(this.bwrap, |
---|
653 | Ext.apply({store:this.store}, this.loadMask)); |
---|
654 | } |
---|
655 | }, |
---|
656 | |
---|
657 | initStateEvents : function(){ |
---|
658 | Ext.grid.GridPanel.superclass.initStateEvents.call(this); |
---|
659 | this.mon(this.colModel, 'hiddenchange', this.saveState, this, {delay: 100}); |
---|
660 | }, |
---|
661 | |
---|
662 | applyState : function(state){ |
---|
663 | var cm = this.colModel, |
---|
664 | cs = state.columns, |
---|
665 | store = this.store, |
---|
666 | s, |
---|
667 | c, |
---|
668 | colIndex; |
---|
669 | |
---|
670 | if(cs){ |
---|
671 | for(var i = 0, len = cs.length; i < len; i++){ |
---|
672 | s = cs[i]; |
---|
673 | c = cm.getColumnById(s.id); |
---|
674 | if(c){ |
---|
675 | colIndex = cm.getIndexById(s.id); |
---|
676 | cm.setState(colIndex, { |
---|
677 | hidden: s.hidden, |
---|
678 | width: s.width, |
---|
679 | sortable: s.sortable |
---|
680 | }); |
---|
681 | if(colIndex != i){ |
---|
682 | cm.moveColumn(colIndex, i); |
---|
683 | } |
---|
684 | } |
---|
685 | } |
---|
686 | } |
---|
687 | if(store){ |
---|
688 | s = state.sort; |
---|
689 | if(s){ |
---|
690 | store[store.remoteSort ? 'setDefaultSort' : 'sort'](s.field, s.direction); |
---|
691 | } |
---|
692 | s = state.group; |
---|
693 | if(store.groupBy){ |
---|
694 | if(s){ |
---|
695 | store.groupBy(s); |
---|
696 | }else{ |
---|
697 | store.clearGrouping(); |
---|
698 | } |
---|
699 | } |
---|
700 | |
---|
701 | } |
---|
702 | var o = Ext.apply({}, state); |
---|
703 | delete o.columns; |
---|
704 | delete o.sort; |
---|
705 | Ext.grid.GridPanel.superclass.applyState.call(this, o); |
---|
706 | }, |
---|
707 | |
---|
708 | getState : function(){ |
---|
709 | var o = {columns: []}, |
---|
710 | store = this.store, |
---|
711 | ss, |
---|
712 | gs; |
---|
713 | |
---|
714 | for(var i = 0, c; (c = this.colModel.config[i]); i++){ |
---|
715 | o.columns[i] = { |
---|
716 | id: c.id, |
---|
717 | width: c.width |
---|
718 | }; |
---|
719 | if(c.hidden){ |
---|
720 | o.columns[i].hidden = true; |
---|
721 | } |
---|
722 | if(c.sortable){ |
---|
723 | o.columns[i].sortable = true; |
---|
724 | } |
---|
725 | } |
---|
726 | if(store){ |
---|
727 | ss = store.getSortState(); |
---|
728 | if(ss){ |
---|
729 | o.sort = ss; |
---|
730 | } |
---|
731 | if(store.getGroupState){ |
---|
732 | gs = store.getGroupState(); |
---|
733 | if(gs){ |
---|
734 | o.group = gs; |
---|
735 | } |
---|
736 | } |
---|
737 | } |
---|
738 | return o; |
---|
739 | }, |
---|
740 | |
---|
741 | // private |
---|
742 | afterRender : function(){ |
---|
743 | Ext.grid.GridPanel.superclass.afterRender.call(this); |
---|
744 | var v = this.view; |
---|
745 | this.on('bodyresize', v.layout, v); |
---|
746 | v.layout(true); |
---|
747 | if(this.deferRowRender){ |
---|
748 | if (!this.deferRowRenderTask){ |
---|
749 | this.deferRowRenderTask = new Ext.util.DelayedTask(v.afterRender, this.view); |
---|
750 | } |
---|
751 | this.deferRowRenderTask.delay(10); |
---|
752 | }else{ |
---|
753 | v.afterRender(); |
---|
754 | } |
---|
755 | this.viewReady = true; |
---|
756 | }, |
---|
757 | |
---|
758 | /** |
---|
759 | * <p>Reconfigures the grid to use a different Store and Column Model |
---|
760 | * and fires the 'reconfigure' event. The View will be bound to the new |
---|
761 | * objects and refreshed.</p> |
---|
762 | * <p>Be aware that upon reconfiguring a GridPanel, certain existing settings <i>may</i> become |
---|
763 | * invalidated. For example the configured {@link #autoExpandColumn} may no longer exist in the |
---|
764 | * new ColumnModel. Also, an existing {@link Ext.PagingToolbar PagingToolbar} will still be bound |
---|
765 | * to the old Store, and will need rebinding. Any {@link #plugins} might also need reconfiguring |
---|
766 | * with the new data.</p> |
---|
767 | * @param {Ext.data.Store} store The new {@link Ext.data.Store} object |
---|
768 | * @param {Ext.grid.ColumnModel} colModel The new {@link Ext.grid.ColumnModel} object |
---|
769 | */ |
---|
770 | reconfigure : function(store, colModel){ |
---|
771 | var rendered = this.rendered; |
---|
772 | if(rendered){ |
---|
773 | if(this.loadMask){ |
---|
774 | this.loadMask.destroy(); |
---|
775 | this.loadMask = new Ext.LoadMask(this.bwrap, |
---|
776 | Ext.apply({}, {store:store}, this.initialConfig.loadMask)); |
---|
777 | } |
---|
778 | } |
---|
779 | if(this.view){ |
---|
780 | this.view.initData(store, colModel); |
---|
781 | } |
---|
782 | this.store = store; |
---|
783 | this.colModel = colModel; |
---|
784 | if(rendered){ |
---|
785 | this.view.refresh(true); |
---|
786 | } |
---|
787 | this.fireEvent('reconfigure', this, store, colModel); |
---|
788 | }, |
---|
789 | |
---|
790 | // private |
---|
791 | onDestroy : function(){ |
---|
792 | if (this.deferRowRenderTask && this.deferRowRenderTask.cancel){ |
---|
793 | this.deferRowRenderTask.cancel(); |
---|
794 | } |
---|
795 | if(this.rendered){ |
---|
796 | Ext.destroy(this.view, this.loadMask); |
---|
797 | }else if(this.store && this.store.autoDestroy){ |
---|
798 | this.store.destroy(); |
---|
799 | } |
---|
800 | Ext.destroy(this.colModel, this.selModel); |
---|
801 | this.store = this.selModel = this.colModel = this.view = this.loadMask = null; |
---|
802 | Ext.grid.GridPanel.superclass.onDestroy.call(this); |
---|
803 | }, |
---|
804 | |
---|
805 | // private |
---|
806 | processEvent : function(name, e){ |
---|
807 | this.view.processEvent(name, e); |
---|
808 | }, |
---|
809 | |
---|
810 | // private |
---|
811 | onClick : function(e){ |
---|
812 | this.processEvent('click', e); |
---|
813 | }, |
---|
814 | |
---|
815 | // private |
---|
816 | onMouseDown : function(e){ |
---|
817 | this.processEvent('mousedown', e); |
---|
818 | }, |
---|
819 | |
---|
820 | // private |
---|
821 | onContextMenu : function(e, t){ |
---|
822 | this.processEvent('contextmenu', e); |
---|
823 | }, |
---|
824 | |
---|
825 | // private |
---|
826 | onDblClick : function(e){ |
---|
827 | this.processEvent('dblclick', e); |
---|
828 | }, |
---|
829 | |
---|
830 | // private |
---|
831 | walkCells : function(row, col, step, fn, scope){ |
---|
832 | var cm = this.colModel, |
---|
833 | clen = cm.getColumnCount(), |
---|
834 | ds = this.store, |
---|
835 | rlen = ds.getCount(), |
---|
836 | first = true; |
---|
837 | |
---|
838 | if(step < 0){ |
---|
839 | if(col < 0){ |
---|
840 | row--; |
---|
841 | first = false; |
---|
842 | } |
---|
843 | while(row >= 0){ |
---|
844 | if(!first){ |
---|
845 | col = clen-1; |
---|
846 | } |
---|
847 | first = false; |
---|
848 | while(col >= 0){ |
---|
849 | if(fn.call(scope || this, row, col, cm) === true){ |
---|
850 | return [row, col]; |
---|
851 | } |
---|
852 | col--; |
---|
853 | } |
---|
854 | row--; |
---|
855 | } |
---|
856 | } else { |
---|
857 | if(col >= clen){ |
---|
858 | row++; |
---|
859 | first = false; |
---|
860 | } |
---|
861 | while(row < rlen){ |
---|
862 | if(!first){ |
---|
863 | col = 0; |
---|
864 | } |
---|
865 | first = false; |
---|
866 | while(col < clen){ |
---|
867 | if(fn.call(scope || this, row, col, cm) === true){ |
---|
868 | return [row, col]; |
---|
869 | } |
---|
870 | col++; |
---|
871 | } |
---|
872 | row++; |
---|
873 | } |
---|
874 | } |
---|
875 | return null; |
---|
876 | }, |
---|
877 | |
---|
878 | /** |
---|
879 | * Returns the grid's underlying element. |
---|
880 | * @return {Element} The element |
---|
881 | */ |
---|
882 | getGridEl : function(){ |
---|
883 | return this.body; |
---|
884 | }, |
---|
885 | |
---|
886 | // private for compatibility, overridden by editor grid |
---|
887 | stopEditing : Ext.emptyFn, |
---|
888 | |
---|
889 | /** |
---|
890 | * Returns the grid's selection model configured by the <code>{@link #selModel}</code> |
---|
891 | * configuration option. If no selection model was configured, this will create |
---|
892 | * and return a {@link Ext.grid.RowSelectionModel RowSelectionModel}. |
---|
893 | * @return {SelectionModel} |
---|
894 | */ |
---|
895 | getSelectionModel : function(){ |
---|
896 | if(!this.selModel){ |
---|
897 | this.selModel = new Ext.grid.RowSelectionModel( |
---|
898 | this.disableSelection ? {selectRow: Ext.emptyFn} : null); |
---|
899 | } |
---|
900 | return this.selModel; |
---|
901 | }, |
---|
902 | |
---|
903 | /** |
---|
904 | * Returns the grid's data store. |
---|
905 | * @return {Ext.data.Store} The store |
---|
906 | */ |
---|
907 | getStore : function(){ |
---|
908 | return this.store; |
---|
909 | }, |
---|
910 | |
---|
911 | /** |
---|
912 | * Returns the grid's ColumnModel. |
---|
913 | * @return {Ext.grid.ColumnModel} The column model |
---|
914 | */ |
---|
915 | getColumnModel : function(){ |
---|
916 | return this.colModel; |
---|
917 | }, |
---|
918 | |
---|
919 | /** |
---|
920 | * Returns the grid's GridView object. |
---|
921 | * @return {Ext.grid.GridView} The grid view |
---|
922 | */ |
---|
923 | getView : function() { |
---|
924 | if (!this.view) { |
---|
925 | this.view = new Ext.grid.GridView(this.viewConfig); |
---|
926 | } |
---|
927 | |
---|
928 | return this.view; |
---|
929 | }, |
---|
930 | /** |
---|
931 | * Called to get grid's drag proxy text, by default returns this.ddText. |
---|
932 | * @return {String} The text |
---|
933 | */ |
---|
934 | getDragDropText : function(){ |
---|
935 | var count = this.selModel.getCount(); |
---|
936 | return String.format(this.ddText, count, count == 1 ? '' : 's'); |
---|
937 | } |
---|
938 | |
---|
939 | /** |
---|
940 | * @cfg {String/Number} activeItem |
---|
941 | * @hide |
---|
942 | */ |
---|
943 | /** |
---|
944 | * @cfg {Boolean} autoDestroy |
---|
945 | * @hide |
---|
946 | */ |
---|
947 | /** |
---|
948 | * @cfg {Object/String/Function} autoLoad |
---|
949 | * @hide |
---|
950 | */ |
---|
951 | /** |
---|
952 | * @cfg {Boolean} autoWidth |
---|
953 | * @hide |
---|
954 | */ |
---|
955 | /** |
---|
956 | * @cfg {Boolean/Number} bufferResize |
---|
957 | * @hide |
---|
958 | */ |
---|
959 | /** |
---|
960 | * @cfg {String} defaultType |
---|
961 | * @hide |
---|
962 | */ |
---|
963 | /** |
---|
964 | * @cfg {Object} defaults |
---|
965 | * @hide |
---|
966 | */ |
---|
967 | /** |
---|
968 | * @cfg {Boolean} hideBorders |
---|
969 | * @hide |
---|
970 | */ |
---|
971 | /** |
---|
972 | * @cfg {Mixed} items |
---|
973 | * @hide |
---|
974 | */ |
---|
975 | /** |
---|
976 | * @cfg {String} layout |
---|
977 | * @hide |
---|
978 | */ |
---|
979 | /** |
---|
980 | * @cfg {Object} layoutConfig |
---|
981 | * @hide |
---|
982 | */ |
---|
983 | /** |
---|
984 | * @cfg {Boolean} monitorResize |
---|
985 | * @hide |
---|
986 | */ |
---|
987 | /** |
---|
988 | * @property items |
---|
989 | * @hide |
---|
990 | */ |
---|
991 | /** |
---|
992 | * @method add |
---|
993 | * @hide |
---|
994 | */ |
---|
995 | /** |
---|
996 | * @method cascade |
---|
997 | * @hide |
---|
998 | */ |
---|
999 | /** |
---|
1000 | * @method doLayout |
---|
1001 | * @hide |
---|
1002 | */ |
---|
1003 | /** |
---|
1004 | * @method find |
---|
1005 | * @hide |
---|
1006 | */ |
---|
1007 | /** |
---|
1008 | * @method findBy |
---|
1009 | * @hide |
---|
1010 | */ |
---|
1011 | /** |
---|
1012 | * @method findById |
---|
1013 | * @hide |
---|
1014 | */ |
---|
1015 | /** |
---|
1016 | * @method findByType |
---|
1017 | * @hide |
---|
1018 | */ |
---|
1019 | /** |
---|
1020 | * @method getComponent |
---|
1021 | * @hide |
---|
1022 | */ |
---|
1023 | /** |
---|
1024 | * @method getLayout |
---|
1025 | * @hide |
---|
1026 | */ |
---|
1027 | /** |
---|
1028 | * @method getUpdater |
---|
1029 | * @hide |
---|
1030 | */ |
---|
1031 | /** |
---|
1032 | * @method insert |
---|
1033 | * @hide |
---|
1034 | */ |
---|
1035 | /** |
---|
1036 | * @method load |
---|
1037 | * @hide |
---|
1038 | */ |
---|
1039 | /** |
---|
1040 | * @method remove |
---|
1041 | * @hide |
---|
1042 | */ |
---|
1043 | /** |
---|
1044 | * @event add |
---|
1045 | * @hide |
---|
1046 | */ |
---|
1047 | /** |
---|
1048 | * @event afterlayout |
---|
1049 | * @hide |
---|
1050 | */ |
---|
1051 | /** |
---|
1052 | * @event beforeadd |
---|
1053 | * @hide |
---|
1054 | */ |
---|
1055 | /** |
---|
1056 | * @event beforeremove |
---|
1057 | * @hide |
---|
1058 | */ |
---|
1059 | /** |
---|
1060 | * @event remove |
---|
1061 | * @hide |
---|
1062 | */ |
---|
1063 | |
---|
1064 | |
---|
1065 | |
---|
1066 | /** |
---|
1067 | * @cfg {String} allowDomMove @hide |
---|
1068 | */ |
---|
1069 | /** |
---|
1070 | * @cfg {String} autoEl @hide |
---|
1071 | */ |
---|
1072 | /** |
---|
1073 | * @cfg {String} applyTo @hide |
---|
1074 | */ |
---|
1075 | /** |
---|
1076 | * @cfg {String} autoScroll @hide |
---|
1077 | */ |
---|
1078 | /** |
---|
1079 | * @cfg {String} bodyBorder @hide |
---|
1080 | */ |
---|
1081 | /** |
---|
1082 | * @cfg {String} bodyStyle @hide |
---|
1083 | */ |
---|
1084 | /** |
---|
1085 | * @cfg {String} contentEl @hide |
---|
1086 | */ |
---|
1087 | /** |
---|
1088 | * @cfg {String} disabledClass @hide |
---|
1089 | */ |
---|
1090 | /** |
---|
1091 | * @cfg {String} elements @hide |
---|
1092 | */ |
---|
1093 | /** |
---|
1094 | * @cfg {String} html @hide |
---|
1095 | */ |
---|
1096 | /** |
---|
1097 | * @cfg {Boolean} preventBodyReset |
---|
1098 | * @hide |
---|
1099 | */ |
---|
1100 | /** |
---|
1101 | * @property disabled |
---|
1102 | * @hide |
---|
1103 | */ |
---|
1104 | /** |
---|
1105 | * @method applyToMarkup |
---|
1106 | * @hide |
---|
1107 | */ |
---|
1108 | /** |
---|
1109 | * @method enable |
---|
1110 | * @hide |
---|
1111 | */ |
---|
1112 | /** |
---|
1113 | * @method disable |
---|
1114 | * @hide |
---|
1115 | */ |
---|
1116 | /** |
---|
1117 | * @method setDisabled |
---|
1118 | * @hide |
---|
1119 | */ |
---|
1120 | }); |
---|
1121 | Ext.reg('grid', Ext.grid.GridPanel);/** |
---|
1122 | * @class Ext.grid.PivotGrid |
---|
1123 | * @extends Ext.grid.GridPanel |
---|
1124 | * <p>The PivotGrid component enables rapid summarization of large data sets. It provides a way to reduce a large set of |
---|
1125 | * data down into a format where trends and insights become more apparent. A classic example is in sales data; a company |
---|
1126 | * will often have a record of all sales it makes for a given period - this will often encompass thousands of rows of |
---|
1127 | * data. The PivotGrid allows you to see how well each salesperson performed, which cities generate the most revenue, |
---|
1128 | * how products perform between cities and so on.</p> |
---|
1129 | * <p>A PivotGrid is composed of two axes (left and top), one {@link #measure} and one {@link #aggregator aggregation} |
---|
1130 | * function. Each axis can contain one or more {@link #dimension}, which are ordered into a hierarchy. Dimensions on the |
---|
1131 | * left axis can also specify a width. Each dimension in each axis can specify its sort ordering, defaulting to "ASC", |
---|
1132 | * and must specify one of the fields in the {@link Ext.data.Record Record} used by the PivotGrid's |
---|
1133 | * {@link Ext.data.Store Store}.</p> |
---|
1134 | <pre><code> |
---|
1135 | // This is the record representing a single sale |
---|
1136 | var SaleRecord = Ext.data.Record.create([ |
---|
1137 | {name: 'person', type: 'string'}, |
---|
1138 | {name: 'product', type: 'string'}, |
---|
1139 | {name: 'city', type: 'string'}, |
---|
1140 | {name: 'state', type: 'string'}, |
---|
1141 | {name: 'year', type: 'int'}, |
---|
1142 | {name: 'value', type: 'int'} |
---|
1143 | ]); |
---|
1144 | |
---|
1145 | // A simple store that loads SaleRecord data from a url |
---|
1146 | var myStore = new Ext.data.Store({ |
---|
1147 | url: 'data.json', |
---|
1148 | autoLoad: true, |
---|
1149 | reader: new Ext.data.JsonReader({ |
---|
1150 | root: 'rows', |
---|
1151 | idProperty: 'id' |
---|
1152 | }, SaleRecord) |
---|
1153 | }); |
---|
1154 | |
---|
1155 | // Create the PivotGrid itself, referencing the store |
---|
1156 | var pivot = new Ext.grid.PivotGrid({ |
---|
1157 | store : myStore, |
---|
1158 | aggregator: 'sum', |
---|
1159 | measure : 'value', |
---|
1160 | |
---|
1161 | leftAxis: [ |
---|
1162 | { |
---|
1163 | width: 60, |
---|
1164 | dataIndex: 'product' |
---|
1165 | }, |
---|
1166 | { |
---|
1167 | width: 120, |
---|
1168 | dataIndex: 'person', |
---|
1169 | direction: 'DESC' |
---|
1170 | } |
---|
1171 | ], |
---|
1172 | |
---|
1173 | topAxis: [ |
---|
1174 | { |
---|
1175 | dataIndex: 'year' |
---|
1176 | } |
---|
1177 | ] |
---|
1178 | }); |
---|
1179 | </code></pre> |
---|
1180 | * <p>The specified {@link #measure} is the field from SaleRecord that is extracted from each combination |
---|
1181 | * of product and person (on the left axis) and year on the top axis. There may be several SaleRecords in the |
---|
1182 | * data set that share this combination, so an array of measure fields is produced. This array is then |
---|
1183 | * aggregated using the {@link #aggregator} function.</p> |
---|
1184 | * <p>The default aggregator function is sum, which simply adds up all of the extracted measure values. Other |
---|
1185 | * built-in aggregator functions are count, avg, min and max. In addition, you can specify your own function. |
---|
1186 | * In this example we show the code used to sum the measures, but you can return any value you like. See |
---|
1187 | * {@link #aggregator} for more details.</p> |
---|
1188 | <pre><code> |
---|
1189 | new Ext.grid.PivotGrid({ |
---|
1190 | aggregator: function(records, measure) { |
---|
1191 | var length = records.length, |
---|
1192 | total = 0, |
---|
1193 | i; |
---|
1194 | |
---|
1195 | for (i = 0; i < length; i++) { |
---|
1196 | total += records[i].get(measure); |
---|
1197 | } |
---|
1198 | |
---|
1199 | return total; |
---|
1200 | }, |
---|
1201 | |
---|
1202 | renderer: function(value) { |
---|
1203 | return Math.round(value); |
---|
1204 | }, |
---|
1205 | |
---|
1206 | //your normal config here |
---|
1207 | }); |
---|
1208 | </code></pre> |
---|
1209 | * <p><u>Renderers</u></p> |
---|
1210 | * <p>PivotGrid optionally accepts a {@link #renderer} function which can modify the data in each cell before it |
---|
1211 | * is rendered. The renderer is passed the value that would usually be placed in the cell and is expected to return |
---|
1212 | * the new value. For example let's imagine we had height data expressed as a decimal - here's how we might use a |
---|
1213 | * renderer to display the data in feet and inches notation:</p> |
---|
1214 | <pre><code> |
---|
1215 | new Ext.grid.PivotGrid({ |
---|
1216 | //in each case the value is a decimal number of feet |
---|
1217 | renderer : function(value) { |
---|
1218 | var feet = Math.floor(value), |
---|
1219 | inches = Math.round((value - feet) * 12); |
---|
1220 | |
---|
1221 | return String.format("{0}' {1}\"", feet, inches); |
---|
1222 | }, |
---|
1223 | //normal config here |
---|
1224 | }); |
---|
1225 | </code></pre> |
---|
1226 | * <p><u>Reconfiguring</u></p> |
---|
1227 | * <p>All aspects PivotGrid's configuration can be updated at runtime. It is easy to change the {@link #setMeasure measure}, |
---|
1228 | * {@link #setAggregator aggregation function}, {@link #setLeftAxis left} and {@link #setTopAxis top} axes and refresh the grid.</p> |
---|
1229 | * <p>In this case we reconfigure the PivotGrid to have city and year as the top axis dimensions, rendering the average sale |
---|
1230 | * value into the cells:</p> |
---|
1231 | <pre><code> |
---|
1232 | //the left axis can also be changed |
---|
1233 | pivot.topAxis.setDimensions([ |
---|
1234 | {dataIndex: 'city', direction: 'DESC'}, |
---|
1235 | {dataIndex: 'year', direction: 'ASC'} |
---|
1236 | ]); |
---|
1237 | |
---|
1238 | pivot.setMeasure('value'); |
---|
1239 | pivot.setAggregator('avg'); |
---|
1240 | |
---|
1241 | pivot.view.refresh(true); |
---|
1242 | </code></pre> |
---|
1243 | * <p>See the {@link Ext.grid.PivotAxis PivotAxis} documentation for further detail on reconfiguring axes.</p> |
---|
1244 | */ |
---|
1245 | Ext.grid.PivotGrid = Ext.extend(Ext.grid.GridPanel, { |
---|
1246 | |
---|
1247 | /** |
---|
1248 | * @cfg {String|Function} aggregator The aggregation function to use to combine the measures extracted |
---|
1249 | * for each dimension combination. Can be any of the built-in aggregators (sum, count, avg, min, max). |
---|
1250 | * Can also be a function which accepts two arguments (an array of Records to aggregate, and the measure |
---|
1251 | * to aggregate them on) and should return a String. |
---|
1252 | */ |
---|
1253 | aggregator: 'sum', |
---|
1254 | |
---|
1255 | /** |
---|
1256 | * @cfg {Function} renderer Optional renderer to pass values through before they are rendered to the dom. This |
---|
1257 | * gives an opportunity to modify cell contents after the value has been computed. |
---|
1258 | */ |
---|
1259 | renderer: undefined, |
---|
1260 | |
---|
1261 | /** |
---|
1262 | * @cfg {String} measure The field to extract from each Record when pivoting around the two axes. See the class |
---|
1263 | * introduction docs for usage |
---|
1264 | */ |
---|
1265 | |
---|
1266 | /** |
---|
1267 | * @cfg {Array|Ext.grid.PivotAxis} leftAxis Either and array of {@link #dimension} to use on the left axis, or |
---|
1268 | * a {@link Ext.grid.PivotAxis} instance. If an array is passed, it is turned into a PivotAxis internally. |
---|
1269 | */ |
---|
1270 | |
---|
1271 | /** |
---|
1272 | * @cfg {Array|Ext.grid.PivotAxis} topAxis Either and array of {@link #dimension} to use on the top axis, or |
---|
1273 | * a {@link Ext.grid.PivotAxis} instance. If an array is passed, it is turned into a PivotAxis internally. |
---|
1274 | */ |
---|
1275 | |
---|
1276 | //inherit docs |
---|
1277 | initComponent: function() { |
---|
1278 | Ext.grid.PivotGrid.superclass.initComponent.apply(this, arguments); |
---|
1279 | |
---|
1280 | this.initAxes(); |
---|
1281 | |
---|
1282 | //no resizing of columns is allowed yet in PivotGrid |
---|
1283 | this.enableColumnResize = false; |
---|
1284 | |
---|
1285 | this.viewConfig = Ext.apply(this.viewConfig || {}, { |
---|
1286 | forceFit: true |
---|
1287 | }); |
---|
1288 | |
---|
1289 | //TODO: dummy col model that is never used - GridView is too tightly integrated with ColumnModel |
---|
1290 | //in 3.x to remove this altogether. |
---|
1291 | this.colModel = new Ext.grid.ColumnModel({}); |
---|
1292 | }, |
---|
1293 | |
---|
1294 | /** |
---|
1295 | * Returns the function currently used to aggregate the records in each Pivot cell |
---|
1296 | * @return {Function} The current aggregator function |
---|
1297 | */ |
---|
1298 | getAggregator: function() { |
---|
1299 | if (typeof this.aggregator == 'string') { |
---|
1300 | return Ext.grid.PivotAggregatorMgr.types[this.aggregator]; |
---|
1301 | } else { |
---|
1302 | return this.aggregator; |
---|
1303 | } |
---|
1304 | }, |
---|
1305 | |
---|
1306 | /** |
---|
1307 | * Sets the function to use when aggregating data for each cell. |
---|
1308 | * @param {String|Function} aggregator The new aggregator function or named function string |
---|
1309 | */ |
---|
1310 | setAggregator: function(aggregator) { |
---|
1311 | this.aggregator = aggregator; |
---|
1312 | }, |
---|
1313 | |
---|
1314 | /** |
---|
1315 | * Sets the field name to use as the Measure in this Pivot Grid |
---|
1316 | * @param {String} measure The field to make the measure |
---|
1317 | */ |
---|
1318 | setMeasure: function(measure) { |
---|
1319 | this.measure = measure; |
---|
1320 | }, |
---|
1321 | |
---|
1322 | /** |
---|
1323 | * Sets the left axis of this pivot grid. Optionally refreshes the grid afterwards. |
---|
1324 | * @param {Ext.grid.PivotAxis} axis The pivot axis |
---|
1325 | * @param {Boolean} refresh True to immediately refresh the grid and its axes (defaults to false) |
---|
1326 | */ |
---|
1327 | setLeftAxis: function(axis, refresh) { |
---|
1328 | /** |
---|
1329 | * The configured {@link Ext.grid.PivotAxis} used as the left Axis for this Pivot Grid |
---|
1330 | * @property leftAxis |
---|
1331 | * @type Ext.grid.PivotAxis |
---|
1332 | */ |
---|
1333 | this.leftAxis = axis; |
---|
1334 | |
---|
1335 | if (refresh) { |
---|
1336 | this.view.refresh(); |
---|
1337 | } |
---|
1338 | }, |
---|
1339 | |
---|
1340 | /** |
---|
1341 | * Sets the top axis of this pivot grid. Optionally refreshes the grid afterwards. |
---|
1342 | * @param {Ext.grid.PivotAxis} axis The pivot axis |
---|
1343 | * @param {Boolean} refresh True to immediately refresh the grid and its axes (defaults to false) |
---|
1344 | */ |
---|
1345 | setTopAxis: function(axis, refresh) { |
---|
1346 | /** |
---|
1347 | * The configured {@link Ext.grid.PivotAxis} used as the top Axis for this Pivot Grid |
---|
1348 | * @property topAxis |
---|
1349 | * @type Ext.grid.PivotAxis |
---|
1350 | */ |
---|
1351 | this.topAxis = axis; |
---|
1352 | |
---|
1353 | if (refresh) { |
---|
1354 | this.view.refresh(); |
---|
1355 | } |
---|
1356 | }, |
---|
1357 | |
---|
1358 | /** |
---|
1359 | * @private |
---|
1360 | * Creates the top and left axes. Should usually only need to be called once from initComponent |
---|
1361 | */ |
---|
1362 | initAxes: function() { |
---|
1363 | var PivotAxis = Ext.grid.PivotAxis; |
---|
1364 | |
---|
1365 | if (!(this.leftAxis instanceof PivotAxis)) { |
---|
1366 | this.setLeftAxis(new PivotAxis({ |
---|
1367 | orientation: 'vertical', |
---|
1368 | dimensions : this.leftAxis || [], |
---|
1369 | store : this.store |
---|
1370 | })); |
---|
1371 | }; |
---|
1372 | |
---|
1373 | if (!(this.topAxis instanceof PivotAxis)) { |
---|
1374 | this.setTopAxis(new PivotAxis({ |
---|
1375 | orientation: 'horizontal', |
---|
1376 | dimensions : this.topAxis || [], |
---|
1377 | store : this.store |
---|
1378 | })); |
---|
1379 | }; |
---|
1380 | }, |
---|
1381 | |
---|
1382 | /** |
---|
1383 | * @private |
---|
1384 | * @return {Array} 2-dimensional array of cell data |
---|
1385 | */ |
---|
1386 | extractData: function() { |
---|
1387 | var records = this.store.data.items, |
---|
1388 | recCount = records.length, |
---|
1389 | cells = [], |
---|
1390 | record, i, j, k; |
---|
1391 | |
---|
1392 | if (recCount == 0) { |
---|
1393 | return []; |
---|
1394 | } |
---|
1395 | |
---|
1396 | var leftTuples = this.leftAxis.getTuples(), |
---|
1397 | leftCount = leftTuples.length, |
---|
1398 | topTuples = this.topAxis.getTuples(), |
---|
1399 | topCount = topTuples.length, |
---|
1400 | aggregator = this.getAggregator(); |
---|
1401 | |
---|
1402 | for (i = 0; i < recCount; i++) { |
---|
1403 | record = records[i]; |
---|
1404 | |
---|
1405 | for (j = 0; j < leftCount; j++) { |
---|
1406 | cells[j] = cells[j] || []; |
---|
1407 | |
---|
1408 | if (leftTuples[j].matcher(record) === true) { |
---|
1409 | for (k = 0; k < topCount; k++) { |
---|
1410 | cells[j][k] = cells[j][k] || []; |
---|
1411 | |
---|
1412 | if (topTuples[k].matcher(record)) { |
---|
1413 | cells[j][k].push(record); |
---|
1414 | } |
---|
1415 | } |
---|
1416 | } |
---|
1417 | } |
---|
1418 | } |
---|
1419 | |
---|
1420 | var rowCount = cells.length, |
---|
1421 | colCount, row; |
---|
1422 | |
---|
1423 | for (i = 0; i < rowCount; i++) { |
---|
1424 | row = cells[i]; |
---|
1425 | colCount = row.length; |
---|
1426 | |
---|
1427 | for (j = 0; j < colCount; j++) { |
---|
1428 | cells[i][j] = aggregator(cells[i][j], this.measure); |
---|
1429 | } |
---|
1430 | } |
---|
1431 | |
---|
1432 | return cells; |
---|
1433 | }, |
---|
1434 | |
---|
1435 | /** |
---|
1436 | * Returns the grid's GridView object. |
---|
1437 | * @return {Ext.grid.PivotGridView} The grid view |
---|
1438 | */ |
---|
1439 | getView: function() { |
---|
1440 | if (!this.view) { |
---|
1441 | this.view = new Ext.grid.PivotGridView(this.viewConfig); |
---|
1442 | } |
---|
1443 | |
---|
1444 | return this.view; |
---|
1445 | } |
---|
1446 | }); |
---|
1447 | |
---|
1448 | Ext.reg('pivotgrid', Ext.grid.PivotGrid); |
---|
1449 | |
---|
1450 | |
---|
1451 | Ext.grid.PivotAggregatorMgr = new Ext.AbstractManager(); |
---|
1452 | |
---|
1453 | Ext.grid.PivotAggregatorMgr.registerType('sum', function(records, measure) { |
---|
1454 | var length = records.length, |
---|
1455 | total = 0, |
---|
1456 | i; |
---|
1457 | |
---|
1458 | for (i = 0; i < length; i++) { |
---|
1459 | total += records[i].get(measure); |
---|
1460 | } |
---|
1461 | |
---|
1462 | return total; |
---|
1463 | }); |
---|
1464 | |
---|
1465 | Ext.grid.PivotAggregatorMgr.registerType('avg', function(records, measure) { |
---|
1466 | var length = records.length, |
---|
1467 | total = 0, |
---|
1468 | i; |
---|
1469 | |
---|
1470 | for (i = 0; i < length; i++) { |
---|
1471 | total += records[i].get(measure); |
---|
1472 | } |
---|
1473 | |
---|
1474 | return (total / length) || 'n/a'; |
---|
1475 | }); |
---|
1476 | |
---|
1477 | Ext.grid.PivotAggregatorMgr.registerType('min', function(records, measure) { |
---|
1478 | var data = [], |
---|
1479 | length = records.length, |
---|
1480 | i; |
---|
1481 | |
---|
1482 | for (i = 0; i < length; i++) { |
---|
1483 | data.push(records[i].get(measure)); |
---|
1484 | } |
---|
1485 | |
---|
1486 | return Math.min.apply(this, data) || 'n/a'; |
---|
1487 | }); |
---|
1488 | |
---|
1489 | Ext.grid.PivotAggregatorMgr.registerType('max', function(records, measure) { |
---|
1490 | var data = [], |
---|
1491 | length = records.length, |
---|
1492 | i; |
---|
1493 | |
---|
1494 | for (i = 0; i < length; i++) { |
---|
1495 | data.push(records[i].get(measure)); |
---|
1496 | } |
---|
1497 | |
---|
1498 | return Math.max.apply(this, data) || 'n/a'; |
---|
1499 | }); |
---|
1500 | |
---|
1501 | Ext.grid.PivotAggregatorMgr.registerType('count', function(records, measure) { |
---|
1502 | return records.length; |
---|
1503 | });/** |
---|
1504 | * @class Ext.grid.GridView |
---|
1505 | * @extends Ext.util.Observable |
---|
1506 | * <p>This class encapsulates the user interface of an {@link Ext.grid.GridPanel}. |
---|
1507 | * Methods of this class may be used to access user interface elements to enable |
---|
1508 | * special display effects. Do not change the DOM structure of the user interface.</p> |
---|
1509 | * <p>This class does not provide ways to manipulate the underlying data. The data |
---|
1510 | * model of a Grid is held in an {@link Ext.data.Store}.</p> |
---|
1511 | * @constructor |
---|
1512 | * @param {Object} config |
---|
1513 | */ |
---|
1514 | Ext.grid.GridView = Ext.extend(Ext.util.Observable, { |
---|
1515 | /** |
---|
1516 | * Override this function to apply custom CSS classes to rows during rendering. You can also supply custom |
---|
1517 | * parameters to the row template for the current row to customize how it is rendered using the <b>rowParams</b> |
---|
1518 | * parameter. This function should return the CSS class name (or empty string '' for none) that will be added |
---|
1519 | * to the row's wrapping div. To apply multiple class names, simply return them space-delimited within the string |
---|
1520 | * (e.g., 'my-class another-class'). Example usage: |
---|
1521 | <pre><code> |
---|
1522 | viewConfig: { |
---|
1523 | forceFit: true, |
---|
1524 | showPreview: true, // custom property |
---|
1525 | enableRowBody: true, // required to create a second, full-width row to show expanded Record data |
---|
1526 | getRowClass: function(record, rowIndex, rp, ds){ // rp = rowParams |
---|
1527 | if(this.showPreview){ |
---|
1528 | rp.body = '<p>'+record.data.excerpt+'</p>'; |
---|
1529 | return 'x-grid3-row-expanded'; |
---|
1530 | } |
---|
1531 | return 'x-grid3-row-collapsed'; |
---|
1532 | } |
---|
1533 | }, |
---|
1534 | </code></pre> |
---|
1535 | * @param {Record} record The {@link Ext.data.Record} corresponding to the current row. |
---|
1536 | * @param {Number} index The row index. |
---|
1537 | * @param {Object} rowParams A config object that is passed to the row template during rendering that allows |
---|
1538 | * customization of various aspects of a grid row. |
---|
1539 | * <p>If {@link #enableRowBody} is configured <b><tt></tt>true</b>, then the following properties may be set |
---|
1540 | * by this function, and will be used to render a full-width expansion row below each grid row:</p> |
---|
1541 | * <ul> |
---|
1542 | * <li><code>body</code> : String <div class="sub-desc">An HTML fragment to be used as the expansion row's body content (defaults to '').</div></li> |
---|
1543 | * <li><code>bodyStyle</code> : String <div class="sub-desc">A CSS style specification that will be applied to the expansion row's <tr> element. (defaults to '').</div></li> |
---|
1544 | * </ul> |
---|
1545 | * The following property will be passed in, and may be appended to: |
---|
1546 | * <ul> |
---|
1547 | * <li><code>tstyle</code> : String <div class="sub-desc">A CSS style specification that willl be applied to the <table> element which encapsulates |
---|
1548 | * both the standard grid row, and any expansion row.</div></li> |
---|
1549 | * </ul> |
---|
1550 | * @param {Store} store The {@link Ext.data.Store} this grid is bound to |
---|
1551 | * @method getRowClass |
---|
1552 | * @return {String} a CSS class name to add to the row. |
---|
1553 | */ |
---|
1554 | |
---|
1555 | /** |
---|
1556 | * @cfg {Boolean} enableRowBody True to add a second TR element per row that can be used to provide a row body |
---|
1557 | * that spans beneath the data row. Use the {@link #getRowClass} method's rowParams config to customize the row body. |
---|
1558 | */ |
---|
1559 | |
---|
1560 | /** |
---|
1561 | * @cfg {String} emptyText Default text (html tags are accepted) to display in the grid body when no rows |
---|
1562 | * are available (defaults to ''). This value will be used to update the <tt>{@link #mainBody}</tt>: |
---|
1563 | <pre><code> |
---|
1564 | this.mainBody.update('<div class="x-grid-empty">' + this.emptyText + '</div>'); |
---|
1565 | </code></pre> |
---|
1566 | */ |
---|
1567 | |
---|
1568 | /** |
---|
1569 | * @cfg {Boolean} headersDisabled True to disable the grid column headers (defaults to <tt>false</tt>). |
---|
1570 | * Use the {@link Ext.grid.ColumnModel ColumnModel} <tt>{@link Ext.grid.ColumnModel#menuDisabled menuDisabled}</tt> |
---|
1571 | * config to disable the <i>menu</i> for individual columns. While this config is true the |
---|
1572 | * following will be disabled:<div class="mdetail-params"><ul> |
---|
1573 | * <li>clicking on header to sort</li> |
---|
1574 | * <li>the trigger to reveal the menu.</li> |
---|
1575 | * </ul></div> |
---|
1576 | */ |
---|
1577 | |
---|
1578 | /** |
---|
1579 | * <p>A customized implementation of a {@link Ext.dd.DragZone DragZone} which provides default implementations |
---|
1580 | * of the template methods of DragZone to enable dragging of the selected rows of a GridPanel. |
---|
1581 | * See {@link Ext.grid.GridDragZone} for details.</p> |
---|
1582 | * <p>This will <b>only</b> be present:<div class="mdetail-params"><ul> |
---|
1583 | * <li><i>if</i> the owning GridPanel was configured with {@link Ext.grid.GridPanel#enableDragDrop enableDragDrop}: <tt>true</tt>.</li> |
---|
1584 | * <li><i>after</i> the owning GridPanel has been rendered.</li> |
---|
1585 | * </ul></div> |
---|
1586 | * @property dragZone |
---|
1587 | * @type {Ext.grid.GridDragZone} |
---|
1588 | */ |
---|
1589 | |
---|
1590 | /** |
---|
1591 | * @cfg {Boolean} deferEmptyText True to defer <tt>{@link #emptyText}</tt> being applied until the store's |
---|
1592 | * first load (defaults to <tt>true</tt>). |
---|
1593 | */ |
---|
1594 | deferEmptyText : true, |
---|
1595 | |
---|
1596 | /** |
---|
1597 | * @cfg {Number} scrollOffset The amount of space to reserve for the vertical scrollbar |
---|
1598 | * (defaults to <tt>undefined</tt>). If an explicit value isn't specified, this will be automatically |
---|
1599 | * calculated. |
---|
1600 | */ |
---|
1601 | scrollOffset : undefined, |
---|
1602 | |
---|
1603 | /** |
---|
1604 | * @cfg {Boolean} autoFill |
---|
1605 | * Defaults to <tt>false</tt>. Specify <tt>true</tt> to have the column widths re-proportioned |
---|
1606 | * when the grid is <b>initially rendered</b>. The |
---|
1607 | * {@link Ext.grid.Column#width initially configured width}</tt> of each column will be adjusted |
---|
1608 | * to fit the grid width and prevent horizontal scrolling. If columns are later resized (manually |
---|
1609 | * or programmatically), the other columns in the grid will <b>not</b> be resized to fit the grid width. |
---|
1610 | * See <tt>{@link #forceFit}</tt> also. |
---|
1611 | */ |
---|
1612 | autoFill : false, |
---|
1613 | |
---|
1614 | /** |
---|
1615 | * @cfg {Boolean} forceFit |
---|
1616 | * <p>Defaults to <tt>false</tt>. Specify <tt>true</tt> to have the column widths re-proportioned |
---|
1617 | * at <b>all times</b>.</p> |
---|
1618 | * <p>The {@link Ext.grid.Column#width initially configured width}</tt> of each |
---|
1619 | * column will be adjusted to fit the grid width and prevent horizontal scrolling. If columns are |
---|
1620 | * later resized (manually or programmatically), the other columns in the grid <b>will</b> be resized |
---|
1621 | * to fit the grid width.</p> |
---|
1622 | * <p>Columns which are configured with <code>fixed: true</code> are omitted from being resized.</p> |
---|
1623 | * <p>See <tt>{@link #autoFill}</tt>.</p> |
---|
1624 | */ |
---|
1625 | forceFit : false, |
---|
1626 | |
---|
1627 | /** |
---|
1628 | * @cfg {Array} sortClasses The CSS classes applied to a header when it is sorted. (defaults to <tt>['sort-asc', 'sort-desc']</tt>) |
---|
1629 | */ |
---|
1630 | sortClasses : ['sort-asc', 'sort-desc'], |
---|
1631 | |
---|
1632 | /** |
---|
1633 | * @cfg {String} sortAscText The text displayed in the 'Sort Ascending' menu item (defaults to <tt>'Sort Ascending'</tt>) |
---|
1634 | */ |
---|
1635 | sortAscText : 'Sort Ascending', |
---|
1636 | |
---|
1637 | /** |
---|
1638 | * @cfg {String} sortDescText The text displayed in the 'Sort Descending' menu item (defaults to <tt>'Sort Descending'</tt>) |
---|
1639 | */ |
---|
1640 | sortDescText : 'Sort Descending', |
---|
1641 | |
---|
1642 | /** |
---|
1643 | * @cfg {String} columnsText The text displayed in the 'Columns' menu item (defaults to <tt>'Columns'</tt>) |
---|
1644 | */ |
---|
1645 | columnsText : 'Columns', |
---|
1646 | |
---|
1647 | /** |
---|
1648 | * @cfg {String} selectedRowClass The CSS class applied to a selected row (defaults to <tt>'x-grid3-row-selected'</tt>). An |
---|
1649 | * example overriding the default styling: |
---|
1650 | <pre><code> |
---|
1651 | .x-grid3-row-selected {background-color: yellow;} |
---|
1652 | </code></pre> |
---|
1653 | * Note that this only controls the row, and will not do anything for the text inside it. To style inner |
---|
1654 | * facets (like text) use something like: |
---|
1655 | <pre><code> |
---|
1656 | .x-grid3-row-selected .x-grid3-cell-inner { |
---|
1657 | color: #FFCC00; |
---|
1658 | } |
---|
1659 | </code></pre> |
---|
1660 | * @type String |
---|
1661 | */ |
---|
1662 | selectedRowClass : 'x-grid3-row-selected', |
---|
1663 | |
---|
1664 | // private |
---|
1665 | borderWidth : 2, |
---|
1666 | tdClass : 'x-grid3-cell', |
---|
1667 | hdCls : 'x-grid3-hd', |
---|
1668 | |
---|
1669 | |
---|
1670 | /** |
---|
1671 | * @cfg {Boolean} markDirty True to show the dirty cell indicator when a cell has been modified. Defaults to <tt>true</tt>. |
---|
1672 | */ |
---|
1673 | markDirty : true, |
---|
1674 | |
---|
1675 | /** |
---|
1676 | * @cfg {Number} cellSelectorDepth The number of levels to search for cells in event delegation (defaults to <tt>4</tt>) |
---|
1677 | */ |
---|
1678 | cellSelectorDepth : 4, |
---|
1679 | |
---|
1680 | /** |
---|
1681 | * @cfg {Number} rowSelectorDepth The number of levels to search for rows in event delegation (defaults to <tt>10</tt>) |
---|
1682 | */ |
---|
1683 | rowSelectorDepth : 10, |
---|
1684 | |
---|
1685 | /** |
---|
1686 | * @cfg {Number} rowBodySelectorDepth The number of levels to search for row bodies in event delegation (defaults to <tt>10</tt>) |
---|
1687 | */ |
---|
1688 | rowBodySelectorDepth : 10, |
---|
1689 | |
---|
1690 | /** |
---|
1691 | * @cfg {String} cellSelector The selector used to find cells internally (defaults to <tt>'td.x-grid3-cell'</tt>) |
---|
1692 | */ |
---|
1693 | cellSelector : 'td.x-grid3-cell', |
---|
1694 | |
---|
1695 | /** |
---|
1696 | * @cfg {String} rowSelector The selector used to find rows internally (defaults to <tt>'div.x-grid3-row'</tt>) |
---|
1697 | */ |
---|
1698 | rowSelector : 'div.x-grid3-row', |
---|
1699 | |
---|
1700 | /** |
---|
1701 | * @cfg {String} rowBodySelector The selector used to find row bodies internally (defaults to <tt>'div.x-grid3-row'</tt>) |
---|
1702 | */ |
---|
1703 | rowBodySelector : 'div.x-grid3-row-body', |
---|
1704 | |
---|
1705 | // private |
---|
1706 | firstRowCls: 'x-grid3-row-first', |
---|
1707 | lastRowCls: 'x-grid3-row-last', |
---|
1708 | rowClsRe: /(?:^|\s+)x-grid3-row-(first|last|alt)(?:\s+|$)/g, |
---|
1709 | |
---|
1710 | /** |
---|
1711 | * @cfg {String} headerMenuOpenCls The CSS class to add to the header cell when its menu is visible. Defaults to 'x-grid3-hd-menu-open' |
---|
1712 | */ |
---|
1713 | headerMenuOpenCls: 'x-grid3-hd-menu-open', |
---|
1714 | |
---|
1715 | /** |
---|
1716 | * @cfg {String} rowOverCls The CSS class added to each row when it is hovered over. Defaults to 'x-grid3-row-over' |
---|
1717 | */ |
---|
1718 | rowOverCls: 'x-grid3-row-over', |
---|
1719 | |
---|
1720 | constructor : function(config) { |
---|
1721 | Ext.apply(this, config); |
---|
1722 | |
---|
1723 | // These events are only used internally by the grid components |
---|
1724 | this.addEvents( |
---|
1725 | /** |
---|
1726 | * @event beforerowremoved |
---|
1727 | * Internal UI Event. Fired before a row is removed. |
---|
1728 | * @param {Ext.grid.GridView} view |
---|
1729 | * @param {Number} rowIndex The index of the row to be removed. |
---|
1730 | * @param {Ext.data.Record} record The Record to be removed |
---|
1731 | */ |
---|
1732 | 'beforerowremoved', |
---|
1733 | |
---|
1734 | /** |
---|
1735 | * @event beforerowsinserted |
---|
1736 | * Internal UI Event. Fired before rows are inserted. |
---|
1737 | * @param {Ext.grid.GridView} view |
---|
1738 | * @param {Number} firstRow The index of the first row to be inserted. |
---|
1739 | * @param {Number} lastRow The index of the last row to be inserted. |
---|
1740 | */ |
---|
1741 | 'beforerowsinserted', |
---|
1742 | |
---|
1743 | /** |
---|
1744 | * @event beforerefresh |
---|
1745 | * Internal UI Event. Fired before the view is refreshed. |
---|
1746 | * @param {Ext.grid.GridView} view |
---|
1747 | */ |
---|
1748 | 'beforerefresh', |
---|
1749 | |
---|
1750 | /** |
---|
1751 | * @event rowremoved |
---|
1752 | * Internal UI Event. Fired after a row is removed. |
---|
1753 | * @param {Ext.grid.GridView} view |
---|
1754 | * @param {Number} rowIndex The index of the row that was removed. |
---|
1755 | * @param {Ext.data.Record} record The Record that was removed |
---|
1756 | */ |
---|
1757 | 'rowremoved', |
---|
1758 | |
---|
1759 | /** |
---|
1760 | * @event rowsinserted |
---|
1761 | * Internal UI Event. Fired after rows are inserted. |
---|
1762 | * @param {Ext.grid.GridView} view |
---|
1763 | * @param {Number} firstRow The index of the first inserted. |
---|
1764 | * @param {Number} lastRow The index of the last row inserted. |
---|
1765 | */ |
---|
1766 | 'rowsinserted', |
---|
1767 | |
---|
1768 | /** |
---|
1769 | * @event rowupdated |
---|
1770 | * Internal UI Event. Fired after a row has been updated. |
---|
1771 | * @param {Ext.grid.GridView} view |
---|
1772 | * @param {Number} firstRow The index of the row updated. |
---|
1773 | * @param {Ext.data.record} record The Record backing the row updated. |
---|
1774 | */ |
---|
1775 | 'rowupdated', |
---|
1776 | |
---|
1777 | /** |
---|
1778 | * @event refresh |
---|
1779 | * Internal UI Event. Fired after the GridView's body has been refreshed. |
---|
1780 | * @param {Ext.grid.GridView} view |
---|
1781 | */ |
---|
1782 | 'refresh' |
---|
1783 | ); |
---|
1784 | |
---|
1785 | Ext.grid.GridView.superclass.constructor.call(this); |
---|
1786 | }, |
---|
1787 | |
---|
1788 | /* -------------------------------- UI Specific ----------------------------- */ |
---|
1789 | |
---|
1790 | /** |
---|
1791 | * The master template to use when rendering the GridView. Has a default template |
---|
1792 | * @property Ext.Template |
---|
1793 | * @type masterTpl |
---|
1794 | */ |
---|
1795 | masterTpl: new Ext.Template( |
---|
1796 | '<div class="x-grid3" hidefocus="true">', |
---|
1797 | '<div class="x-grid3-viewport">', |
---|
1798 | '<div class="x-grid3-header">', |
---|
1799 | '<div class="x-grid3-header-inner">', |
---|
1800 | '<div class="x-grid3-header-offset" style="{ostyle}">{header}</div>', |
---|
1801 | '</div>', |
---|
1802 | '<div class="x-clear"></div>', |
---|
1803 | '</div>', |
---|
1804 | '<div class="x-grid3-scroller">', |
---|
1805 | '<div class="x-grid3-body" style="{bstyle}">{body}</div>', |
---|
1806 | '<a href="#" class="x-grid3-focus" tabIndex="-1"></a>', |
---|
1807 | '</div>', |
---|
1808 | '</div>', |
---|
1809 | '<div class="x-grid3-resize-marker"> </div>', |
---|
1810 | '<div class="x-grid3-resize-proxy"> </div>', |
---|
1811 | '</div>' |
---|
1812 | ), |
---|
1813 | |
---|
1814 | /** |
---|
1815 | * The template to use when rendering headers. Has a default template |
---|
1816 | * @property headerTpl |
---|
1817 | * @type Ext.Template |
---|
1818 | */ |
---|
1819 | headerTpl: new Ext.Template( |
---|
1820 | '<table border="0" cellspacing="0" cellpadding="0" style="{tstyle}">', |
---|
1821 | '<thead>', |
---|
1822 | '<tr class="x-grid3-hd-row">{cells}</tr>', |
---|
1823 | '</thead>', |
---|
1824 | '</table>' |
---|
1825 | ), |
---|
1826 | |
---|
1827 | /** |
---|
1828 | * The template to use when rendering the body. Has a default template |
---|
1829 | * @property bodyTpl |
---|
1830 | * @type Ext.Template |
---|
1831 | */ |
---|
1832 | bodyTpl: new Ext.Template('{rows}'), |
---|
1833 | |
---|
1834 | /** |
---|
1835 | * The template to use to render each cell. Has a default template |
---|
1836 | * @property cellTpl |
---|
1837 | * @type Ext.Template |
---|
1838 | */ |
---|
1839 | cellTpl: new Ext.Template( |
---|
1840 | '<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} {css}" style="{style}" tabIndex="0" {cellAttr}>', |
---|
1841 | '<div class="x-grid3-cell-inner x-grid3-col-{id}" unselectable="on" {attr}>{value}</div>', |
---|
1842 | '</td>' |
---|
1843 | ), |
---|
1844 | |
---|
1845 | /** |
---|
1846 | * @private |
---|
1847 | * Provides default templates if they are not given for this particular instance. Most of the templates are defined on |
---|
1848 | * the prototype, the ones defined inside this function are done so because they are based on Grid or GridView configuration |
---|
1849 | */ |
---|
1850 | initTemplates : function() { |
---|
1851 | var templates = this.templates || {}, |
---|
1852 | template, name, |
---|
1853 | |
---|
1854 | headerCellTpl = new Ext.Template( |
---|
1855 | '<td class="x-grid3-hd x-grid3-cell x-grid3-td-{id} {css}" style="{style}">', |
---|
1856 | '<div {tooltip} {attr} class="x-grid3-hd-inner x-grid3-hd-{id}" unselectable="on" style="{istyle}">', |
---|
1857 | this.grid.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '', |
---|
1858 | '{value}', |
---|
1859 | '<img alt="" class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />', |
---|
1860 | '</div>', |
---|
1861 | '</td>' |
---|
1862 | ), |
---|
1863 | |
---|
1864 | rowBodyText = [ |
---|
1865 | '<tr class="x-grid3-row-body-tr" style="{bodyStyle}">', |
---|
1866 | '<td colspan="{cols}" class="x-grid3-body-cell" tabIndex="0" hidefocus="on">', |
---|
1867 | '<div class="x-grid3-row-body">{body}</div>', |
---|
1868 | '</td>', |
---|
1869 | '</tr>' |
---|
1870 | ].join(""), |
---|
1871 | |
---|
1872 | innerText = [ |
---|
1873 | '<table class="x-grid3-row-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">', |
---|
1874 | '<tbody>', |
---|
1875 | '<tr>{cells}</tr>', |
---|
1876 | this.enableRowBody ? rowBodyText : '', |
---|
1877 | '</tbody>', |
---|
1878 | '</table>' |
---|
1879 | ].join(""); |
---|
1880 | |
---|
1881 | Ext.applyIf(templates, { |
---|
1882 | hcell : headerCellTpl, |
---|
1883 | cell : this.cellTpl, |
---|
1884 | body : this.bodyTpl, |
---|
1885 | header : this.headerTpl, |
---|
1886 | master : this.masterTpl, |
---|
1887 | row : new Ext.Template('<div class="x-grid3-row {alt}" style="{tstyle}">' + innerText + '</div>'), |
---|
1888 | rowInner: new Ext.Template(innerText) |
---|
1889 | }); |
---|
1890 | |
---|
1891 | for (name in templates) { |
---|
1892 | template = templates[name]; |
---|
1893 | |
---|
1894 | if (template && Ext.isFunction(template.compile) && !template.compiled) { |
---|
1895 | template.disableFormats = true; |
---|
1896 | template.compile(); |
---|
1897 | } |
---|
1898 | } |
---|
1899 | |
---|
1900 | this.templates = templates; |
---|
1901 | this.colRe = new RegExp('x-grid3-td-([^\\s]+)', ''); |
---|
1902 | }, |
---|
1903 | |
---|
1904 | /** |
---|
1905 | * @private |
---|
1906 | * Each GridView has its own private flyweight, accessed through this method |
---|
1907 | */ |
---|
1908 | fly : function(el) { |
---|
1909 | if (!this._flyweight) { |
---|
1910 | this._flyweight = new Ext.Element.Flyweight(document.body); |
---|
1911 | } |
---|
1912 | this._flyweight.dom = el; |
---|
1913 | return this._flyweight; |
---|
1914 | }, |
---|
1915 | |
---|
1916 | // private |
---|
1917 | getEditorParent : function() { |
---|
1918 | return this.scroller.dom; |
---|
1919 | }, |
---|
1920 | |
---|
1921 | /** |
---|
1922 | * @private |
---|
1923 | * Finds and stores references to important elements |
---|
1924 | */ |
---|
1925 | initElements : function() { |
---|
1926 | var Element = Ext.Element, |
---|
1927 | el = Ext.get(this.grid.getGridEl().dom.firstChild), |
---|
1928 | mainWrap = new Element(el.child('div.x-grid3-viewport')), |
---|
1929 | mainHd = new Element(mainWrap.child('div.x-grid3-header')), |
---|
1930 | scroller = new Element(mainWrap.child('div.x-grid3-scroller')); |
---|
1931 | |
---|
1932 | if (this.grid.hideHeaders) { |
---|
1933 | mainHd.setDisplayed(false); |
---|
1934 | } |
---|
1935 | |
---|
1936 | if (this.forceFit) { |
---|
1937 | scroller.setStyle('overflow-x', 'hidden'); |
---|
1938 | } |
---|
1939 | |
---|
1940 | /** |
---|
1941 | * <i>Read-only</i>. The GridView's body Element which encapsulates all rows in the Grid. |
---|
1942 | * This {@link Ext.Element Element} is only available after the GridPanel has been rendered. |
---|
1943 | * @type Ext.Element |
---|
1944 | * @property mainBody |
---|
1945 | */ |
---|
1946 | |
---|
1947 | Ext.apply(this, { |
---|
1948 | el : el, |
---|
1949 | mainWrap: mainWrap, |
---|
1950 | scroller: scroller, |
---|
1951 | mainHd : mainHd, |
---|
1952 | innerHd : mainHd.child('div.x-grid3-header-inner').dom, |
---|
1953 | mainBody: new Element(Element.fly(scroller).child('div.x-grid3-body')), |
---|
1954 | focusEl : new Element(Element.fly(scroller).child('a')), |
---|
1955 | |
---|
1956 | resizeMarker: new Element(el.child('div.x-grid3-resize-marker')), |
---|
1957 | resizeProxy : new Element(el.child('div.x-grid3-resize-proxy')) |
---|
1958 | }); |
---|
1959 | |
---|
1960 | this.focusEl.swallowEvent('click', true); |
---|
1961 | }, |
---|
1962 | |
---|
1963 | // private |
---|
1964 | getRows : function() { |
---|
1965 | return this.hasRows() ? this.mainBody.dom.childNodes : []; |
---|
1966 | }, |
---|
1967 | |
---|
1968 | // finder methods, used with delegation |
---|
1969 | |
---|
1970 | // private |
---|
1971 | findCell : function(el) { |
---|
1972 | if (!el) { |
---|
1973 | return false; |
---|
1974 | } |
---|
1975 | return this.fly(el).findParent(this.cellSelector, this.cellSelectorDepth); |
---|
1976 | }, |
---|
1977 | |
---|
1978 | /** |
---|
1979 | * <p>Return the index of the grid column which contains the passed HTMLElement.</p> |
---|
1980 | * See also {@link #findRowIndex} |
---|
1981 | * @param {HTMLElement} el The target element |
---|
1982 | * @return {Number} The column index, or <b>false</b> if the target element is not within a row of this GridView. |
---|
1983 | */ |
---|
1984 | findCellIndex : function(el, requiredCls) { |
---|
1985 | var cell = this.findCell(el), |
---|
1986 | hasCls; |
---|
1987 | |
---|
1988 | if (cell) { |
---|
1989 | hasCls = this.fly(cell).hasClass(requiredCls); |
---|
1990 | if (!requiredCls || hasCls) { |
---|
1991 | return this.getCellIndex(cell); |
---|
1992 | } |
---|
1993 | } |
---|
1994 | return false; |
---|
1995 | }, |
---|
1996 | |
---|
1997 | // private |
---|
1998 | getCellIndex : function(el) { |
---|
1999 | if (el) { |
---|
2000 | var match = el.className.match(this.colRe); |
---|
2001 | |
---|
2002 | if (match && match[1]) { |
---|
2003 | return this.cm.getIndexById(match[1]); |
---|
2004 | } |
---|
2005 | } |
---|
2006 | return false; |
---|
2007 | }, |
---|
2008 | |
---|
2009 | // private |
---|
2010 | findHeaderCell : function(el) { |
---|
2011 | var cell = this.findCell(el); |
---|
2012 | return cell && this.fly(cell).hasClass(this.hdCls) ? cell : null; |
---|
2013 | }, |
---|
2014 | |
---|
2015 | // private |
---|
2016 | findHeaderIndex : function(el){ |
---|
2017 | return this.findCellIndex(el, this.hdCls); |
---|
2018 | }, |
---|
2019 | |
---|
2020 | /** |
---|
2021 | * Return the HtmlElement representing the grid row which contains the passed element. |
---|
2022 | * @param {HTMLElement} el The target HTMLElement |
---|
2023 | * @return {HTMLElement} The row element, or null if the target element is not within a row of this GridView. |
---|
2024 | */ |
---|
2025 | findRow : function(el) { |
---|
2026 | if (!el) { |
---|
2027 | return false; |
---|
2028 | } |
---|
2029 | return this.fly(el).findParent(this.rowSelector, this.rowSelectorDepth); |
---|
2030 | }, |
---|
2031 | |
---|
2032 | /** |
---|
2033 | * Return the index of the grid row which contains the passed HTMLElement. |
---|
2034 | * See also {@link #findCellIndex} |
---|
2035 | * @param {HTMLElement} el The target HTMLElement |
---|
2036 | * @return {Number} The row index, or <b>false</b> if the target element is not within a row of this GridView. |
---|
2037 | */ |
---|
2038 | findRowIndex : function(el) { |
---|
2039 | var row = this.findRow(el); |
---|
2040 | return row ? row.rowIndex : false; |
---|
2041 | }, |
---|
2042 | |
---|
2043 | /** |
---|
2044 | * Return the HtmlElement representing the grid row body which contains the passed element. |
---|
2045 | * @param {HTMLElement} el The target HTMLElement |
---|
2046 | * @return {HTMLElement} The row body element, or null if the target element is not within a row body of this GridView. |
---|
2047 | */ |
---|
2048 | findRowBody : function(el) { |
---|
2049 | if (!el) { |
---|
2050 | return false; |
---|
2051 | } |
---|
2052 | |
---|
2053 | return this.fly(el).findParent(this.rowBodySelector, this.rowBodySelectorDepth); |
---|
2054 | }, |
---|
2055 | |
---|
2056 | // getter methods for fetching elements dynamically in the grid |
---|
2057 | |
---|
2058 | /** |
---|
2059 | * Return the <tt><div></tt> HtmlElement which represents a Grid row for the specified index. |
---|
2060 | * @param {Number} index The row index |
---|
2061 | * @return {HtmlElement} The div element. |
---|
2062 | */ |
---|
2063 | getRow : function(row) { |
---|
2064 | return this.getRows()[row]; |
---|
2065 | }, |
---|
2066 | |
---|
2067 | /** |
---|
2068 | * Returns the grid's <tt><td></tt> HtmlElement at the specified coordinates. |
---|
2069 | * @param {Number} row The row index in which to find the cell. |
---|
2070 | * @param {Number} col The column index of the cell. |
---|
2071 | * @return {HtmlElement} The td at the specified coordinates. |
---|
2072 | */ |
---|
2073 | getCell : function(row, col) { |
---|
2074 | return Ext.fly(this.getRow(row)).query(this.cellSelector)[col]; |
---|
2075 | }, |
---|
2076 | |
---|
2077 | /** |
---|
2078 | * Return the <tt><td></tt> HtmlElement which represents the Grid's header cell for the specified column index. |
---|
2079 | * @param {Number} index The column index |
---|
2080 | * @return {HtmlElement} The td element. |
---|
2081 | */ |
---|
2082 | getHeaderCell : function(index) { |
---|
2083 | return this.mainHd.dom.getElementsByTagName('td')[index]; |
---|
2084 | }, |
---|
2085 | |
---|
2086 | // manipulating elements |
---|
2087 | |
---|
2088 | // private - use getRowClass to apply custom row classes |
---|
2089 | addRowClass : function(rowId, cls) { |
---|
2090 | var row = this.getRow(rowId); |
---|
2091 | if (row) { |
---|
2092 | this.fly(row).addClass(cls); |
---|
2093 | } |
---|
2094 | }, |
---|
2095 | |
---|
2096 | // private |
---|
2097 | removeRowClass : function(row, cls) { |
---|
2098 | var r = this.getRow(row); |
---|
2099 | if(r){ |
---|
2100 | this.fly(r).removeClass(cls); |
---|
2101 | } |
---|
2102 | }, |
---|
2103 | |
---|
2104 | // private |
---|
2105 | removeRow : function(row) { |
---|
2106 | Ext.removeNode(this.getRow(row)); |
---|
2107 | this.syncFocusEl(row); |
---|
2108 | }, |
---|
2109 | |
---|
2110 | // private |
---|
2111 | removeRows : function(firstRow, lastRow) { |
---|
2112 | var bd = this.mainBody.dom, |
---|
2113 | rowIndex; |
---|
2114 | |
---|
2115 | for (rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){ |
---|
2116 | Ext.removeNode(bd.childNodes[firstRow]); |
---|
2117 | } |
---|
2118 | |
---|
2119 | this.syncFocusEl(firstRow); |
---|
2120 | }, |
---|
2121 | |
---|
2122 | /* ----------------------------------- Scrolling functions -------------------------------------------*/ |
---|
2123 | |
---|
2124 | // private |
---|
2125 | getScrollState : function() { |
---|
2126 | var sb = this.scroller.dom; |
---|
2127 | |
---|
2128 | return { |
---|
2129 | left: sb.scrollLeft, |
---|
2130 | top : sb.scrollTop |
---|
2131 | }; |
---|
2132 | }, |
---|
2133 | |
---|
2134 | // private |
---|
2135 | restoreScroll : function(state) { |
---|
2136 | var sb = this.scroller.dom; |
---|
2137 | sb.scrollLeft = state.left; |
---|
2138 | sb.scrollTop = state.top; |
---|
2139 | }, |
---|
2140 | |
---|
2141 | /** |
---|
2142 | * Scrolls the grid to the top |
---|
2143 | */ |
---|
2144 | scrollToTop : function() { |
---|
2145 | var dom = this.scroller.dom; |
---|
2146 | |
---|
2147 | dom.scrollTop = 0; |
---|
2148 | dom.scrollLeft = 0; |
---|
2149 | }, |
---|
2150 | |
---|
2151 | // private |
---|
2152 | syncScroll : function() { |
---|
2153 | this.syncHeaderScroll(); |
---|
2154 | var mb = this.scroller.dom; |
---|
2155 | this.grid.fireEvent('bodyscroll', mb.scrollLeft, mb.scrollTop); |
---|
2156 | }, |
---|
2157 | |
---|
2158 | // private |
---|
2159 | syncHeaderScroll : function() { |
---|
2160 | var innerHd = this.innerHd, |
---|
2161 | scrollLeft = this.scroller.dom.scrollLeft; |
---|
2162 | |
---|
2163 | innerHd.scrollLeft = scrollLeft; |
---|
2164 | innerHd.scrollLeft = scrollLeft; // second time for IE (1/2 time first fails, other browsers ignore) |
---|
2165 | }, |
---|
2166 | |
---|
2167 | /** |
---|
2168 | * @private |
---|
2169 | * Ensures the given column has the given icon class |
---|
2170 | */ |
---|
2171 | updateSortIcon : function(col, dir) { |
---|
2172 | var sortClasses = this.sortClasses, |
---|
2173 | sortClass = sortClasses[dir == "DESC" ? 1 : 0], |
---|
2174 | headers = this.mainHd.select('td').removeClass(sortClasses); |
---|
2175 | |
---|
2176 | headers.item(col).addClass(sortClass); |
---|
2177 | }, |
---|
2178 | |
---|
2179 | /** |
---|
2180 | * @private |
---|
2181 | * Updates the size of every column and cell in the grid |
---|
2182 | */ |
---|
2183 | updateAllColumnWidths : function() { |
---|
2184 | var totalWidth = this.getTotalWidth(), |
---|
2185 | colCount = this.cm.getColumnCount(), |
---|
2186 | rows = this.getRows(), |
---|
2187 | rowCount = rows.length, |
---|
2188 | widths = [], |
---|
2189 | row, rowFirstChild, trow, i, j; |
---|
2190 | |
---|
2191 | for (i = 0; i < colCount; i++) { |
---|
2192 | widths[i] = this.getColumnWidth(i); |
---|
2193 | this.getHeaderCell(i).style.width = widths[i]; |
---|
2194 | } |
---|
2195 | |
---|
2196 | this.updateHeaderWidth(); |
---|
2197 | |
---|
2198 | for (i = 0; i < rowCount; i++) { |
---|
2199 | row = rows[i]; |
---|
2200 | row.style.width = totalWidth; |
---|
2201 | rowFirstChild = row.firstChild; |
---|
2202 | |
---|
2203 | if (rowFirstChild) { |
---|
2204 | rowFirstChild.style.width = totalWidth; |
---|
2205 | trow = rowFirstChild.rows[0]; |
---|
2206 | |
---|
2207 | for (j = 0; j < colCount; j++) { |
---|
2208 | trow.childNodes[j].style.width = widths[j]; |
---|
2209 | } |
---|
2210 | } |
---|
2211 | } |
---|
2212 | |
---|
2213 | this.onAllColumnWidthsUpdated(widths, totalWidth); |
---|
2214 | }, |
---|
2215 | |
---|
2216 | /** |
---|
2217 | * @private |
---|
2218 | * Called after a column's width has been updated, this resizes all of the cells for that column in each row |
---|
2219 | * @param {Number} column The column index |
---|
2220 | */ |
---|
2221 | updateColumnWidth : function(column, width) { |
---|
2222 | var columnWidth = this.getColumnWidth(column), |
---|
2223 | totalWidth = this.getTotalWidth(), |
---|
2224 | headerCell = this.getHeaderCell(column), |
---|
2225 | nodes = this.getRows(), |
---|
2226 | nodeCount = nodes.length, |
---|
2227 | row, i, firstChild; |
---|
2228 | |
---|
2229 | this.updateHeaderWidth(); |
---|
2230 | headerCell.style.width = columnWidth; |
---|
2231 | |
---|
2232 | for (i = 0; i < nodeCount; i++) { |
---|
2233 | row = nodes[i]; |
---|
2234 | firstChild = row.firstChild; |
---|
2235 | |
---|
2236 | row.style.width = totalWidth; |
---|
2237 | if (firstChild) { |
---|
2238 | firstChild.style.width = totalWidth; |
---|
2239 | firstChild.rows[0].childNodes[column].style.width = columnWidth; |
---|
2240 | } |
---|
2241 | } |
---|
2242 | |
---|
2243 | this.onColumnWidthUpdated(column, columnWidth, totalWidth); |
---|
2244 | }, |
---|
2245 | |
---|
2246 | /** |
---|
2247 | * @private |
---|
2248 | * Sets the hidden status of a given column. |
---|
2249 | * @param {Number} col The column index |
---|
2250 | * @param {Boolean} hidden True to make the column hidden |
---|
2251 | */ |
---|
2252 | updateColumnHidden : function(col, hidden) { |
---|
2253 | var totalWidth = this.getTotalWidth(), |
---|
2254 | display = hidden ? 'none' : '', |
---|
2255 | headerCell = this.getHeaderCell(col), |
---|
2256 | nodes = this.getRows(), |
---|
2257 | nodeCount = nodes.length, |
---|
2258 | row, rowFirstChild, i; |
---|
2259 | |
---|
2260 | this.updateHeaderWidth(); |
---|
2261 | headerCell.style.display = display; |
---|
2262 | |
---|
2263 | for (i = 0; i < nodeCount; i++) { |
---|
2264 | row = nodes[i]; |
---|
2265 | row.style.width = totalWidth; |
---|
2266 | rowFirstChild = row.firstChild; |
---|
2267 | |
---|
2268 | if (rowFirstChild) { |
---|
2269 | rowFirstChild.style.width = totalWidth; |
---|
2270 | rowFirstChild.rows[0].childNodes[col].style.display = display; |
---|
2271 | } |
---|
2272 | } |
---|
2273 | |
---|
2274 | this.onColumnHiddenUpdated(col, hidden, totalWidth); |
---|
2275 | delete this.lastViewWidth; //recalc |
---|
2276 | this.layout(); |
---|
2277 | }, |
---|
2278 | |
---|
2279 | /** |
---|
2280 | * @private |
---|
2281 | * Renders all of the rows to a string buffer and returns the string. This is called internally |
---|
2282 | * by renderRows and performs the actual string building for the rows - it does not inject HTML into the DOM. |
---|
2283 | * @param {Array} columns The column data acquired from getColumnData. |
---|
2284 | * @param {Array} records The array of records to render |
---|
2285 | * @param {Ext.data.Store} store The store to render the rows from |
---|
2286 | * @param {Number} startRow The index of the first row being rendered. Sometimes we only render a subset of |
---|
2287 | * the rows so this is used to maintain logic for striping etc |
---|
2288 | * @param {Number} colCount The total number of columns in the column model |
---|
2289 | * @param {Boolean} stripe True to stripe the rows |
---|
2290 | * @return {String} A string containing the HTML for the rendered rows |
---|
2291 | */ |
---|
2292 | doRender : function(columns, records, store, startRow, colCount, stripe) { |
---|
2293 | var templates = this.templates, |
---|
2294 | cellTemplate = templates.cell, |
---|
2295 | rowTemplate = templates.row, |
---|
2296 | last = colCount - 1, |
---|
2297 | tstyle = 'width:' + this.getTotalWidth() + ';', |
---|
2298 | // buffers |
---|
2299 | rowBuffer = [], |
---|
2300 | colBuffer = [], |
---|
2301 | rowParams = {tstyle: tstyle}, |
---|
2302 | meta = {}, |
---|
2303 | len = records.length, |
---|
2304 | alt, |
---|
2305 | column, |
---|
2306 | record, i, j, rowIndex; |
---|
2307 | |
---|
2308 | //build up each row's HTML |
---|
2309 | for (j = 0; j < len; j++) { |
---|
2310 | record = records[j]; |
---|
2311 | colBuffer = []; |
---|
2312 | |
---|
2313 | rowIndex = j + startRow; |
---|
2314 | |
---|
2315 | //build up each column's HTML |
---|
2316 | for (i = 0; i < colCount; i++) { |
---|
2317 | column = columns[i]; |
---|
2318 | |
---|
2319 | meta.id = column.id; |
---|
2320 | meta.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : ''); |
---|
2321 | meta.attr = meta.cellAttr = ''; |
---|
2322 | meta.style = column.style; |
---|
2323 | meta.value = column.renderer.call(column.scope, record.data[column.name], meta, record, rowIndex, i, store); |
---|
2324 | |
---|
2325 | if (Ext.isEmpty(meta.value)) { |
---|
2326 | meta.value = ' '; |
---|
2327 | } |
---|
2328 | |
---|
2329 | if (this.markDirty && record.dirty && typeof record.modified[column.name] != 'undefined') { |
---|
2330 | meta.css += ' x-grid3-dirty-cell'; |
---|
2331 | } |
---|
2332 | |
---|
2333 | colBuffer[colBuffer.length] = cellTemplate.apply(meta); |
---|
2334 | } |
---|
2335 | |
---|
2336 | alt = []; |
---|
2337 | //set up row striping and row dirtiness CSS classes |
---|
2338 | if (stripe && ((rowIndex + 1) % 2 === 0)) { |
---|
2339 | alt[0] = 'x-grid3-row-alt'; |
---|
2340 | } |
---|
2341 | |
---|
2342 | if (record.dirty) { |
---|
2343 | alt[1] = ' x-grid3-dirty-row'; |
---|
2344 | } |
---|
2345 | |
---|
2346 | rowParams.cols = colCount; |
---|
2347 | |
---|
2348 | if (this.getRowClass) { |
---|
2349 | alt[2] = this.getRowClass(record, rowIndex, rowParams, store); |
---|
2350 | } |
---|
2351 | |
---|
2352 | rowParams.alt = alt.join(' '); |
---|
2353 | rowParams.cells = colBuffer.join(''); |
---|
2354 | |
---|
2355 | rowBuffer[rowBuffer.length] = rowTemplate.apply(rowParams); |
---|
2356 | } |
---|
2357 | |
---|
2358 | return rowBuffer.join(''); |
---|
2359 | }, |
---|
2360 | |
---|
2361 | /** |
---|
2362 | * @private |
---|
2363 | * Adds CSS classes and rowIndex to each row |
---|
2364 | * @param {Number} startRow The row to start from (defaults to 0) |
---|
2365 | */ |
---|
2366 | processRows : function(startRow, skipStripe) { |
---|
2367 | if (!this.ds || this.ds.getCount() < 1) { |
---|
2368 | return; |
---|
2369 | } |
---|
2370 | |
---|
2371 | var rows = this.getRows(), |
---|
2372 | length = rows.length, |
---|
2373 | row, i; |
---|
2374 | |
---|
2375 | skipStripe = skipStripe || !this.grid.stripeRows; |
---|
2376 | startRow = startRow || 0; |
---|
2377 | |
---|
2378 | for (i = 0; i < length; i++) { |
---|
2379 | row = rows[i]; |
---|
2380 | if (row) { |
---|
2381 | row.rowIndex = i; |
---|
2382 | if (!skipStripe) { |
---|
2383 | row.className = row.className.replace(this.rowClsRe, ' '); |
---|
2384 | if ((i + 1) % 2 === 0){ |
---|
2385 | row.className += ' x-grid3-row-alt'; |
---|
2386 | } |
---|
2387 | } |
---|
2388 | } |
---|
2389 | } |
---|
2390 | |
---|
2391 | // add first/last-row classes |
---|
2392 | if (startRow === 0) { |
---|
2393 | Ext.fly(rows[0]).addClass(this.firstRowCls); |
---|
2394 | } |
---|
2395 | |
---|
2396 | Ext.fly(rows[length - 1]).addClass(this.lastRowCls); |
---|
2397 | }, |
---|
2398 | |
---|
2399 | /** |
---|
2400 | * @private |
---|
2401 | */ |
---|
2402 | afterRender : function() { |
---|
2403 | if (!this.ds || !this.cm) { |
---|
2404 | return; |
---|
2405 | } |
---|
2406 | |
---|
2407 | this.mainBody.dom.innerHTML = this.renderBody() || ' '; |
---|
2408 | this.processRows(0, true); |
---|
2409 | |
---|
2410 | if (this.deferEmptyText !== true) { |
---|
2411 | this.applyEmptyText(); |
---|
2412 | } |
---|
2413 | |
---|
2414 | this.grid.fireEvent('viewready', this.grid); |
---|
2415 | }, |
---|
2416 | |
---|
2417 | /** |
---|
2418 | * @private |
---|
2419 | * This is always intended to be called after renderUI. Sets up listeners on the UI elements |
---|
2420 | * and sets up options like column menus, moving and resizing. |
---|
2421 | */ |
---|
2422 | afterRenderUI: function() { |
---|
2423 | var grid = this.grid; |
---|
2424 | |
---|
2425 | this.initElements(); |
---|
2426 | |
---|
2427 | // get mousedowns early |
---|
2428 | Ext.fly(this.innerHd).on('click', this.handleHdDown, this); |
---|
2429 | |
---|
2430 | this.mainHd.on({ |
---|
2431 | scope : this, |
---|
2432 | mouseover: this.handleHdOver, |
---|
2433 | mouseout : this.handleHdOut, |
---|
2434 | mousemove: this.handleHdMove |
---|
2435 | }); |
---|
2436 | |
---|
2437 | this.scroller.on('scroll', this.syncScroll, this); |
---|
2438 | |
---|
2439 | if (grid.enableColumnResize !== false) { |
---|
2440 | this.splitZone = new Ext.grid.GridView.SplitDragZone(grid, this.mainHd.dom); |
---|
2441 | } |
---|
2442 | |
---|
2443 | if (grid.enableColumnMove) { |
---|
2444 | this.columnDrag = new Ext.grid.GridView.ColumnDragZone(grid, this.innerHd); |
---|
2445 | this.columnDrop = new Ext.grid.HeaderDropZone(grid, this.mainHd.dom); |
---|
2446 | } |
---|
2447 | |
---|
2448 | if (grid.enableHdMenu !== false) { |
---|
2449 | this.hmenu = new Ext.menu.Menu({id: grid.id + '-hctx'}); |
---|
2450 | this.hmenu.add( |
---|
2451 | {itemId:'asc', text: this.sortAscText, cls: 'xg-hmenu-sort-asc'}, |
---|
2452 | {itemId:'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'} |
---|
2453 | ); |
---|
2454 | |
---|
2455 | if (grid.enableColumnHide !== false) { |
---|
2456 | this.colMenu = new Ext.menu.Menu({id:grid.id + '-hcols-menu'}); |
---|
2457 | this.colMenu.on({ |
---|
2458 | scope : this, |
---|
2459 | beforeshow: this.beforeColMenuShow, |
---|
2460 | itemclick : this.handleHdMenuClick |
---|
2461 | }); |
---|
2462 | this.hmenu.add('-', { |
---|
2463 | itemId:'columns', |
---|
2464 | hideOnClick: false, |
---|
2465 | text: this.columnsText, |
---|
2466 | menu: this.colMenu, |
---|
2467 | iconCls: 'x-cols-icon' |
---|
2468 | }); |
---|
2469 | } |
---|
2470 | |
---|
2471 | this.hmenu.on('itemclick', this.handleHdMenuClick, this); |
---|
2472 | } |
---|
2473 | |
---|
2474 | if (grid.trackMouseOver) { |
---|
2475 | this.mainBody.on({ |
---|
2476 | scope : this, |
---|
2477 | mouseover: this.onRowOver, |
---|
2478 | mouseout : this.onRowOut |
---|
2479 | }); |
---|
2480 | } |
---|
2481 | |
---|
2482 | if (grid.enableDragDrop || grid.enableDrag) { |
---|
2483 | this.dragZone = new Ext.grid.GridDragZone(grid, { |
---|
2484 | ddGroup : grid.ddGroup || 'GridDD' |
---|
2485 | }); |
---|
2486 | } |
---|
2487 | |
---|
2488 | this.updateHeaderSortState(); |
---|
2489 | }, |
---|
2490 | |
---|
2491 | /** |
---|
2492 | * @private |
---|
2493 | * Renders each of the UI elements in turn. This is called internally, once, by this.render. It does not |
---|
2494 | * render rows from the store, just the surrounding UI elements. |
---|
2495 | */ |
---|
2496 | renderUI : function() { |
---|
2497 | var templates = this.templates; |
---|
2498 | |
---|
2499 | return templates.master.apply({ |
---|
2500 | body : templates.body.apply({rows:' '}), |
---|
2501 | header: this.renderHeaders(), |
---|
2502 | ostyle: 'width:' + this.getOffsetWidth() + ';', |
---|
2503 | bstyle: 'width:' + this.getTotalWidth() + ';' |
---|
2504 | }); |
---|
2505 | }, |
---|
2506 | |
---|
2507 | // private |
---|
2508 | processEvent : function(name, e) { |
---|
2509 | var target = e.getTarget(), |
---|
2510 | grid = this.grid, |
---|
2511 | header = this.findHeaderIndex(target), |
---|
2512 | row, cell, col, body; |
---|
2513 | |
---|
2514 | grid.fireEvent(name, e); |
---|
2515 | |
---|
2516 | if (header !== false) { |
---|
2517 | grid.fireEvent('header' + name, grid, header, e); |
---|
2518 | } else { |
---|
2519 | row = this.findRowIndex(target); |
---|
2520 | |
---|
2521 | // Grid's value-added events must bubble correctly to allow cancelling via returning false: cell->column->row |
---|
2522 | // We must allow a return of false at any of these levels to cancel the event processing. |
---|
2523 | // Particularly allowing rowmousedown to be cancellable by prior handlers which need to prevent selection. |
---|
2524 | if (row !== false) { |
---|
2525 | cell = this.findCellIndex(target); |
---|
2526 | if (cell !== false) { |
---|
2527 | col = grid.colModel.getColumnAt(cell); |
---|
2528 | if (grid.fireEvent('cell' + name, grid, row, cell, e) !== false) { |
---|
2529 | if (!col || (col.processEvent && (col.processEvent(name, e, grid, row, cell) !== false))) { |
---|
2530 | grid.fireEvent('row' + name, grid, row, e); |
---|
2531 | } |
---|
2532 | } |
---|
2533 | } else { |
---|
2534 | if (grid.fireEvent('row' + name, grid, row, e) !== false) { |
---|
2535 | (body = this.findRowBody(target)) && grid.fireEvent('rowbody' + name, grid, row, e); |
---|
2536 | } |
---|
2537 | } |
---|
2538 | } else { |
---|
2539 | grid.fireEvent('container' + name, grid, e); |
---|
2540 | } |
---|
2541 | } |
---|
2542 | }, |
---|
2543 | |
---|
2544 | /** |
---|
2545 | * @private |
---|
2546 | * Sizes the grid's header and body elements |
---|
2547 | */ |
---|
2548 | layout : function(initial) { |
---|
2549 | if (!this.mainBody) { |
---|
2550 | return; // not rendered |
---|
2551 | } |
---|
2552 | |
---|
2553 | var grid = this.grid, |
---|
2554 | gridEl = grid.getGridEl(), |
---|
2555 | gridSize = gridEl.getSize(true), |
---|
2556 | gridWidth = gridSize.width, |
---|
2557 | gridHeight = gridSize.height, |
---|
2558 | scroller = this.scroller, |
---|
2559 | scrollStyle, headerHeight, scrollHeight; |
---|
2560 | |
---|
2561 | if (gridWidth < 20 || gridHeight < 20) { |
---|
2562 | return; |
---|
2563 | } |
---|
2564 | |
---|
2565 | if (grid.autoHeight) { |
---|
2566 | scrollStyle = scroller.dom.style; |
---|
2567 | scrollStyle.overflow = 'visible'; |
---|
2568 | |
---|
2569 | if (Ext.isWebKit) { |
---|
2570 | scrollStyle.position = 'static'; |
---|
2571 | } |
---|
2572 | } else { |
---|
2573 | this.el.setSize(gridWidth, gridHeight); |
---|
2574 | |
---|
2575 | headerHeight = this.mainHd.getHeight(); |
---|
2576 | scrollHeight = gridHeight - headerHeight; |
---|
2577 | |
---|
2578 | scroller.setSize(gridWidth, scrollHeight); |
---|
2579 | |
---|
2580 | if (this.innerHd) { |
---|
2581 | this.innerHd.style.width = (gridWidth) + "px"; |
---|
2582 | } |
---|
2583 | } |
---|
2584 | |
---|
2585 | if (this.forceFit || (initial === true && this.autoFill)) { |
---|
2586 | if (this.lastViewWidth != gridWidth) { |
---|
2587 | this.fitColumns(false, false); |
---|
2588 | this.lastViewWidth = gridWidth; |
---|
2589 | } |
---|
2590 | } else { |
---|
2591 | this.autoExpand(); |
---|
2592 | this.syncHeaderScroll(); |
---|
2593 | } |
---|
2594 | |
---|
2595 | this.onLayout(gridWidth, scrollHeight); |
---|
2596 | }, |
---|
2597 | |
---|
2598 | // template functions for subclasses and plugins |
---|
2599 | // these functions include precalculated values |
---|
2600 | onLayout : function(vw, vh) { |
---|
2601 | // do nothing |
---|
2602 | }, |
---|
2603 | |
---|
2604 | onColumnWidthUpdated : function(col, w, tw) { |
---|
2605 | //template method |
---|
2606 | }, |
---|
2607 | |
---|
2608 | onAllColumnWidthsUpdated : function(ws, tw) { |
---|
2609 | //template method |
---|
2610 | }, |
---|
2611 | |
---|
2612 | onColumnHiddenUpdated : function(col, hidden, tw) { |
---|
2613 | // template method |
---|
2614 | }, |
---|
2615 | |
---|
2616 | updateColumnText : function(col, text) { |
---|
2617 | // template method |
---|
2618 | }, |
---|
2619 | |
---|
2620 | afterMove : function(colIndex) { |
---|
2621 | // template method |
---|
2622 | }, |
---|
2623 | |
---|
2624 | /* ----------------------------------- Core Specific -------------------------------------------*/ |
---|
2625 | // private |
---|
2626 | init : function(grid) { |
---|
2627 | this.grid = grid; |
---|
2628 | |
---|
2629 | this.initTemplates(); |
---|
2630 | this.initData(grid.store, grid.colModel); |
---|
2631 | this.initUI(grid); |
---|
2632 | }, |
---|
2633 | |
---|
2634 | // private |
---|
2635 | getColumnId : function(index){ |
---|
2636 | return this.cm.getColumnId(index); |
---|
2637 | }, |
---|
2638 | |
---|
2639 | // private |
---|
2640 | getOffsetWidth : function() { |
---|
2641 | return (this.cm.getTotalWidth() + this.getScrollOffset()) + 'px'; |
---|
2642 | }, |
---|
2643 | |
---|
2644 | // private |
---|
2645 | getScrollOffset: function() { |
---|
2646 | return Ext.num(this.scrollOffset, Ext.getScrollBarWidth()); |
---|
2647 | }, |
---|
2648 | |
---|
2649 | /** |
---|
2650 | * @private |
---|
2651 | * Renders the header row using the 'header' template. Does not inject the HTML into the DOM, just |
---|
2652 | * returns a string. |
---|
2653 | * @return {String} Rendered header row |
---|
2654 | */ |
---|
2655 | renderHeaders : function() { |
---|
2656 | var colModel = this.cm, |
---|
2657 | templates = this.templates, |
---|
2658 | headerTpl = templates.hcell, |
---|
2659 | properties = {}, |
---|
2660 | colCount = colModel.getColumnCount(), |
---|
2661 | last = colCount - 1, |
---|
2662 | cells = [], |
---|
2663 | i, cssCls; |
---|
2664 | |
---|
2665 | for (i = 0; i < colCount; i++) { |
---|
2666 | if (i == 0) { |
---|
2667 | cssCls = 'x-grid3-cell-first '; |
---|
2668 | } else { |
---|
2669 | cssCls = i == last ? 'x-grid3-cell-last ' : ''; |
---|
2670 | } |
---|
2671 | |
---|
2672 | properties = { |
---|
2673 | id : colModel.getColumnId(i), |
---|
2674 | value : colModel.getColumnHeader(i) || '', |
---|
2675 | style : this.getColumnStyle(i, true), |
---|
2676 | css : cssCls, |
---|
2677 | tooltip: this.getColumnTooltip(i) |
---|
2678 | }; |
---|
2679 | |
---|
2680 | if (colModel.config[i].align == 'right') { |
---|
2681 | properties.istyle = 'padding-right: 16px;'; |
---|
2682 | } else { |
---|
2683 | delete properties.istyle; |
---|
2684 | } |
---|
2685 | |
---|
2686 | cells[i] = headerTpl.apply(properties); |
---|
2687 | } |
---|
2688 | |
---|
2689 | return templates.header.apply({ |
---|
2690 | cells : cells.join(""), |
---|
2691 | tstyle: String.format("width: {0};", this.getTotalWidth()) |
---|
2692 | }); |
---|
2693 | }, |
---|
2694 | |
---|
2695 | /** |
---|
2696 | * @private |
---|
2697 | */ |
---|
2698 | getColumnTooltip : function(i) { |
---|
2699 | var tooltip = this.cm.getColumnTooltip(i); |
---|
2700 | if (tooltip) { |
---|
2701 | if (Ext.QuickTips.isEnabled()) { |
---|
2702 | return 'ext:qtip="' + tooltip + '"'; |
---|
2703 | } else { |
---|
2704 | return 'title="' + tooltip + '"'; |
---|
2705 | } |
---|
2706 | } |
---|
2707 | |
---|
2708 | return ''; |
---|
2709 | }, |
---|
2710 | |
---|
2711 | // private |
---|
2712 | beforeUpdate : function() { |
---|
2713 | this.grid.stopEditing(true); |
---|
2714 | }, |
---|
2715 | |
---|
2716 | /** |
---|
2717 | * @private |
---|
2718 | * Re-renders the headers and ensures they are sized correctly |
---|
2719 | */ |
---|
2720 | updateHeaders : function() { |
---|
2721 | this.innerHd.firstChild.innerHTML = this.renderHeaders(); |
---|
2722 | |
---|
2723 | this.updateHeaderWidth(false); |
---|
2724 | }, |
---|
2725 | |
---|
2726 | /** |
---|
2727 | * @private |
---|
2728 | * Ensures that the header is sized to the total width available to it |
---|
2729 | * @param {Boolean} updateMain True to update the mainBody's width also (defaults to true) |
---|
2730 | */ |
---|
2731 | updateHeaderWidth: function(updateMain) { |
---|
2732 | var innerHdChild = this.innerHd.firstChild, |
---|
2733 | totalWidth = this.getTotalWidth(); |
---|
2734 | |
---|
2735 | innerHdChild.style.width = this.getOffsetWidth(); |
---|
2736 | innerHdChild.firstChild.style.width = totalWidth; |
---|
2737 | |
---|
2738 | if (updateMain !== false) { |
---|
2739 | this.mainBody.dom.style.width = totalWidth; |
---|
2740 | } |
---|
2741 | }, |
---|
2742 | |
---|
2743 | /** |
---|
2744 | * Focuses the specified row. |
---|
2745 | * @param {Number} row The row index |
---|
2746 | */ |
---|
2747 | focusRow : function(row) { |
---|
2748 | this.focusCell(row, 0, false); |
---|
2749 | }, |
---|
2750 | |
---|
2751 | /** |
---|
2752 | * Focuses the specified cell. |
---|
2753 | * @param {Number} row The row index |
---|
2754 | * @param {Number} col The column index |
---|
2755 | */ |
---|
2756 | focusCell : function(row, col, hscroll) { |
---|
2757 | this.syncFocusEl(this.ensureVisible(row, col, hscroll)); |
---|
2758 | |
---|
2759 | var focusEl = this.focusEl; |
---|
2760 | |
---|
2761 | if (Ext.isGecko) { |
---|
2762 | focusEl.focus(); |
---|
2763 | } else { |
---|
2764 | focusEl.focus.defer(1, focusEl); |
---|
2765 | } |
---|
2766 | }, |
---|
2767 | |
---|
2768 | /** |
---|
2769 | * @private |
---|
2770 | * Finds the Elements corresponding to the given row and column indexes |
---|
2771 | */ |
---|
2772 | resolveCell : function(row, col, hscroll) { |
---|
2773 | if (!Ext.isNumber(row)) { |
---|
2774 | row = row.rowIndex; |
---|
2775 | } |
---|
2776 | |
---|
2777 | if (!this.ds) { |
---|
2778 | return null; |
---|
2779 | } |
---|
2780 | |
---|
2781 | if (row < 0 || row >= this.ds.getCount()) { |
---|
2782 | return null; |
---|
2783 | } |
---|
2784 | col = (col !== undefined ? col : 0); |
---|
2785 | |
---|
2786 | var rowEl = this.getRow(row), |
---|
2787 | colModel = this.cm, |
---|
2788 | colCount = colModel.getColumnCount(), |
---|
2789 | cellEl; |
---|
2790 | |
---|
2791 | if (!(hscroll === false && col === 0)) { |
---|
2792 | while (col < colCount && colModel.isHidden(col)) { |
---|
2793 | col++; |
---|
2794 | } |
---|
2795 | |
---|
2796 | cellEl = this.getCell(row, col); |
---|
2797 | } |
---|
2798 | |
---|
2799 | return {row: rowEl, cell: cellEl}; |
---|
2800 | }, |
---|
2801 | |
---|
2802 | /** |
---|
2803 | * @private |
---|
2804 | * Returns the XY co-ordinates of a given row/cell resolution (see {@link #resolveCell}) |
---|
2805 | * @return {Array} X and Y coords |
---|
2806 | */ |
---|
2807 | getResolvedXY : function(resolved) { |
---|
2808 | if (!resolved) { |
---|
2809 | return null; |
---|
2810 | } |
---|
2811 | |
---|
2812 | var cell = resolved.cell, |
---|
2813 | row = resolved.row; |
---|
2814 | |
---|
2815 | if (cell) { |
---|
2816 | return Ext.fly(cell).getXY(); |
---|
2817 | } else { |
---|
2818 | return [this.el.getX(), Ext.fly(row).getY()]; |
---|
2819 | } |
---|
2820 | }, |
---|
2821 | |
---|
2822 | /** |
---|
2823 | * @private |
---|
2824 | * Moves the focus element to the x and y co-ordinates of the given row and column |
---|
2825 | */ |
---|
2826 | syncFocusEl : function(row, col, hscroll) { |
---|
2827 | var xy = row; |
---|
2828 | |
---|
2829 | if (!Ext.isArray(xy)) { |
---|
2830 | row = Math.min(row, Math.max(0, this.getRows().length-1)); |
---|
2831 | |
---|
2832 | if (isNaN(row)) { |
---|
2833 | return; |
---|
2834 | } |
---|
2835 | |
---|
2836 | xy = this.getResolvedXY(this.resolveCell(row, col, hscroll)); |
---|
2837 | } |
---|
2838 | |
---|
2839 | this.focusEl.setXY(xy || this.scroller.getXY()); |
---|
2840 | }, |
---|
2841 | |
---|
2842 | /** |
---|
2843 | * @private |
---|
2844 | */ |
---|
2845 | ensureVisible : function(row, col, hscroll) { |
---|
2846 | var resolved = this.resolveCell(row, col, hscroll); |
---|
2847 | |
---|
2848 | if (!resolved || !resolved.row) { |
---|
2849 | return null; |
---|
2850 | } |
---|
2851 | |
---|
2852 | var rowEl = resolved.row, |
---|
2853 | cellEl = resolved.cell, |
---|
2854 | c = this.scroller.dom, |
---|
2855 | p = rowEl, |
---|
2856 | ctop = 0, |
---|
2857 | stop = this.el.dom; |
---|
2858 | |
---|
2859 | while (p && p != stop) { |
---|
2860 | ctop += p.offsetTop; |
---|
2861 | p = p.offsetParent; |
---|
2862 | } |
---|
2863 | |
---|
2864 | ctop -= this.mainHd.dom.offsetHeight; |
---|
2865 | stop = parseInt(c.scrollTop, 10); |
---|
2866 | |
---|
2867 | var cbot = ctop + rowEl.offsetHeight, |
---|
2868 | ch = c.clientHeight, |
---|
2869 | sbot = stop + ch; |
---|
2870 | |
---|
2871 | |
---|
2872 | if (ctop < stop) { |
---|
2873 | c.scrollTop = ctop; |
---|
2874 | } else if(cbot > sbot) { |
---|
2875 | c.scrollTop = cbot-ch; |
---|
2876 | } |
---|
2877 | |
---|
2878 | if (hscroll !== false) { |
---|
2879 | var cleft = parseInt(cellEl.offsetLeft, 10), |
---|
2880 | cright = cleft + cellEl.offsetWidth, |
---|
2881 | sleft = parseInt(c.scrollLeft, 10), |
---|
2882 | sright = sleft + c.clientWidth; |
---|
2883 | |
---|
2884 | if (cleft < sleft) { |
---|
2885 | c.scrollLeft = cleft; |
---|
2886 | } else if(cright > sright) { |
---|
2887 | c.scrollLeft = cright-c.clientWidth; |
---|
2888 | } |
---|
2889 | } |
---|
2890 | |
---|
2891 | return this.getResolvedXY(resolved); |
---|
2892 | }, |
---|
2893 | |
---|
2894 | // private |
---|
2895 | insertRows : function(dm, firstRow, lastRow, isUpdate) { |
---|
2896 | var last = dm.getCount() - 1; |
---|
2897 | if( !isUpdate && firstRow === 0 && lastRow >= last) { |
---|
2898 | this.fireEvent('beforerowsinserted', this, firstRow, lastRow); |
---|
2899 | this.refresh(); |
---|
2900 | this.fireEvent('rowsinserted', this, firstRow, lastRow); |
---|
2901 | } else { |
---|
2902 | if (!isUpdate) { |
---|
2903 | this.fireEvent('beforerowsinserted', this, firstRow, lastRow); |
---|
2904 | } |
---|
2905 | var html = this.renderRows(firstRow, lastRow), |
---|
2906 | before = this.getRow(firstRow); |
---|
2907 | if (before) { |
---|
2908 | if(firstRow === 0){ |
---|
2909 | Ext.fly(this.getRow(0)).removeClass(this.firstRowCls); |
---|
2910 | } |
---|
2911 | Ext.DomHelper.insertHtml('beforeBegin', before, html); |
---|
2912 | } else { |
---|
2913 | var r = this.getRow(last - 1); |
---|
2914 | if(r){ |
---|
2915 | Ext.fly(r).removeClass(this.lastRowCls); |
---|
2916 | } |
---|
2917 | Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html); |
---|
2918 | } |
---|
2919 | if (!isUpdate) { |
---|
2920 | this.processRows(firstRow); |
---|
2921 | this.fireEvent('rowsinserted', this, firstRow, lastRow); |
---|
2922 | } else if (firstRow === 0 || firstRow >= last) { |
---|
2923 | //ensure first/last row is kept after an update. |
---|
2924 | Ext.fly(this.getRow(firstRow)).addClass(firstRow === 0 ? this.firstRowCls : this.lastRowCls); |
---|
2925 | } |
---|
2926 | } |
---|
2927 | this.syncFocusEl(firstRow); |
---|
2928 | }, |
---|
2929 | |
---|
2930 | /** |
---|
2931 | * @private |
---|
2932 | * DEPRECATED - this doesn't appear to be called anywhere in the library, remove in 4.0. |
---|
2933 | */ |
---|
2934 | deleteRows : function(dm, firstRow, lastRow) { |
---|
2935 | if (dm.getRowCount() < 1) { |
---|
2936 | this.refresh(); |
---|
2937 | } else { |
---|
2938 | this.fireEvent('beforerowsdeleted', this, firstRow, lastRow); |
---|
2939 | |
---|
2940 | this.removeRows(firstRow, lastRow); |
---|
2941 | |
---|
2942 | this.processRows(firstRow); |
---|
2943 | this.fireEvent('rowsdeleted', this, firstRow, lastRow); |
---|
2944 | } |
---|
2945 | }, |
---|
2946 | |
---|
2947 | /** |
---|
2948 | * @private |
---|
2949 | * Builds a CSS string for the given column index |
---|
2950 | * @param {Number} colIndex The column index |
---|
2951 | * @param {Boolean} isHeader True if getting the style for the column's header |
---|
2952 | * @return {String} The CSS string |
---|
2953 | */ |
---|
2954 | getColumnStyle : function(colIndex, isHeader) { |
---|
2955 | var colModel = this.cm, |
---|
2956 | colConfig = colModel.config, |
---|
2957 | style = isHeader ? '' : colConfig[colIndex].css || '', |
---|
2958 | align = colConfig[colIndex].align; |
---|
2959 | |
---|
2960 | style += String.format("width: {0};", this.getColumnWidth(colIndex)); |
---|
2961 | |
---|
2962 | if (colModel.isHidden(colIndex)) { |
---|
2963 | style += 'display: none; '; |
---|
2964 | } |
---|
2965 | |
---|
2966 | if (align) { |
---|
2967 | style += String.format("text-align: {0};", align); |
---|
2968 | } |
---|
2969 | |
---|
2970 | return style; |
---|
2971 | }, |
---|
2972 | |
---|
2973 | /** |
---|
2974 | * @private |
---|
2975 | * Returns the width of a given column minus its border width |
---|
2976 | * @return {Number} The column index |
---|
2977 | * @return {String|Number} The width in pixels |
---|
2978 | */ |
---|
2979 | getColumnWidth : function(column) { |
---|
2980 | var columnWidth = this.cm.getColumnWidth(column), |
---|
2981 | borderWidth = this.borderWidth; |
---|
2982 | |
---|
2983 | if (Ext.isNumber(columnWidth)) { |
---|
2984 | if (Ext.isBorderBox || (Ext.isWebKit && !Ext.isSafari2)) { |
---|
2985 | return columnWidth + "px"; |
---|
2986 | } else { |
---|
2987 | return Math.max(columnWidth - borderWidth, 0) + "px"; |
---|
2988 | } |
---|
2989 | } else { |
---|
2990 | return columnWidth; |
---|
2991 | } |
---|
2992 | }, |
---|
2993 | |
---|
2994 | /** |
---|
2995 | * @private |
---|
2996 | * Returns the total width of all visible columns |
---|
2997 | * @return {String} |
---|
2998 | */ |
---|
2999 | getTotalWidth : function() { |
---|
3000 | return this.cm.getTotalWidth() + 'px'; |
---|
3001 | }, |
---|
3002 | |
---|
3003 | /** |
---|
3004 | * @private |
---|
3005 | * Resizes each column to fit the available grid width. |
---|
3006 | * TODO: The second argument isn't even used, remove it in 4.0 |
---|
3007 | * @param {Boolean} preventRefresh True to prevent resizing of each row to the new column sizes (defaults to false) |
---|
3008 | * @param {null} onlyExpand NOT USED, will be removed in 4.0 |
---|
3009 | * @param {Number} omitColumn The index of a column to leave at its current width. Defaults to undefined |
---|
3010 | * @return {Boolean} True if the operation succeeded, false if not or undefined if the grid view is not yet initialized |
---|
3011 | */ |
---|
3012 | fitColumns : function(preventRefresh, onlyExpand, omitColumn) { |
---|
3013 | var grid = this.grid, |
---|
3014 | colModel = this.cm, |
---|
3015 | totalColWidth = colModel.getTotalWidth(false), |
---|
3016 | gridWidth = this.getGridInnerWidth(), |
---|
3017 | extraWidth = gridWidth - totalColWidth, |
---|
3018 | columns = [], |
---|
3019 | extraCol = 0, |
---|
3020 | width = 0, |
---|
3021 | colWidth, fraction, i; |
---|
3022 | |
---|
3023 | // not initialized, so don't screw up the default widths |
---|
3024 | if (gridWidth < 20 || extraWidth === 0) { |
---|
3025 | return false; |
---|
3026 | } |
---|
3027 | |
---|
3028 | var visibleColCount = colModel.getColumnCount(true), |
---|
3029 | totalColCount = colModel.getColumnCount(false), |
---|
3030 | adjCount = visibleColCount - (Ext.isNumber(omitColumn) ? 1 : 0); |
---|
3031 | |
---|
3032 | if (adjCount === 0) { |
---|
3033 | adjCount = 1; |
---|
3034 | omitColumn = undefined; |
---|
3035 | } |
---|
3036 | |
---|
3037 | //FIXME: the algorithm used here is odd and potentially confusing. Includes this for loop and the while after it. |
---|
3038 | for (i = 0; i < totalColCount; i++) { |
---|
3039 | if (!colModel.isFixed(i) && i !== omitColumn) { |
---|
3040 | colWidth = colModel.getColumnWidth(i); |
---|
3041 | columns.push(i, colWidth); |
---|
3042 | |
---|
3043 | if (!colModel.isHidden(i)) { |
---|
3044 | extraCol = i; |
---|
3045 | width += colWidth; |
---|
3046 | } |
---|
3047 | } |
---|
3048 | } |
---|
3049 | |
---|
3050 | fraction = (gridWidth - colModel.getTotalWidth()) / width; |
---|
3051 | |
---|
3052 | while (columns.length) { |
---|
3053 | colWidth = columns.pop(); |
---|
3054 | i = columns.pop(); |
---|
3055 | |
---|
3056 | colModel.setColumnWidth(i, Math.max(grid.minColumnWidth, Math.floor(colWidth + colWidth * fraction)), true); |
---|
3057 | } |
---|
3058 | |
---|
3059 | //this has been changed above so remeasure now |
---|
3060 | totalColWidth = colModel.getTotalWidth(false); |
---|
3061 | |
---|
3062 | if (totalColWidth > gridWidth) { |
---|
3063 | var adjustCol = (adjCount == visibleColCount) ? extraCol : omitColumn, |
---|
3064 | newWidth = Math.max(1, colModel.getColumnWidth(adjustCol) - (totalColWidth - gridWidth)); |
---|
3065 | |
---|
3066 | colModel.setColumnWidth(adjustCol, newWidth, true); |
---|
3067 | } |
---|
3068 | |
---|
3069 | if (preventRefresh !== true) { |
---|
3070 | this.updateAllColumnWidths(); |
---|
3071 | } |
---|
3072 | |
---|
3073 | return true; |
---|
3074 | }, |
---|
3075 | |
---|
3076 | /** |
---|
3077 | * @private |
---|
3078 | * Resizes the configured autoExpandColumn to take the available width after the other columns have |
---|
3079 | * been accounted for |
---|
3080 | * @param {Boolean} preventUpdate True to prevent the resizing of all rows (defaults to false) |
---|
3081 | */ |
---|
3082 | autoExpand : function(preventUpdate) { |
---|
3083 | var grid = this.grid, |
---|
3084 | colModel = this.cm, |
---|
3085 | gridWidth = this.getGridInnerWidth(), |
---|
3086 | totalColumnWidth = colModel.getTotalWidth(false), |
---|
3087 | autoExpandColumn = grid.autoExpandColumn; |
---|
3088 | |
---|
3089 | if (!this.userResized && autoExpandColumn) { |
---|
3090 | if (gridWidth != totalColumnWidth) { |
---|
3091 | //if we are not already using all available width, resize the autoExpandColumn |
---|
3092 | var colIndex = colModel.getIndexById(autoExpandColumn), |
---|
3093 | currentWidth = colModel.getColumnWidth(colIndex), |
---|
3094 | desiredWidth = gridWidth - totalColumnWidth + currentWidth, |
---|
3095 | newWidth = Math.min(Math.max(desiredWidth, grid.autoExpandMin), grid.autoExpandMax); |
---|
3096 | |
---|
3097 | if (currentWidth != newWidth) { |
---|
3098 | colModel.setColumnWidth(colIndex, newWidth, true); |
---|
3099 | |
---|
3100 | if (preventUpdate !== true) { |
---|
3101 | this.updateColumnWidth(colIndex, newWidth); |
---|
3102 | } |
---|
3103 | } |
---|
3104 | } |
---|
3105 | } |
---|
3106 | }, |
---|
3107 | |
---|
3108 | /** |
---|
3109 | * Returns the total internal width available to the grid, taking the scrollbar into account |
---|
3110 | * @return {Number} The total width |
---|
3111 | */ |
---|
3112 | getGridInnerWidth: function() { |
---|
3113 | return this.grid.getGridEl().getWidth(true) - this.getScrollOffset(); |
---|
3114 | }, |
---|
3115 | |
---|
3116 | /** |
---|
3117 | * @private |
---|
3118 | * Returns an array of column configurations - one for each column |
---|
3119 | * @return {Array} Array of column config objects. This includes the column name, renderer, id style and renderer |
---|
3120 | */ |
---|
3121 | getColumnData : function() { |
---|
3122 | var columns = [], |
---|
3123 | colModel = this.cm, |
---|
3124 | colCount = colModel.getColumnCount(), |
---|
3125 | fields = this.ds.fields, |
---|
3126 | i, name; |
---|
3127 | |
---|
3128 | for (i = 0; i < colCount; i++) { |
---|
3129 | name = colModel.getDataIndex(i); |
---|
3130 | |
---|
3131 | columns[i] = { |
---|
3132 | name : Ext.isDefined(name) ? name : (fields.get(i) ? fields.get(i).name : undefined), |
---|
3133 | renderer: colModel.getRenderer(i), |
---|
3134 | scope : colModel.getRendererScope(i), |
---|
3135 | id : colModel.getColumnId(i), |
---|
3136 | style : this.getColumnStyle(i) |
---|
3137 | }; |
---|
3138 | } |
---|
3139 | |
---|
3140 | return columns; |
---|
3141 | }, |
---|
3142 | |
---|
3143 | /** |
---|
3144 | * @private |
---|
3145 | * Renders rows between start and end indexes |
---|
3146 | * @param {Number} startRow Index of the first row to render |
---|
3147 | * @param {Number} endRow Index of the last row to render |
---|
3148 | */ |
---|
3149 | renderRows : function(startRow, endRow) { |
---|
3150 | var grid = this.grid, |
---|
3151 | store = grid.store, |
---|
3152 | stripe = grid.stripeRows, |
---|
3153 | colModel = grid.colModel, |
---|
3154 | colCount = colModel.getColumnCount(), |
---|
3155 | rowCount = store.getCount(), |
---|
3156 | records; |
---|
3157 | |
---|
3158 | if (rowCount < 1) { |
---|
3159 | return ''; |
---|
3160 | } |
---|
3161 | |
---|
3162 | startRow = startRow || 0; |
---|
3163 | endRow = Ext.isDefined(endRow) ? endRow : rowCount - 1; |
---|
3164 | records = store.getRange(startRow, endRow); |
---|
3165 | |
---|
3166 | return this.doRender(this.getColumnData(), records, store, startRow, colCount, stripe); |
---|
3167 | }, |
---|
3168 | |
---|
3169 | // private |
---|
3170 | renderBody : function(){ |
---|
3171 | var markup = this.renderRows() || ' '; |
---|
3172 | return this.templates.body.apply({rows: markup}); |
---|
3173 | }, |
---|
3174 | |
---|
3175 | /** |
---|
3176 | * @private |
---|
3177 | * Refreshes a row by re-rendering it. Fires the rowupdated event when done |
---|
3178 | */ |
---|
3179 | refreshRow: function(record) { |
---|
3180 | var store = this.ds, |
---|
3181 | colCount = this.cm.getColumnCount(), |
---|
3182 | columns = this.getColumnData(), |
---|
3183 | last = colCount - 1, |
---|
3184 | cls = ['x-grid3-row'], |
---|
3185 | rowParams = { |
---|
3186 | tstyle: String.format("width: {0};", this.getTotalWidth()) |
---|
3187 | }, |
---|
3188 | colBuffer = [], |
---|
3189 | cellTpl = this.templates.cell, |
---|
3190 | rowIndex, row, column, meta, css, i; |
---|
3191 | |
---|
3192 | if (Ext.isNumber(record)) { |
---|
3193 | rowIndex = record; |
---|
3194 | record = store.getAt(rowIndex); |
---|
3195 | } else { |
---|
3196 | rowIndex = store.indexOf(record); |
---|
3197 | } |
---|
3198 | |
---|
3199 | //the record could not be found |
---|
3200 | if (!record || rowIndex < 0) { |
---|
3201 | return; |
---|
3202 | } |
---|
3203 | |
---|
3204 | //builds each column in this row |
---|
3205 | for (i = 0; i < colCount; i++) { |
---|
3206 | column = columns[i]; |
---|
3207 | |
---|
3208 | if (i == 0) { |
---|
3209 | css = 'x-grid3-cell-first'; |
---|
3210 | } else { |
---|
3211 | css = (i == last) ? 'x-grid3-cell-last ' : ''; |
---|
3212 | } |
---|
3213 | |
---|
3214 | meta = { |
---|
3215 | id : column.id, |
---|
3216 | style : column.style, |
---|
3217 | css : css, |
---|
3218 | attr : "", |
---|
3219 | cellAttr: "" |
---|
3220 | }; |
---|
3221 | // Need to set this after, because we pass meta to the renderer |
---|
3222 | meta.value = column.renderer.call(column.scope, record.data[column.name], meta, record, rowIndex, i, store); |
---|
3223 | |
---|
3224 | if (Ext.isEmpty(meta.value)) { |
---|
3225 | meta.value = ' '; |
---|
3226 | } |
---|
3227 | |
---|
3228 | if (this.markDirty && record.dirty && typeof record.modified[column.name] != 'undefined') { |
---|
3229 | meta.css += ' x-grid3-dirty-cell'; |
---|
3230 | } |
---|
3231 | |
---|
3232 | colBuffer[i] = cellTpl.apply(meta); |
---|
3233 | } |
---|
3234 | |
---|
3235 | row = this.getRow(rowIndex); |
---|
3236 | row.className = ''; |
---|
3237 | |
---|
3238 | if (this.grid.stripeRows && ((rowIndex + 1) % 2 === 0)) { |
---|
3239 | cls.push('x-grid3-row-alt'); |
---|
3240 | } |
---|
3241 | |
---|
3242 | if (this.getRowClass) { |
---|
3243 | rowParams.cols = colCount; |
---|
3244 | cls.push(this.getRowClass(record, rowIndex, rowParams, store)); |
---|
3245 | } |
---|
3246 | |
---|
3247 | this.fly(row).addClass(cls).setStyle(rowParams.tstyle); |
---|
3248 | rowParams.cells = colBuffer.join(""); |
---|
3249 | row.innerHTML = this.templates.rowInner.apply(rowParams); |
---|
3250 | |
---|
3251 | this.fireEvent('rowupdated', this, rowIndex, record); |
---|
3252 | }, |
---|
3253 | |
---|
3254 | /** |
---|
3255 | * Refreshs the grid UI |
---|
3256 | * @param {Boolean} headersToo (optional) True to also refresh the headers |
---|
3257 | */ |
---|
3258 | refresh : function(headersToo) { |
---|
3259 | this.fireEvent('beforerefresh', this); |
---|
3260 | this.grid.stopEditing(true); |
---|
3261 | |
---|
3262 | var result = this.renderBody(); |
---|
3263 | this.mainBody.update(result).setWidth(this.getTotalWidth()); |
---|
3264 | if (headersToo === true) { |
---|
3265 | this.updateHeaders(); |
---|
3266 | this.updateHeaderSortState(); |
---|
3267 | } |
---|
3268 | this.processRows(0, true); |
---|
3269 | this.layout(); |
---|
3270 | this.applyEmptyText(); |
---|
3271 | this.fireEvent('refresh', this); |
---|
3272 | }, |
---|
3273 | |
---|
3274 | /** |
---|
3275 | * @private |
---|
3276 | * Displays the configured emptyText if there are currently no rows to display |
---|
3277 | */ |
---|
3278 | applyEmptyText : function() { |
---|
3279 | if (this.emptyText && !this.hasRows()) { |
---|
3280 | this.mainBody.update('<div class="x-grid-empty">' + this.emptyText + '</div>'); |
---|
3281 | } |
---|
3282 | }, |
---|
3283 | |
---|
3284 | /** |
---|
3285 | * @private |
---|
3286 | * Adds sorting classes to the column headers based on the bound store's sortInfo. Fires the 'sortchange' event |
---|
3287 | * if the sorting has changed since this function was last run. |
---|
3288 | */ |
---|
3289 | updateHeaderSortState : function() { |
---|
3290 | var state = this.ds.getSortState(); |
---|
3291 | if (!state) { |
---|
3292 | return; |
---|
3293 | } |
---|
3294 | |
---|
3295 | if (!this.sortState || (this.sortState.field != state.field || this.sortState.direction != state.direction)) { |
---|
3296 | this.grid.fireEvent('sortchange', this.grid, state); |
---|
3297 | } |
---|
3298 | |
---|
3299 | this.sortState = state; |
---|
3300 | |
---|
3301 | var sortColumn = this.cm.findColumnIndex(state.field); |
---|
3302 | if (sortColumn != -1) { |
---|
3303 | var sortDir = state.direction; |
---|
3304 | this.updateSortIcon(sortColumn, sortDir); |
---|
3305 | } |
---|
3306 | }, |
---|
3307 | |
---|
3308 | /** |
---|
3309 | * @private |
---|
3310 | * Removes any sorting indicator classes from the column headers |
---|
3311 | */ |
---|
3312 | clearHeaderSortState : function() { |
---|
3313 | if (!this.sortState) { |
---|
3314 | return; |
---|
3315 | } |
---|
3316 | this.grid.fireEvent('sortchange', this.grid, null); |
---|
3317 | this.mainHd.select('td').removeClass(this.sortClasses); |
---|
3318 | delete this.sortState; |
---|
3319 | }, |
---|
3320 | |
---|
3321 | /** |
---|
3322 | * @private |
---|
3323 | * Destroys all objects associated with the GridView |
---|
3324 | */ |
---|
3325 | destroy : function() { |
---|
3326 | var me = this, |
---|
3327 | grid = me.grid, |
---|
3328 | gridEl = grid.getGridEl(), |
---|
3329 | dragZone = me.dragZone, |
---|
3330 | splitZone = me.splitZone, |
---|
3331 | columnDrag = me.columnDrag, |
---|
3332 | columnDrop = me.columnDrop, |
---|
3333 | scrollToTopTask = me.scrollToTopTask, |
---|
3334 | columnDragData, |
---|
3335 | columnDragProxy; |
---|
3336 | |
---|
3337 | if (scrollToTopTask && scrollToTopTask.cancel) { |
---|
3338 | scrollToTopTask.cancel(); |
---|
3339 | } |
---|
3340 | |
---|
3341 | Ext.destroyMembers(me, 'colMenu', 'hmenu'); |
---|
3342 | |
---|
3343 | me.initData(null, null); |
---|
3344 | me.purgeListeners(); |
---|
3345 | |
---|
3346 | Ext.fly(me.innerHd).un("click", me.handleHdDown, me); |
---|
3347 | |
---|
3348 | if (grid.enableColumnMove) { |
---|
3349 | columnDragData = columnDrag.dragData; |
---|
3350 | columnDragProxy = columnDrag.proxy; |
---|
3351 | Ext.destroy( |
---|
3352 | columnDrag.el, |
---|
3353 | columnDragProxy.ghost, |
---|
3354 | columnDragProxy.el, |
---|
3355 | columnDrop.el, |
---|
3356 | columnDrop.proxyTop, |
---|
3357 | columnDrop.proxyBottom, |
---|
3358 | columnDragData.ddel, |
---|
3359 | columnDragData.header |
---|
3360 | ); |
---|
3361 | |
---|
3362 | if (columnDragProxy.anim) { |
---|
3363 | Ext.destroy(columnDragProxy.anim); |
---|
3364 | } |
---|
3365 | |
---|
3366 | delete columnDragProxy.ghost; |
---|
3367 | delete columnDragData.ddel; |
---|
3368 | delete columnDragData.header; |
---|
3369 | columnDrag.destroy(); |
---|
3370 | |
---|
3371 | delete Ext.dd.DDM.locationCache[columnDrag.id]; |
---|
3372 | delete columnDrag._domRef; |
---|
3373 | |
---|
3374 | delete columnDrop.proxyTop; |
---|
3375 | delete columnDrop.proxyBottom; |
---|
3376 | columnDrop.destroy(); |
---|
3377 | delete Ext.dd.DDM.locationCache["gridHeader" + gridEl.id]; |
---|
3378 | delete columnDrop._domRef; |
---|
3379 | delete Ext.dd.DDM.ids[columnDrop.ddGroup]; |
---|
3380 | } |
---|
3381 | |
---|
3382 | if (splitZone) { // enableColumnResize |
---|
3383 | splitZone.destroy(); |
---|
3384 | delete splitZone._domRef; |
---|
3385 | delete Ext.dd.DDM.ids["gridSplitters" + gridEl.id]; |
---|
3386 | } |
---|
3387 | |
---|
3388 | Ext.fly(me.innerHd).removeAllListeners(); |
---|
3389 | Ext.removeNode(me.innerHd); |
---|
3390 | delete me.innerHd; |
---|
3391 | |
---|
3392 | Ext.destroy( |
---|
3393 | me.el, |
---|
3394 | me.mainWrap, |
---|
3395 | me.mainHd, |
---|
3396 | me.scroller, |
---|
3397 | me.mainBody, |
---|
3398 | me.focusEl, |
---|
3399 | me.resizeMarker, |
---|
3400 | me.resizeProxy, |
---|
3401 | me.activeHdBtn, |
---|
3402 | me._flyweight, |
---|
3403 | dragZone, |
---|
3404 | splitZone |
---|
3405 | ); |
---|
3406 | |
---|
3407 | delete grid.container; |
---|
3408 | |
---|
3409 | if (dragZone) { |
---|
3410 | dragZone.destroy(); |
---|
3411 | } |
---|
3412 | |
---|
3413 | Ext.dd.DDM.currentTarget = null; |
---|
3414 | delete Ext.dd.DDM.locationCache[gridEl.id]; |
---|
3415 | |
---|
3416 | Ext.EventManager.removeResizeListener(me.onWindowResize, me); |
---|
3417 | }, |
---|
3418 | |
---|
3419 | // private |
---|
3420 | onDenyColumnHide : function() { |
---|
3421 | |
---|
3422 | }, |
---|
3423 | |
---|
3424 | // private |
---|
3425 | render : function() { |
---|
3426 | if (this.autoFill) { |
---|
3427 | var ct = this.grid.ownerCt; |
---|
3428 | |
---|
3429 | if (ct && ct.getLayout()) { |
---|
3430 | ct.on('afterlayout', function() { |
---|
3431 | this.fitColumns(true, true); |
---|
3432 | this.updateHeaders(); |
---|
3433 | this.updateHeaderSortState(); |
---|
3434 | }, this, {single: true}); |
---|
3435 | } |
---|
3436 | } else if (this.forceFit) { |
---|
3437 | this.fitColumns(true, false); |
---|
3438 | } else if (this.grid.autoExpandColumn) { |
---|
3439 | this.autoExpand(true); |
---|
3440 | } |
---|
3441 | |
---|
3442 | this.grid.getGridEl().dom.innerHTML = this.renderUI(); |
---|
3443 | |
---|
3444 | this.afterRenderUI(); |
---|
3445 | }, |
---|
3446 | |
---|
3447 | /* --------------------------------- Model Events and Handlers --------------------------------*/ |
---|
3448 | |
---|
3449 | /** |
---|
3450 | * @private |
---|
3451 | * Binds a new Store and ColumnModel to this GridView. Removes any listeners from the old objects (if present) |
---|
3452 | * and adds listeners to the new ones |
---|
3453 | * @param {Ext.data.Store} newStore The new Store instance |
---|
3454 | * @param {Ext.grid.ColumnModel} newColModel The new ColumnModel instance |
---|
3455 | */ |
---|
3456 | initData : function(newStore, newColModel) { |
---|
3457 | var me = this; |
---|
3458 | |
---|
3459 | if (me.ds) { |
---|
3460 | var oldStore = me.ds; |
---|
3461 | |
---|
3462 | oldStore.un('add', me.onAdd, me); |
---|
3463 | oldStore.un('load', me.onLoad, me); |
---|
3464 | oldStore.un('clear', me.onClear, me); |
---|
3465 | oldStore.un('remove', me.onRemove, me); |
---|
3466 | oldStore.un('update', me.onUpdate, me); |
---|
3467 | oldStore.un('datachanged', me.onDataChange, me); |
---|
3468 | |
---|
3469 | if (oldStore !== newStore && oldStore.autoDestroy) { |
---|
3470 | oldStore.destroy(); |
---|
3471 | } |
---|
3472 | } |
---|
3473 | |
---|
3474 | if (newStore) { |
---|
3475 | newStore.on({ |
---|
3476 | scope : me, |
---|
3477 | load : me.onLoad, |
---|
3478 | add : me.onAdd, |
---|
3479 | remove : me.onRemove, |
---|
3480 | update : me.onUpdate, |
---|
3481 | clear : me.onClear, |
---|
3482 | datachanged: me.onDataChange |
---|
3483 | }); |
---|
3484 | } |
---|
3485 | |
---|
3486 | if (me.cm) { |
---|
3487 | var oldColModel = me.cm; |
---|
3488 | |
---|
3489 | oldColModel.un('configchange', me.onColConfigChange, me); |
---|
3490 | oldColModel.un('widthchange', me.onColWidthChange, me); |
---|
3491 | oldColModel.un('headerchange', me.onHeaderChange, me); |
---|
3492 | oldColModel.un('hiddenchange', me.onHiddenChange, me); |
---|
3493 | oldColModel.un('columnmoved', me.onColumnMove, me); |
---|
3494 | } |
---|
3495 | |
---|
3496 | if (newColModel) { |
---|
3497 | delete me.lastViewWidth; |
---|
3498 | |
---|
3499 | newColModel.on({ |
---|
3500 | scope : me, |
---|
3501 | configchange: me.onColConfigChange, |
---|
3502 | widthchange : me.onColWidthChange, |
---|
3503 | headerchange: me.onHeaderChange, |
---|
3504 | hiddenchange: me.onHiddenChange, |
---|
3505 | columnmoved : me.onColumnMove |
---|
3506 | }); |
---|
3507 | } |
---|
3508 | |
---|
3509 | me.ds = newStore; |
---|
3510 | me.cm = newColModel; |
---|
3511 | }, |
---|
3512 | |
---|
3513 | // private |
---|
3514 | onDataChange : function(){ |
---|
3515 | this.refresh(true); |
---|
3516 | this.updateHeaderSortState(); |
---|
3517 | this.syncFocusEl(0); |
---|
3518 | }, |
---|
3519 | |
---|
3520 | // private |
---|
3521 | onClear : function() { |
---|
3522 | this.refresh(); |
---|
3523 | this.syncFocusEl(0); |
---|
3524 | }, |
---|
3525 | |
---|
3526 | // private |
---|
3527 | onUpdate : function(store, record) { |
---|
3528 | this.refreshRow(record); |
---|
3529 | }, |
---|
3530 | |
---|
3531 | // private |
---|
3532 | onAdd : function(store, records, index) { |
---|
3533 | this.insertRows(store, index, index + (records.length-1)); |
---|
3534 | }, |
---|
3535 | |
---|
3536 | // private |
---|
3537 | onRemove : function(store, record, index, isUpdate) { |
---|
3538 | if (isUpdate !== true) { |
---|
3539 | this.fireEvent('beforerowremoved', this, index, record); |
---|
3540 | } |
---|
3541 | |
---|
3542 | this.removeRow(index); |
---|
3543 | |
---|
3544 | if (isUpdate !== true) { |
---|
3545 | this.processRows(index); |
---|
3546 | this.applyEmptyText(); |
---|
3547 | this.fireEvent('rowremoved', this, index, record); |
---|
3548 | } |
---|
3549 | }, |
---|
3550 | |
---|
3551 | /** |
---|
3552 | * @private |
---|
3553 | * Called when a store is loaded, scrolls to the top row |
---|
3554 | */ |
---|
3555 | onLoad : function() { |
---|
3556 | if (Ext.isGecko) { |
---|
3557 | if (!this.scrollToTopTask) { |
---|
3558 | this.scrollToTopTask = new Ext.util.DelayedTask(this.scrollToTop, this); |
---|
3559 | } |
---|
3560 | this.scrollToTopTask.delay(1); |
---|
3561 | } else { |
---|
3562 | this.scrollToTop(); |
---|
3563 | } |
---|
3564 | }, |
---|
3565 | |
---|
3566 | // private |
---|
3567 | onColWidthChange : function(cm, col, width) { |
---|
3568 | this.updateColumnWidth(col, width); |
---|
3569 | }, |
---|
3570 | |
---|
3571 | // private |
---|
3572 | onHeaderChange : function(cm, col, text) { |
---|
3573 | this.updateHeaders(); |
---|
3574 | }, |
---|
3575 | |
---|
3576 | // private |
---|
3577 | onHiddenChange : function(cm, col, hidden) { |
---|
3578 | this.updateColumnHidden(col, hidden); |
---|
3579 | }, |
---|
3580 | |
---|
3581 | // private |
---|
3582 | onColumnMove : function(cm, oldIndex, newIndex) { |
---|
3583 | this.indexMap = null; |
---|
3584 | this.refresh(true); |
---|
3585 | this.restoreScroll(this.getScrollState()); |
---|
3586 | |
---|
3587 | this.afterMove(newIndex); |
---|
3588 | this.grid.fireEvent('columnmove', oldIndex, newIndex); |
---|
3589 | }, |
---|
3590 | |
---|
3591 | // private |
---|
3592 | onColConfigChange : function() { |
---|
3593 | delete this.lastViewWidth; |
---|
3594 | this.indexMap = null; |
---|
3595 | this.refresh(true); |
---|
3596 | }, |
---|
3597 | |
---|
3598 | /* -------------------- UI Events and Handlers ------------------------------ */ |
---|
3599 | // private |
---|
3600 | initUI : function(grid) { |
---|
3601 | grid.on('headerclick', this.onHeaderClick, this); |
---|
3602 | }, |
---|
3603 | |
---|
3604 | // private |
---|
3605 | initEvents : Ext.emptyFn, |
---|
3606 | |
---|
3607 | // private |
---|
3608 | onHeaderClick : function(g, index) { |
---|
3609 | if (this.headersDisabled || !this.cm.isSortable(index)) { |
---|
3610 | return; |
---|
3611 | } |
---|
3612 | g.stopEditing(true); |
---|
3613 | g.store.sort(this.cm.getDataIndex(index)); |
---|
3614 | }, |
---|
3615 | |
---|
3616 | /** |
---|
3617 | * @private |
---|
3618 | * Adds the hover class to a row when hovered over |
---|
3619 | */ |
---|
3620 | onRowOver : function(e, target) { |
---|
3621 | var row = this.findRowIndex(target); |
---|
3622 | |
---|
3623 | if (row !== false) { |
---|
3624 | this.addRowClass(row, this.rowOverCls); |
---|
3625 | } |
---|
3626 | }, |
---|
3627 | |
---|
3628 | /** |
---|
3629 | * @private |
---|
3630 | * Removes the hover class from a row on mouseout |
---|
3631 | */ |
---|
3632 | onRowOut : function(e, target) { |
---|
3633 | var row = this.findRowIndex(target); |
---|
3634 | |
---|
3635 | if (row !== false && !e.within(this.getRow(row), true)) { |
---|
3636 | this.removeRowClass(row, this.rowOverCls); |
---|
3637 | } |
---|
3638 | }, |
---|
3639 | |
---|
3640 | // private |
---|
3641 | onRowSelect : function(row) { |
---|
3642 | this.addRowClass(row, this.selectedRowClass); |
---|
3643 | }, |
---|
3644 | |
---|
3645 | // private |
---|
3646 | onRowDeselect : function(row) { |
---|
3647 | this.removeRowClass(row, this.selectedRowClass); |
---|
3648 | }, |
---|
3649 | |
---|
3650 | // private |
---|
3651 | onCellSelect : function(row, col) { |
---|
3652 | var cell = this.getCell(row, col); |
---|
3653 | if (cell) { |
---|
3654 | this.fly(cell).addClass('x-grid3-cell-selected'); |
---|
3655 | } |
---|
3656 | }, |
---|
3657 | |
---|
3658 | // private |
---|
3659 | onCellDeselect : function(row, col) { |
---|
3660 | var cell = this.getCell(row, col); |
---|
3661 | if (cell) { |
---|
3662 | this.fly(cell).removeClass('x-grid3-cell-selected'); |
---|
3663 | } |
---|
3664 | }, |
---|
3665 | |
---|
3666 | // private |
---|
3667 | handleWheel : function(e) { |
---|
3668 | e.stopPropagation(); |
---|
3669 | }, |
---|
3670 | |
---|
3671 | /** |
---|
3672 | * @private |
---|
3673 | * Called by the SplitDragZone when a drag has been completed. Resizes the columns |
---|
3674 | */ |
---|
3675 | onColumnSplitterMoved : function(cellIndex, width) { |
---|
3676 | this.userResized = true; |
---|
3677 | this.grid.colModel.setColumnWidth(cellIndex, width, true); |
---|
3678 | |
---|
3679 | if (this.forceFit) { |
---|
3680 | this.fitColumns(true, false, cellIndex); |
---|
3681 | this.updateAllColumnWidths(); |
---|
3682 | } else { |
---|
3683 | this.updateColumnWidth(cellIndex, width); |
---|
3684 | this.syncHeaderScroll(); |
---|
3685 | } |
---|
3686 | |
---|
3687 | this.grid.fireEvent('columnresize', cellIndex, width); |
---|
3688 | }, |
---|
3689 | |
---|
3690 | /** |
---|
3691 | * @private |
---|
3692 | * Click handler for the shared column dropdown menu, called on beforeshow. Builds the menu |
---|
3693 | * which displays the list of columns for the user to show or hide. |
---|
3694 | */ |
---|
3695 | beforeColMenuShow : function() { |
---|
3696 | var colModel = this.cm, |
---|
3697 | colCount = colModel.getColumnCount(), |
---|
3698 | colMenu = this.colMenu, |
---|
3699 | i; |
---|
3700 | |
---|
3701 | colMenu.removeAll(); |
---|
3702 | |
---|
3703 | for (i = 0; i < colCount; i++) { |
---|
3704 | if (colModel.config[i].hideable !== false) { |
---|
3705 | colMenu.add(new Ext.menu.CheckItem({ |
---|
3706 | text : colModel.getColumnHeader(i), |
---|
3707 | itemId : 'col-' + colModel.getColumnId(i), |
---|
3708 | checked : !colModel.isHidden(i), |
---|
3709 | disabled : colModel.config[i].hideable === false, |
---|
3710 | hideOnClick: false |
---|
3711 | })); |
---|
3712 | } |
---|
3713 | } |
---|
3714 | }, |
---|
3715 | |
---|
3716 | /** |
---|
3717 | * @private |
---|
3718 | * Attached as the 'itemclick' handler to the header menu and the column show/hide submenu (if available). |
---|
3719 | * Performs sorting if the sorter buttons were clicked, otherwise hides/shows the column that was clicked. |
---|
3720 | */ |
---|
3721 | handleHdMenuClick : function(item) { |
---|
3722 | var store = this.ds, |
---|
3723 | dataIndex = this.cm.getDataIndex(this.hdCtxIndex); |
---|
3724 | |
---|
3725 | switch (item.getItemId()) { |
---|
3726 | case 'asc': |
---|
3727 | store.sort(dataIndex, 'ASC'); |
---|
3728 | break; |
---|
3729 | case 'desc': |
---|
3730 | store.sort(dataIndex, 'DESC'); |
---|
3731 | break; |
---|
3732 | default: |
---|
3733 | this.handleHdMenuClickDefault(item); |
---|
3734 | } |
---|
3735 | return true; |
---|
3736 | }, |
---|
3737 | |
---|
3738 | /** |
---|
3739 | * Called by handleHdMenuClick if any button except a sort ASC/DESC button was clicked. The default implementation provides |
---|
3740 | * the column hide/show functionality based on the check state of the menu item. A different implementation can be provided |
---|
3741 | * if needed. |
---|
3742 | * @param {Ext.menu.BaseItem} item The menu item that was clicked |
---|
3743 | */ |
---|
3744 | handleHdMenuClickDefault: function(item) { |
---|
3745 | var colModel = this.cm, |
---|
3746 | itemId = item.getItemId(), |
---|
3747 | index = colModel.getIndexById(itemId.substr(4)); |
---|
3748 | |
---|
3749 | if (index != -1) { |
---|
3750 | if (item.checked && colModel.getColumnsBy(this.isHideableColumn, this).length <= 1) { |
---|
3751 | this.onDenyColumnHide(); |
---|
3752 | return; |
---|
3753 | } |
---|
3754 | colModel.setHidden(index, item.checked); |
---|
3755 | } |
---|
3756 | }, |
---|
3757 | |
---|
3758 | /** |
---|
3759 | * @private |
---|
3760 | * Called when a header cell is clicked - shows the menu if the click happened over a trigger button |
---|
3761 | */ |
---|
3762 | handleHdDown : function(e, target) { |
---|
3763 | if (Ext.fly(target).hasClass('x-grid3-hd-btn')) { |
---|
3764 | e.stopEvent(); |
---|
3765 | |
---|
3766 | var colModel = this.cm, |
---|
3767 | header = this.findHeaderCell(target), |
---|
3768 | index = this.getCellIndex(header), |
---|
3769 | sortable = colModel.isSortable(index), |
---|
3770 | menu = this.hmenu, |
---|
3771 | menuItems = menu.items, |
---|
3772 | menuCls = this.headerMenuOpenCls; |
---|
3773 | |
---|
3774 | this.hdCtxIndex = index; |
---|
3775 | |
---|
3776 | Ext.fly(header).addClass(menuCls); |
---|
3777 | menuItems.get('asc').setDisabled(!sortable); |
---|
3778 | menuItems.get('desc').setDisabled(!sortable); |
---|
3779 | |
---|
3780 | menu.on('hide', function() { |
---|
3781 | Ext.fly(header).removeClass(menuCls); |
---|
3782 | }, this, {single:true}); |
---|
3783 | |
---|
3784 | menu.show(target, 'tl-bl?'); |
---|
3785 | } |
---|
3786 | }, |
---|
3787 | |
---|
3788 | /** |
---|
3789 | * @private |
---|
3790 | * Attached to the headers' mousemove event. This figures out the CSS cursor to use based on where the mouse is currently |
---|
3791 | * pointed. If the mouse is currently hovered over the extreme left or extreme right of any header cell and the cell next |
---|
3792 | * to it is resizable it is given the resize cursor, otherwise the cursor is set to an empty string. |
---|
3793 | */ |
---|
3794 | handleHdMove : function(e) { |
---|
3795 | var header = this.findHeaderCell(this.activeHdRef); |
---|
3796 | |
---|
3797 | if (header && !this.headersDisabled) { |
---|
3798 | var handleWidth = this.splitHandleWidth || 5, |
---|
3799 | activeRegion = this.activeHdRegion, |
---|
3800 | headerStyle = header.style, |
---|
3801 | colModel = this.cm, |
---|
3802 | cursor = '', |
---|
3803 | pageX = e.getPageX(); |
---|
3804 | |
---|
3805 | if (this.grid.enableColumnResize !== false) { |
---|
3806 | var activeHeaderIndex = this.activeHdIndex, |
---|
3807 | previousVisible = this.getPreviousVisible(activeHeaderIndex), |
---|
3808 | currentResizable = colModel.isResizable(activeHeaderIndex), |
---|
3809 | previousResizable = previousVisible && colModel.isResizable(previousVisible), |
---|
3810 | inLeftResizer = pageX - activeRegion.left <= handleWidth, |
---|
3811 | inRightResizer = activeRegion.right - pageX <= (!this.activeHdBtn ? handleWidth : 2); |
---|
3812 | |
---|
3813 | if (inLeftResizer && previousResizable) { |
---|
3814 | cursor = Ext.isAir ? 'move' : Ext.isWebKit ? 'e-resize' : 'col-resize'; // col-resize not always supported |
---|
3815 | } else if (inRightResizer && currentResizable) { |
---|
3816 | cursor = Ext.isAir ? 'move' : Ext.isWebKit ? 'w-resize' : 'col-resize'; |
---|
3817 | } |
---|
3818 | } |
---|
3819 | |
---|
3820 | headerStyle.cursor = cursor; |
---|
3821 | } |
---|
3822 | }, |
---|
3823 | |
---|
3824 | /** |
---|
3825 | * @private |
---|
3826 | * Returns the index of the nearest currently visible header to the left of the given index. |
---|
3827 | * @param {Number} index The header index |
---|
3828 | * @return {Number/undefined} The index of the nearest visible header |
---|
3829 | */ |
---|
3830 | getPreviousVisible: function(index) { |
---|
3831 | while (index > 0) { |
---|
3832 | if (!this.cm.isHidden(index - 1)) { |
---|
3833 | return index; |
---|
3834 | } |
---|
3835 | index--; |
---|
3836 | } |
---|
3837 | return undefined; |
---|
3838 | }, |
---|
3839 | |
---|
3840 | /** |
---|
3841 | * @private |
---|
3842 | * Tied to the header element's mouseover event - adds the over class to the header cell if the menu is not disabled |
---|
3843 | * for that cell |
---|
3844 | */ |
---|
3845 | handleHdOver : function(e, target) { |
---|
3846 | var header = this.findHeaderCell(target); |
---|
3847 | |
---|
3848 | if (header && !this.headersDisabled) { |
---|
3849 | var fly = this.fly(header); |
---|
3850 | |
---|
3851 | this.activeHdRef = target; |
---|
3852 | this.activeHdIndex = this.getCellIndex(header); |
---|
3853 | this.activeHdRegion = fly.getRegion(); |
---|
3854 | |
---|
3855 | if (!this.isMenuDisabled(this.activeHdIndex, fly)) { |
---|
3856 | fly.addClass('x-grid3-hd-over'); |
---|
3857 | this.activeHdBtn = fly.child('.x-grid3-hd-btn'); |
---|
3858 | |
---|
3859 | if (this.activeHdBtn) { |
---|
3860 | this.activeHdBtn.dom.style.height = (header.firstChild.offsetHeight - 1) + 'px'; |
---|
3861 | } |
---|
3862 | } |
---|
3863 | } |
---|
3864 | }, |
---|
3865 | |
---|
3866 | /** |
---|
3867 | * @private |
---|
3868 | * Tied to the header element's mouseout event. Removes the hover class from the header cell |
---|
3869 | */ |
---|
3870 | handleHdOut : function(e, target) { |
---|
3871 | var header = this.findHeaderCell(target); |
---|
3872 | |
---|
3873 | if (header && (!Ext.isIE || !e.within(header, true))) { |
---|
3874 | this.activeHdRef = null; |
---|
3875 | this.fly(header).removeClass('x-grid3-hd-over'); |
---|
3876 | header.style.cursor = ''; |
---|
3877 | } |
---|
3878 | }, |
---|
3879 | |
---|
3880 | /** |
---|
3881 | * @private |
---|
3882 | * Used by {@link #handleHdOver} to determine whether or not to show the header menu class on cell hover |
---|
3883 | * @param {Number} cellIndex The header cell index |
---|
3884 | * @param {Ext.Element} el The cell element currently being hovered over |
---|
3885 | */ |
---|
3886 | isMenuDisabled: function(cellIndex, el) { |
---|
3887 | return this.cm.isMenuDisabled(cellIndex); |
---|
3888 | }, |
---|
3889 | |
---|
3890 | /** |
---|
3891 | * @private |
---|
3892 | * Returns true if there are any rows rendered into the GridView |
---|
3893 | * @return {Boolean} True if any rows have been rendered |
---|
3894 | */ |
---|
3895 | hasRows : function() { |
---|
3896 | var fc = this.mainBody.dom.firstChild; |
---|
3897 | return fc && fc.nodeType == 1 && fc.className != 'x-grid-empty'; |
---|
3898 | }, |
---|
3899 | |
---|
3900 | /** |
---|
3901 | * @private |
---|
3902 | */ |
---|
3903 | isHideableColumn : function(c) { |
---|
3904 | return !c.hidden; |
---|
3905 | }, |
---|
3906 | |
---|
3907 | /** |
---|
3908 | * @private |
---|
3909 | * DEPRECATED - will be removed in Ext JS 5.0 |
---|
3910 | */ |
---|
3911 | bind : function(d, c) { |
---|
3912 | this.initData(d, c); |
---|
3913 | } |
---|
3914 | }); |
---|
3915 | |
---|
3916 | |
---|
3917 | // private |
---|
3918 | // This is a support class used internally by the Grid components |
---|
3919 | Ext.grid.GridView.SplitDragZone = Ext.extend(Ext.dd.DDProxy, { |
---|
3920 | |
---|
3921 | constructor: function(grid, hd){ |
---|
3922 | this.grid = grid; |
---|
3923 | this.view = grid.getView(); |
---|
3924 | this.marker = this.view.resizeMarker; |
---|
3925 | this.proxy = this.view.resizeProxy; |
---|
3926 | Ext.grid.GridView.SplitDragZone.superclass.constructor.call(this, hd, |
---|
3927 | 'gridSplitters' + this.grid.getGridEl().id, { |
---|
3928 | dragElId : Ext.id(this.proxy.dom), resizeFrame:false |
---|
3929 | }); |
---|
3930 | this.scroll = false; |
---|
3931 | this.hw = this.view.splitHandleWidth || 5; |
---|
3932 | }, |
---|
3933 | |
---|
3934 | b4StartDrag : function(x, y){ |
---|
3935 | this.dragHeadersDisabled = this.view.headersDisabled; |
---|
3936 | this.view.headersDisabled = true; |
---|
3937 | var h = this.view.mainWrap.getHeight(); |
---|
3938 | this.marker.setHeight(h); |
---|
3939 | this.marker.show(); |
---|
3940 | this.marker.alignTo(this.view.getHeaderCell(this.cellIndex), 'tl-tl', [-2, 0]); |
---|
3941 | this.proxy.setHeight(h); |
---|
3942 | var w = this.cm.getColumnWidth(this.cellIndex), |
---|
3943 | minw = Math.max(w-this.grid.minColumnWidth, 0); |
---|
3944 | this.resetConstraints(); |
---|
3945 | this.setXConstraint(minw, 1000); |
---|
3946 | this.setYConstraint(0, 0); |
---|
3947 | this.minX = x - minw; |
---|
3948 | this.maxX = x + 1000; |
---|
3949 | this.startPos = x; |
---|
3950 | Ext.dd.DDProxy.prototype.b4StartDrag.call(this, x, y); |
---|
3951 | }, |
---|
3952 | |
---|
3953 | allowHeaderDrag : function(e){ |
---|
3954 | return true; |
---|
3955 | }, |
---|
3956 | |
---|
3957 | handleMouseDown : function(e){ |
---|
3958 | var t = this.view.findHeaderCell(e.getTarget()); |
---|
3959 | if(t && this.allowHeaderDrag(e)){ |
---|
3960 | var xy = this.view.fly(t).getXY(), |
---|
3961 | x = xy[0], |
---|
3962 | exy = e.getXY(), |
---|
3963 | ex = exy[0], |
---|
3964 | w = t.offsetWidth, |
---|
3965 | adjust = false; |
---|
3966 | |
---|
3967 | if((ex - x) <= this.hw){ |
---|
3968 | adjust = -1; |
---|
3969 | }else if((x+w) - ex <= this.hw){ |
---|
3970 | adjust = 0; |
---|
3971 | } |
---|
3972 | if(adjust !== false){ |
---|
3973 | this.cm = this.grid.colModel; |
---|
3974 | var ci = this.view.getCellIndex(t); |
---|
3975 | if(adjust == -1){ |
---|
3976 | if (ci + adjust < 0) { |
---|
3977 | return; |
---|
3978 | } |
---|
3979 | while(this.cm.isHidden(ci+adjust)){ |
---|
3980 | --adjust; |
---|
3981 | if(ci+adjust < 0){ |
---|
3982 | return; |
---|
3983 | } |
---|
3984 | } |
---|
3985 | } |
---|
3986 | this.cellIndex = ci+adjust; |
---|
3987 | this.split = t.dom; |
---|
3988 | if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){ |
---|
3989 | Ext.grid.GridView.SplitDragZone.superclass.handleMouseDown.apply(this, arguments); |
---|
3990 | } |
---|
3991 | }else if(this.view.columnDrag){ |
---|
3992 | this.view.columnDrag.callHandleMouseDown(e); |
---|
3993 | } |
---|
3994 | } |
---|
3995 | }, |
---|
3996 | |
---|
3997 | endDrag : function(e){ |
---|
3998 | this.marker.hide(); |
---|
3999 | var v = this.view, |
---|
4000 | endX = Math.max(this.minX, e.getPageX()), |
---|
4001 | diff = endX - this.startPos, |
---|
4002 | disabled = this.dragHeadersDisabled; |
---|
4003 | |
---|
4004 | v.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff); |
---|
4005 | setTimeout(function(){ |
---|
4006 | v.headersDisabled = disabled; |
---|
4007 | }, 50); |
---|
4008 | }, |
---|
4009 | |
---|
4010 | autoOffset : function(){ |
---|
4011 | this.setDelta(0,0); |
---|
4012 | } |
---|
4013 | }); |
---|
4014 | /** |
---|
4015 | * @class Ext.grid.PivotGridView |
---|
4016 | * @extends Ext.grid.GridView |
---|
4017 | * Specialised GridView for rendering Pivot Grid components. Config can be passed to the PivotGridView via the PivotGrid constructor's |
---|
4018 | * viewConfig option: |
---|
4019 | <pre><code> |
---|
4020 | new Ext.grid.PivotGrid({ |
---|
4021 | viewConfig: { |
---|
4022 | title: 'My Pivot Grid', |
---|
4023 | getCellCls: function(value) { |
---|
4024 | return value > 10 'red' : 'green'; |
---|
4025 | } |
---|
4026 | } |
---|
4027 | }); |
---|
4028 | </code></pre> |
---|
4029 | * <p>Currently {@link #title} and {@link #getCellCls} are the only configuration options accepted by PivotGridView. All other |
---|
4030 | * interaction is performed via the {@link Ext.grid.PivotGrid PivotGrid} class.</p> |
---|
4031 | */ |
---|
4032 | Ext.grid.PivotGridView = Ext.extend(Ext.grid.GridView, { |
---|
4033 | |
---|
4034 | /** |
---|
4035 | * The CSS class added to all group header cells. Defaults to 'grid-hd-group-cell' |
---|
4036 | * @property colHeaderCellCls |
---|
4037 | * @type String |
---|
4038 | */ |
---|
4039 | colHeaderCellCls: 'grid-hd-group-cell', |
---|
4040 | |
---|
4041 | /** |
---|
4042 | * @cfg {String} title Optional title to be placed in the top left corner of the PivotGrid. Defaults to an empty string. |
---|
4043 | */ |
---|
4044 | title: '', |
---|
4045 | |
---|
4046 | /** |
---|
4047 | * @cfg {Function} getCellCls Optional function which should return a CSS class name for each cell value. This is useful when |
---|
4048 | * color coding cells based on their value. Defaults to undefined. |
---|
4049 | */ |
---|
4050 | |
---|
4051 | /** |
---|
4052 | * Returns the headers to be rendered at the top of the grid. Should be a 2-dimensional array, where each item specifies the number |
---|
4053 | * of columns it groups (column in this case refers to normal grid columns). In the example below we have 5 city groups, which are |
---|
4054 | * each part of a continent supergroup. The colspan for each city group refers to the number of normal grid columns that group spans, |
---|
4055 | * so in this case the grid would be expected to have a total of 12 columns: |
---|
4056 | <pre><code> |
---|
4057 | [ |
---|
4058 | { |
---|
4059 | items: [ |
---|
4060 | {header: 'England', colspan: 5}, |
---|
4061 | {header: 'USA', colspan: 3} |
---|
4062 | ] |
---|
4063 | }, |
---|
4064 | { |
---|
4065 | items: [ |
---|
4066 | {header: 'London', colspan: 2}, |
---|
4067 | {header: 'Cambridge', colspan: 3}, |
---|
4068 | {header: 'Palo Alto', colspan: 3} |
---|
4069 | ] |
---|
4070 | } |
---|
4071 | ] |
---|
4072 | </code></pre> |
---|
4073 | * In the example above we have cities nested under countries. The nesting could be deeper if desired - e.g. Continent -> Country -> |
---|
4074 | * State -> City, or any other structure. The only constaint is that the same depth must be used throughout the structure. |
---|
4075 | * @return {Array} A tree structure containing the headers to be rendered. Must include the colspan property at each level, which should |
---|
4076 | * be the sum of all child nodes beneath this node. |
---|
4077 | */ |
---|
4078 | getColumnHeaders: function() { |
---|
4079 | return this.grid.topAxis.buildHeaders();; |
---|
4080 | }, |
---|
4081 | |
---|
4082 | /** |
---|
4083 | * Returns the headers to be rendered on the left of the grid. Should be a 2-dimensional array, where each item specifies the number |
---|
4084 | * of rows it groups. In the example below we have 5 city groups, which are each part of a continent supergroup. The rowspan for each |
---|
4085 | * city group refers to the number of normal grid columns that group spans, so in this case the grid would be expected to have a |
---|
4086 | * total of 12 rows: |
---|
4087 | <pre><code> |
---|
4088 | [ |
---|
4089 | { |
---|
4090 | width: 90, |
---|
4091 | items: [ |
---|
4092 | {header: 'England', rowspan: 5}, |
---|
4093 | {header: 'USA', rowspan: 3} |
---|
4094 | ] |
---|
4095 | }, |
---|
4096 | { |
---|
4097 | width: 50, |
---|
4098 | items: [ |
---|
4099 | {header: 'London', rowspan: 2}, |
---|
4100 | {header: 'Cambridge', rowspan: 3}, |
---|
4101 | {header: 'Palo Alto', rowspan: 3} |
---|
4102 | ] |
---|
4103 | } |
---|
4104 | ] |
---|
4105 | </code></pre> |
---|
4106 | * In the example above we have cities nested under countries. The nesting could be deeper if desired - e.g. Continent -> Country -> |
---|
4107 | * State -> City, or any other structure. The only constaint is that the same depth must be used throughout the structure. |
---|
4108 | * @return {Array} A tree structure containing the headers to be rendered. Must include the colspan property at each level, which should |
---|
4109 | * be the sum of all child nodes beneath this node. |
---|
4110 | * Each group may specify the width it should be rendered with. |
---|
4111 | * @return {Array} The row groups |
---|
4112 | */ |
---|
4113 | getRowHeaders: function() { |
---|
4114 | return this.grid.leftAxis.buildHeaders(); |
---|
4115 | }, |
---|
4116 | |
---|
4117 | /** |
---|
4118 | * @private |
---|
4119 | * Renders rows between start and end indexes |
---|
4120 | * @param {Number} startRow Index of the first row to render |
---|
4121 | * @param {Number} endRow Index of the last row to render |
---|
4122 | */ |
---|
4123 | renderRows : function(startRow, endRow) { |
---|
4124 | var grid = this.grid, |
---|
4125 | rows = grid.extractData(), |
---|
4126 | rowCount = rows.length, |
---|
4127 | templates = this.templates, |
---|
4128 | renderer = grid.renderer, |
---|
4129 | hasRenderer = typeof renderer == 'function', |
---|
4130 | getCellCls = this.getCellCls, |
---|
4131 | hasGetCellCls = typeof getCellCls == 'function', |
---|
4132 | cellTemplate = templates.cell, |
---|
4133 | rowTemplate = templates.row, |
---|
4134 | rowBuffer = [], |
---|
4135 | meta = {}, |
---|
4136 | tstyle = 'width:' + this.getGridInnerWidth() + 'px;', |
---|
4137 | colBuffer, colCount, column, i, row; |
---|
4138 | |
---|
4139 | startRow = startRow || 0; |
---|
4140 | endRow = Ext.isDefined(endRow) ? endRow : rowCount - 1; |
---|
4141 | |
---|
4142 | for (i = 0; i < rowCount; i++) { |
---|
4143 | row = rows[i]; |
---|
4144 | colCount = row.length; |
---|
4145 | colBuffer = []; |
---|
4146 | |
---|
4147 | //build up each column's HTML |
---|
4148 | for (var j = 0; j < colCount; j++) { |
---|
4149 | |
---|
4150 | meta.id = i + '-' + j; |
---|
4151 | meta.css = j === 0 ? 'x-grid3-cell-first ' : (j == (colCount - 1) ? 'x-grid3-cell-last ' : ''); |
---|
4152 | meta.attr = meta.cellAttr = ''; |
---|
4153 | meta.value = row[j]; |
---|
4154 | |
---|
4155 | if (Ext.isEmpty(meta.value)) { |
---|
4156 | meta.value = ' '; |
---|
4157 | } |
---|
4158 | |
---|
4159 | if (hasRenderer) { |
---|
4160 | meta.value = renderer(meta.value); |
---|
4161 | } |
---|
4162 | |
---|
4163 | if (hasGetCellCls) { |
---|
4164 | meta.css += getCellCls(meta.value) + ' '; |
---|
4165 | } |
---|
4166 | |
---|
4167 | colBuffer[colBuffer.length] = cellTemplate.apply(meta); |
---|
4168 | } |
---|
4169 | |
---|
4170 | rowBuffer[rowBuffer.length] = rowTemplate.apply({ |
---|
4171 | tstyle: tstyle, |
---|
4172 | cols : colCount, |
---|
4173 | cells : colBuffer.join(""), |
---|
4174 | alt : '' |
---|
4175 | }); |
---|
4176 | } |
---|
4177 | |
---|
4178 | return rowBuffer.join(""); |
---|
4179 | }, |
---|
4180 | |
---|
4181 | /** |
---|
4182 | * The master template to use when rendering the GridView. Has a default template |
---|
4183 | * @property Ext.Template |
---|
4184 | * @type masterTpl |
---|
4185 | */ |
---|
4186 | masterTpl: new Ext.Template( |
---|
4187 | '<div class="x-grid3 x-pivotgrid" hidefocus="true">', |
---|
4188 | '<div class="x-grid3-viewport">', |
---|
4189 | '<div class="x-grid3-header">', |
---|
4190 | '<div class="x-grid3-header-title"><span>{title}</span></div>', |
---|
4191 | '<div class="x-grid3-header-inner">', |
---|
4192 | '<div class="x-grid3-header-offset" style="{ostyle}"></div>', |
---|
4193 | '</div>', |
---|
4194 | '<div class="x-clear"></div>', |
---|
4195 | '</div>', |
---|
4196 | '<div class="x-grid3-scroller">', |
---|
4197 | '<div class="x-grid3-row-headers"></div>', |
---|
4198 | '<div class="x-grid3-body" style="{bstyle}">{body}</div>', |
---|
4199 | '<a href="#" class="x-grid3-focus" tabIndex="-1"></a>', |
---|
4200 | '</div>', |
---|
4201 | '</div>', |
---|
4202 | '<div class="x-grid3-resize-marker"> </div>', |
---|
4203 | '<div class="x-grid3-resize-proxy"> </div>', |
---|
4204 | '</div>' |
---|
4205 | ), |
---|
4206 | |
---|
4207 | /** |
---|
4208 | * @private |
---|
4209 | * Adds a gcell template to the internal templates object. This is used to render the headers in a multi-level column header. |
---|
4210 | */ |
---|
4211 | initTemplates: function() { |
---|
4212 | Ext.grid.PivotGridView.superclass.initTemplates.apply(this, arguments); |
---|
4213 | |
---|
4214 | var templates = this.templates || {}; |
---|
4215 | if (!templates.gcell) { |
---|
4216 | templates.gcell = new Ext.XTemplate( |
---|
4217 | '<td class="x-grid3-hd x-grid3-gcell x-grid3-td-{id} ux-grid-hd-group-row-{row} ' + this.colHeaderCellCls + '" style="{style}">', |
---|
4218 | '<div {tooltip} class="x-grid3-hd-inner x-grid3-hd-{id}" unselectable="on" style="{istyle}">', |
---|
4219 | this.grid.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '', '{value}', |
---|
4220 | '</div>', |
---|
4221 | '</td>' |
---|
4222 | ); |
---|
4223 | } |
---|
4224 | |
---|
4225 | this.templates = templates; |
---|
4226 | this.hrowRe = new RegExp("ux-grid-hd-group-row-(\\d+)", ""); |
---|
4227 | }, |
---|
4228 | |
---|
4229 | /** |
---|
4230 | * @private |
---|
4231 | * Sets up the reference to the row headers element |
---|
4232 | */ |
---|
4233 | initElements: function() { |
---|
4234 | Ext.grid.PivotGridView.superclass.initElements.apply(this, arguments); |
---|
4235 | |
---|
4236 | /** |
---|
4237 | * @property rowHeadersEl |
---|
4238 | * @type Ext.Element |
---|
4239 | * The element containing all row headers |
---|
4240 | */ |
---|
4241 | this.rowHeadersEl = new Ext.Element(this.scroller.child('div.x-grid3-row-headers')); |
---|
4242 | |
---|
4243 | /** |
---|
4244 | * @property headerTitleEl |
---|
4245 | * @type Ext.Element |
---|
4246 | * The element that contains the optional title (top left section of the pivot grid) |
---|
4247 | */ |
---|
4248 | this.headerTitleEl = new Ext.Element(this.mainHd.child('div.x-grid3-header-title')); |
---|
4249 | }, |
---|
4250 | |
---|
4251 | /** |
---|
4252 | * @private |
---|
4253 | * Takes row headers into account when calculating total available width |
---|
4254 | */ |
---|
4255 | getGridInnerWidth: function() { |
---|
4256 | var previousWidth = Ext.grid.PivotGridView.superclass.getGridInnerWidth.apply(this, arguments); |
---|
4257 | |
---|
4258 | return previousWidth - this.getTotalRowHeaderWidth(); |
---|
4259 | }, |
---|
4260 | |
---|
4261 | /** |
---|
4262 | * Returns the total width of all row headers as specified by {@link #getRowHeaders} |
---|
4263 | * @return {Number} The total width |
---|
4264 | */ |
---|
4265 | getTotalRowHeaderWidth: function() { |
---|
4266 | var headers = this.getRowHeaders(), |
---|
4267 | length = headers.length, |
---|
4268 | total = 0, |
---|
4269 | i; |
---|
4270 | |
---|
4271 | for (i = 0; i< length; i++) { |
---|
4272 | total += headers[i].width; |
---|
4273 | } |
---|
4274 | |
---|
4275 | return total; |
---|
4276 | }, |
---|
4277 | |
---|
4278 | /** |
---|
4279 | * @private |
---|
4280 | * Returns the total height of all column headers |
---|
4281 | * @return {Number} The total height |
---|
4282 | */ |
---|
4283 | getTotalColumnHeaderHeight: function() { |
---|
4284 | return this.getColumnHeaders().length * 21; |
---|
4285 | }, |
---|
4286 | |
---|
4287 | /** |
---|
4288 | * Inherit docs |
---|
4289 | * @private |
---|
4290 | * @param {HTMLElement} el |
---|
4291 | */ |
---|
4292 | getCellIndex : function(el) { |
---|
4293 | if (el) { |
---|
4294 | var match = el.className.match(this.colRe), |
---|
4295 | data; |
---|
4296 | |
---|
4297 | if (match && (data = match[1])) { |
---|
4298 | return parseInt(data.split('-')[1], 10); |
---|
4299 | } |
---|
4300 | } |
---|
4301 | return false; |
---|
4302 | }, |
---|
4303 | |
---|
4304 | |
---|
4305 | /** |
---|
4306 | * @private |
---|
4307 | * Slight specialisation of the GridView renderUI - just adds the row headers |
---|
4308 | */ |
---|
4309 | renderUI : function() { |
---|
4310 | var templates = this.templates, |
---|
4311 | innerWidth = this.getGridInnerWidth(); |
---|
4312 | |
---|
4313 | return templates.master.apply({ |
---|
4314 | body : templates.body.apply({rows:' '}), |
---|
4315 | ostyle: 'width:' + innerWidth + 'px', |
---|
4316 | bstyle: 'width:' + innerWidth + 'px' |
---|
4317 | }); |
---|
4318 | }, |
---|
4319 | |
---|
4320 | /** |
---|
4321 | * @private |
---|
4322 | * Make sure that the headers and rows are all sized correctly during layout |
---|
4323 | */ |
---|
4324 | onLayout: function(width, height) { |
---|
4325 | Ext.grid.PivotGridView.superclass.onLayout.apply(this, arguments); |
---|
4326 | |
---|
4327 | var width = this.getGridInnerWidth(); |
---|
4328 | |
---|
4329 | this.resizeColumnHeaders(width); |
---|
4330 | this.resizeAllRows(width); |
---|
4331 | }, |
---|
4332 | |
---|
4333 | /** |
---|
4334 | * Refreshs the grid UI |
---|
4335 | * @param {Boolean} headersToo (optional) True to also refresh the headers |
---|
4336 | */ |
---|
4337 | refresh : function(headersToo) { |
---|
4338 | this.fireEvent('beforerefresh', this); |
---|
4339 | this.grid.stopEditing(true); |
---|
4340 | |
---|
4341 | var result = this.renderBody(); |
---|
4342 | this.mainBody.update(result).setWidth(this.getGridInnerWidth()); |
---|
4343 | if (headersToo === true) { |
---|
4344 | this.updateHeaders(); |
---|
4345 | this.updateHeaderSortState(); |
---|
4346 | } |
---|
4347 | this.processRows(0, true); |
---|
4348 | this.layout(); |
---|
4349 | this.applyEmptyText(); |
---|
4350 | this.fireEvent('refresh', this); |
---|
4351 | }, |
---|
4352 | |
---|
4353 | /** |
---|
4354 | * @private |
---|
4355 | * Bypasses GridView's renderHeaders as they are taken care of separately by the PivotAxis instances |
---|
4356 | */ |
---|
4357 | renderHeaders: Ext.emptyFn, |
---|
4358 | |
---|
4359 | /** |
---|
4360 | * @private |
---|
4361 | * Taken care of by PivotAxis |
---|
4362 | */ |
---|
4363 | fitColumns: Ext.emptyFn, |
---|
4364 | |
---|
4365 | /** |
---|
4366 | * @private |
---|
4367 | * Called on layout, ensures that the width of each column header is correct. Omitting this can lead to faulty |
---|
4368 | * layouts when nested in a container. |
---|
4369 | * @param {Number} width The new width |
---|
4370 | */ |
---|
4371 | resizeColumnHeaders: function(width) { |
---|
4372 | var topAxis = this.grid.topAxis; |
---|
4373 | |
---|
4374 | if (topAxis.rendered) { |
---|
4375 | topAxis.el.setWidth(width); |
---|
4376 | } |
---|
4377 | }, |
---|
4378 | |
---|
4379 | /** |
---|
4380 | * @private |
---|
4381 | * Sets the row header div to the correct width. Should be called after rendering and reconfiguration of headers |
---|
4382 | */ |
---|
4383 | resizeRowHeaders: function() { |
---|
4384 | var rowHeaderWidth = this.getTotalRowHeaderWidth(), |
---|
4385 | marginStyle = String.format("margin-left: {0}px;", rowHeaderWidth); |
---|
4386 | |
---|
4387 | this.rowHeadersEl.setWidth(rowHeaderWidth); |
---|
4388 | this.mainBody.applyStyles(marginStyle); |
---|
4389 | Ext.fly(this.innerHd).applyStyles(marginStyle); |
---|
4390 | |
---|
4391 | this.headerTitleEl.setWidth(rowHeaderWidth); |
---|
4392 | this.headerTitleEl.setHeight(this.getTotalColumnHeaderHeight()); |
---|
4393 | }, |
---|
4394 | |
---|
4395 | /** |
---|
4396 | * @private |
---|
4397 | * Resizes all rendered rows to the given width. Usually called by onLayout |
---|
4398 | * @param {Number} width The new width |
---|
4399 | */ |
---|
4400 | resizeAllRows: function(width) { |
---|
4401 | var rows = this.getRows(), |
---|
4402 | length = rows.length, |
---|
4403 | i; |
---|
4404 | |
---|
4405 | for (i = 0; i < length; i++) { |
---|
4406 | Ext.fly(rows[i]).setWidth(width); |
---|
4407 | Ext.fly(rows[i]).child('table').setWidth(width); |
---|
4408 | } |
---|
4409 | }, |
---|
4410 | |
---|
4411 | /** |
---|
4412 | * @private |
---|
4413 | * Updates the Row Headers, deferring the updating of Column Headers to GridView |
---|
4414 | */ |
---|
4415 | updateHeaders: function() { |
---|
4416 | this.renderGroupRowHeaders(); |
---|
4417 | this.renderGroupColumnHeaders(); |
---|
4418 | }, |
---|
4419 | |
---|
4420 | /** |
---|
4421 | * @private |
---|
4422 | * Renders all row header groups at all levels based on the structure fetched from {@link #getGroupRowHeaders} |
---|
4423 | */ |
---|
4424 | renderGroupRowHeaders: function() { |
---|
4425 | var leftAxis = this.grid.leftAxis; |
---|
4426 | |
---|
4427 | this.resizeRowHeaders(); |
---|
4428 | leftAxis.rendered = false; |
---|
4429 | leftAxis.render(this.rowHeadersEl); |
---|
4430 | |
---|
4431 | this.setTitle(this.title); |
---|
4432 | }, |
---|
4433 | |
---|
4434 | /** |
---|
4435 | * Sets the title text in the top left segment of the PivotGridView |
---|
4436 | * @param {String} title The title |
---|
4437 | */ |
---|
4438 | setTitle: function(title) { |
---|
4439 | this.headerTitleEl.child('span').dom.innerHTML = title; |
---|
4440 | }, |
---|
4441 | |
---|
4442 | /** |
---|
4443 | * @private |
---|
4444 | * Renders all column header groups at all levels based on the structure fetched from {@link #getColumnHeaders} |
---|
4445 | */ |
---|
4446 | renderGroupColumnHeaders: function() { |
---|
4447 | var topAxis = this.grid.topAxis; |
---|
4448 | |
---|
4449 | topAxis.rendered = false; |
---|
4450 | topAxis.render(this.innerHd.firstChild); |
---|
4451 | }, |
---|
4452 | |
---|
4453 | /** |
---|
4454 | * @private |
---|
4455 | * Overridden to test whether the user is hovering over a group cell, in which case we don't show the menu |
---|
4456 | */ |
---|
4457 | isMenuDisabled: function(cellIndex, el) { |
---|
4458 | return true; |
---|
4459 | } |
---|
4460 | });/** |
---|
4461 | * @class Ext.grid.PivotAxis |
---|
4462 | * @extends Ext.Component |
---|
4463 | * <p>PivotAxis is a class that supports a {@link Ext.grid.PivotGrid}. Each PivotGrid contains two PivotAxis instances - the left |
---|
4464 | * axis and the top axis. Each PivotAxis defines an ordered set of dimensions, each of which should correspond to a field in a |
---|
4465 | * Store's Record (see {@link Ext.grid.PivotGrid} documentation for further explanation).</p> |
---|
4466 | * <p>Developers should have little interaction with the PivotAxis instances directly as most of their management is performed by |
---|
4467 | * the PivotGrid. An exception is the dynamic reconfiguration of axes at run time - to achieve this we use PivotAxis's |
---|
4468 | * {@link #setDimensions} function and refresh the grid:</p> |
---|
4469 | <pre><code> |
---|
4470 | var pivotGrid = new Ext.grid.PivotGrid({ |
---|
4471 | //some PivotGrid config here |
---|
4472 | }); |
---|
4473 | |
---|
4474 | //change the left axis dimensions |
---|
4475 | pivotGrid.leftAxis.setDimensions([ |
---|
4476 | { |
---|
4477 | dataIndex: 'person', |
---|
4478 | direction: 'DESC', |
---|
4479 | width : 100 |
---|
4480 | }, |
---|
4481 | { |
---|
4482 | dataIndex: 'product', |
---|
4483 | direction: 'ASC', |
---|
4484 | width : 80 |
---|
4485 | } |
---|
4486 | ]); |
---|
4487 | |
---|
4488 | pivotGrid.view.refresh(true); |
---|
4489 | </code></pre> |
---|
4490 | * This clears the previous dimensions on the axis and redraws the grid with the new dimensions. |
---|
4491 | */ |
---|
4492 | Ext.grid.PivotAxis = Ext.extend(Ext.Component, { |
---|
4493 | /** |
---|
4494 | * @cfg {String} orientation One of 'vertical' or 'horizontal'. Defaults to horizontal |
---|
4495 | */ |
---|
4496 | orientation: 'horizontal', |
---|
4497 | |
---|
4498 | /** |
---|
4499 | * @cfg {Number} defaultHeaderWidth The width to render each row header that does not have a width specified via |
---|
4500 | {@link #getRowGroupHeaders}. Defaults to 80. |
---|
4501 | */ |
---|
4502 | defaultHeaderWidth: 80, |
---|
4503 | |
---|
4504 | /** |
---|
4505 | * @private |
---|
4506 | * @cfg {Number} paddingWidth The amount of padding used by each cell. |
---|
4507 | * TODO: From 4.x onwards this can be removed as it won't be needed. For now it is used to account for the differences between |
---|
4508 | * the content box and border box measurement models |
---|
4509 | */ |
---|
4510 | paddingWidth: 7, |
---|
4511 | |
---|
4512 | /** |
---|
4513 | * Updates the dimensions used by this axis |
---|
4514 | * @param {Array} dimensions The new dimensions |
---|
4515 | */ |
---|
4516 | setDimensions: function(dimensions) { |
---|
4517 | this.dimensions = dimensions; |
---|
4518 | }, |
---|
4519 | |
---|
4520 | /** |
---|
4521 | * @private |
---|
4522 | * Builds the html table that contains the dimensions for this axis. This branches internally between vertical |
---|
4523 | * and horizontal orientations because the table structure is slightly different in each case |
---|
4524 | */ |
---|
4525 | onRender: function(ct, position) { |
---|
4526 | var rows = this.orientation == 'horizontal' |
---|
4527 | ? this.renderHorizontalRows() |
---|
4528 | : this.renderVerticalRows(); |
---|
4529 | |
---|
4530 | this.el = Ext.DomHelper.overwrite(ct.dom, {tag: 'table', cn: rows}, true); |
---|
4531 | }, |
---|
4532 | |
---|
4533 | /** |
---|
4534 | * @private |
---|
4535 | * Specialised renderer for horizontal oriented axes |
---|
4536 | * @return {Object} The HTML Domspec for a horizontal oriented axis |
---|
4537 | */ |
---|
4538 | renderHorizontalRows: function() { |
---|
4539 | var headers = this.buildHeaders(), |
---|
4540 | rowCount = headers.length, |
---|
4541 | rows = [], |
---|
4542 | cells, cols, colCount, i, j; |
---|
4543 | |
---|
4544 | for (i = 0; i < rowCount; i++) { |
---|
4545 | cells = []; |
---|
4546 | cols = headers[i].items; |
---|
4547 | colCount = cols.length; |
---|
4548 | |
---|
4549 | for (j = 0; j < colCount; j++) { |
---|
4550 | cells.push({ |
---|
4551 | tag: 'td', |
---|
4552 | html: cols[j].header, |
---|
4553 | colspan: cols[j].span |
---|
4554 | }); |
---|
4555 | } |
---|
4556 | |
---|
4557 | rows[i] = { |
---|
4558 | tag: 'tr', |
---|
4559 | cn: cells |
---|
4560 | }; |
---|
4561 | } |
---|
4562 | |
---|
4563 | return rows; |
---|
4564 | }, |
---|
4565 | |
---|
4566 | /** |
---|
4567 | * @private |
---|
4568 | * Specialised renderer for vertical oriented axes |
---|
4569 | * @return {Object} The HTML Domspec for a vertical oriented axis |
---|
4570 | */ |
---|
4571 | renderVerticalRows: function() { |
---|
4572 | var headers = this.buildHeaders(), |
---|
4573 | colCount = headers.length, |
---|
4574 | rowCells = [], |
---|
4575 | rows = [], |
---|
4576 | rowCount, col, row, colWidth, i, j; |
---|
4577 | |
---|
4578 | for (i = 0; i < colCount; i++) { |
---|
4579 | col = headers[i]; |
---|
4580 | colWidth = col.width || 80; |
---|
4581 | rowCount = col.items.length; |
---|
4582 | |
---|
4583 | for (j = 0; j < rowCount; j++) { |
---|
4584 | row = col.items[j]; |
---|
4585 | |
---|
4586 | rowCells[row.start] = rowCells[row.start] || []; |
---|
4587 | rowCells[row.start].push({ |
---|
4588 | tag : 'td', |
---|
4589 | html : row.header, |
---|
4590 | rowspan: row.span, |
---|
4591 | width : Ext.isBorderBox ? colWidth : colWidth - this.paddingWidth |
---|
4592 | }); |
---|
4593 | } |
---|
4594 | } |
---|
4595 | |
---|
4596 | rowCount = rowCells.length; |
---|
4597 | for (i = 0; i < rowCount; i++) { |
---|
4598 | rows[i] = { |
---|
4599 | tag: 'tr', |
---|
4600 | cn : rowCells[i] |
---|
4601 | }; |
---|
4602 | } |
---|
4603 | |
---|
4604 | return rows; |
---|
4605 | }, |
---|
4606 | |
---|
4607 | /** |
---|
4608 | * @private |
---|
4609 | * Returns the set of all unique tuples based on the bound store and dimension definitions. |
---|
4610 | * Internally we construct a new, temporary store to make use of the multi-sort capabilities of Store. In |
---|
4611 | * 4.x this functionality should have been moved to MixedCollection so this step should not be needed. |
---|
4612 | * @return {Array} All unique tuples |
---|
4613 | */ |
---|
4614 | getTuples: function() { |
---|
4615 | var newStore = new Ext.data.Store({}); |
---|
4616 | |
---|
4617 | newStore.data = this.store.data.clone(); |
---|
4618 | newStore.fields = this.store.fields; |
---|
4619 | |
---|
4620 | var sorters = [], |
---|
4621 | dimensions = this.dimensions, |
---|
4622 | length = dimensions.length, |
---|
4623 | i; |
---|
4624 | |
---|
4625 | for (i = 0; i < length; i++) { |
---|
4626 | sorters.push({ |
---|
4627 | field : dimensions[i].dataIndex, |
---|
4628 | direction: dimensions[i].direction || 'ASC' |
---|
4629 | }); |
---|
4630 | } |
---|
4631 | |
---|
4632 | newStore.sort(sorters); |
---|
4633 | |
---|
4634 | var records = newStore.data.items, |
---|
4635 | hashes = [], |
---|
4636 | tuples = [], |
---|
4637 | recData, hash, info, data, key; |
---|
4638 | |
---|
4639 | length = records.length; |
---|
4640 | |
---|
4641 | for (i = 0; i < length; i++) { |
---|
4642 | info = this.getRecordInfo(records[i]); |
---|
4643 | data = info.data; |
---|
4644 | hash = ""; |
---|
4645 | |
---|
4646 | for (key in data) { |
---|
4647 | hash += data[key] + '---'; |
---|
4648 | } |
---|
4649 | |
---|
4650 | if (hashes.indexOf(hash) == -1) { |
---|
4651 | hashes.push(hash); |
---|
4652 | tuples.push(info); |
---|
4653 | } |
---|
4654 | } |
---|
4655 | |
---|
4656 | newStore.destroy(); |
---|
4657 | |
---|
4658 | return tuples; |
---|
4659 | }, |
---|
4660 | |
---|
4661 | /** |
---|
4662 | * @private |
---|
4663 | */ |
---|
4664 | getRecordInfo: function(record) { |
---|
4665 | var dimensions = this.dimensions, |
---|
4666 | length = dimensions.length, |
---|
4667 | data = {}, |
---|
4668 | dimension, dataIndex, i; |
---|
4669 | |
---|
4670 | //get an object containing just the data we are interested in based on the configured dimensions |
---|
4671 | for (i = 0; i < length; i++) { |
---|
4672 | dimension = dimensions[i]; |
---|
4673 | dataIndex = dimension.dataIndex; |
---|
4674 | |
---|
4675 | data[dataIndex] = record.get(dataIndex); |
---|
4676 | } |
---|
4677 | |
---|
4678 | //creates a specialised matcher function for a given tuple. The returned function will return |
---|
4679 | //true if the record passed to it matches the dataIndex values of each dimension in this axis |
---|
4680 | var createMatcherFunction = function(data) { |
---|
4681 | return function(record) { |
---|
4682 | for (var dataIndex in data) { |
---|
4683 | if (record.get(dataIndex) != data[dataIndex]) { |
---|
4684 | return false; |
---|
4685 | } |
---|
4686 | } |
---|
4687 | |
---|
4688 | return true; |
---|
4689 | }; |
---|
4690 | }; |
---|
4691 | |
---|
4692 | return { |
---|
4693 | data: data, |
---|
4694 | matcher: createMatcherFunction(data) |
---|
4695 | }; |
---|
4696 | }, |
---|
4697 | |
---|
4698 | /** |
---|
4699 | * @private |
---|
4700 | * Uses the calculated set of tuples to build an array of headers that can be rendered into a table using rowspan or |
---|
4701 | * colspan. Basically this takes the set of tuples and spans any cells that run into one another, so if we had dimensions |
---|
4702 | * of Person and Product and several tuples containing different Products for the same Person, those Products would be |
---|
4703 | * spanned. |
---|
4704 | * @return {Array} The headers |
---|
4705 | */ |
---|
4706 | buildHeaders: function() { |
---|
4707 | var tuples = this.getTuples(), |
---|
4708 | rowCount = tuples.length, |
---|
4709 | dimensions = this.dimensions, |
---|
4710 | dimension, |
---|
4711 | colCount = dimensions.length, |
---|
4712 | headers = [], |
---|
4713 | tuple, rows, currentHeader, previousHeader, span, start, isLast, changed, i, j; |
---|
4714 | |
---|
4715 | for (i = 0; i < colCount; i++) { |
---|
4716 | dimension = dimensions[i]; |
---|
4717 | rows = []; |
---|
4718 | span = 0; |
---|
4719 | start = 0; |
---|
4720 | |
---|
4721 | for (j = 0; j < rowCount; j++) { |
---|
4722 | tuple = tuples[j]; |
---|
4723 | isLast = j == (rowCount - 1); |
---|
4724 | currentHeader = tuple.data[dimension.dataIndex]; |
---|
4725 | |
---|
4726 | /* |
---|
4727 | * 'changed' indicates that we need to create a new cell. This should be true whenever the cell |
---|
4728 | * above (previousHeader) is different from this cell, or when the cell on the previous dimension |
---|
4729 | * changed (e.g. if the current dimension is Product and the previous was Person, we need to start |
---|
4730 | * a new cell if Product is the same but Person changed, so we check the previous dimension and tuple) |
---|
4731 | */ |
---|
4732 | changed = previousHeader != undefined && previousHeader != currentHeader; |
---|
4733 | if (i > 0 && j > 0) { |
---|
4734 | changed = changed || tuple.data[dimensions[i-1].dataIndex] != tuples[j-1].data[dimensions[i-1].dataIndex]; |
---|
4735 | } |
---|
4736 | |
---|
4737 | if (changed) { |
---|
4738 | rows.push({ |
---|
4739 | header: previousHeader, |
---|
4740 | span : span, |
---|
4741 | start : start |
---|
4742 | }); |
---|
4743 | |
---|
4744 | start += span; |
---|
4745 | span = 0; |
---|
4746 | } |
---|
4747 | |
---|
4748 | if (isLast) { |
---|
4749 | rows.push({ |
---|
4750 | header: currentHeader, |
---|
4751 | span : span + 1, |
---|
4752 | start : start |
---|
4753 | }); |
---|
4754 | |
---|
4755 | start += span; |
---|
4756 | span = 0; |
---|
4757 | } |
---|
4758 | |
---|
4759 | previousHeader = currentHeader; |
---|
4760 | span++; |
---|
4761 | } |
---|
4762 | |
---|
4763 | headers.push({ |
---|
4764 | items: rows, |
---|
4765 | width: dimension.width || this.defaultHeaderWidth |
---|
4766 | }); |
---|
4767 | |
---|
4768 | previousHeader = undefined; |
---|
4769 | } |
---|
4770 | |
---|
4771 | return headers; |
---|
4772 | } |
---|
4773 | }); |
---|
4774 | // private |
---|
4775 | // This is a support class used internally by the Grid components |
---|
4776 | Ext.grid.HeaderDragZone = Ext.extend(Ext.dd.DragZone, { |
---|
4777 | maxDragWidth: 120, |
---|
4778 | |
---|
4779 | constructor : function(grid, hd, hd2){ |
---|
4780 | this.grid = grid; |
---|
4781 | this.view = grid.getView(); |
---|
4782 | this.ddGroup = "gridHeader" + this.grid.getGridEl().id; |
---|
4783 | Ext.grid.HeaderDragZone.superclass.constructor.call(this, hd); |
---|
4784 | if(hd2){ |
---|
4785 | this.setHandleElId(Ext.id(hd)); |
---|
4786 | this.setOuterHandleElId(Ext.id(hd2)); |
---|
4787 | } |
---|
4788 | this.scroll = false; |
---|
4789 | }, |
---|
4790 | |
---|
4791 | getDragData : function(e){ |
---|
4792 | var t = Ext.lib.Event.getTarget(e), |
---|
4793 | h = this.view.findHeaderCell(t); |
---|
4794 | if(h){ |
---|
4795 | return {ddel: h.firstChild, header:h}; |
---|
4796 | } |
---|
4797 | return false; |
---|
4798 | }, |
---|
4799 | |
---|
4800 | onInitDrag : function(e){ |
---|
4801 | // keep the value here so we can restore it; |
---|
4802 | this.dragHeadersDisabled = this.view.headersDisabled; |
---|
4803 | this.view.headersDisabled = true; |
---|
4804 | var clone = this.dragData.ddel.cloneNode(true); |
---|
4805 | clone.id = Ext.id(); |
---|
4806 | clone.style.width = Math.min(this.dragData.header.offsetWidth,this.maxDragWidth) + "px"; |
---|
4807 | this.proxy.update(clone); |
---|
4808 | return true; |
---|
4809 | }, |
---|
4810 | |
---|
4811 | afterValidDrop : function(){ |
---|
4812 | this.completeDrop(); |
---|
4813 | }, |
---|
4814 | |
---|
4815 | afterInvalidDrop : function(){ |
---|
4816 | this.completeDrop(); |
---|
4817 | }, |
---|
4818 | |
---|
4819 | completeDrop: function(){ |
---|
4820 | var v = this.view, |
---|
4821 | disabled = this.dragHeadersDisabled; |
---|
4822 | setTimeout(function(){ |
---|
4823 | v.headersDisabled = disabled; |
---|
4824 | }, 50); |
---|
4825 | } |
---|
4826 | }); |
---|
4827 | |
---|
4828 | // private |
---|
4829 | // This is a support class used internally by the Grid components |
---|
4830 | Ext.grid.HeaderDropZone = Ext.extend(Ext.dd.DropZone, { |
---|
4831 | proxyOffsets : [-4, -9], |
---|
4832 | fly: Ext.Element.fly, |
---|
4833 | |
---|
4834 | constructor : function(grid, hd, hd2){ |
---|
4835 | this.grid = grid; |
---|
4836 | this.view = grid.getView(); |
---|
4837 | // split the proxies so they don't interfere with mouse events |
---|
4838 | this.proxyTop = Ext.DomHelper.append(document.body, { |
---|
4839 | cls:"col-move-top", html:" " |
---|
4840 | }, true); |
---|
4841 | this.proxyBottom = Ext.DomHelper.append(document.body, { |
---|
4842 | cls:"col-move-bottom", html:" " |
---|
4843 | }, true); |
---|
4844 | this.proxyTop.hide = this.proxyBottom.hide = function(){ |
---|
4845 | this.setLeftTop(-100,-100); |
---|
4846 | this.setStyle("visibility", "hidden"); |
---|
4847 | }; |
---|
4848 | this.ddGroup = "gridHeader" + this.grid.getGridEl().id; |
---|
4849 | // temporarily disabled |
---|
4850 | //Ext.dd.ScrollManager.register(this.view.scroller.dom); |
---|
4851 | Ext.grid.HeaderDropZone.superclass.constructor.call(this, grid.getGridEl().dom); |
---|
4852 | }, |
---|
4853 | |
---|
4854 | getTargetFromEvent : function(e){ |
---|
4855 | var t = Ext.lib.Event.getTarget(e), |
---|
4856 | cindex = this.view.findCellIndex(t); |
---|
4857 | if(cindex !== false){ |
---|
4858 | return this.view.getHeaderCell(cindex); |
---|
4859 | } |
---|
4860 | }, |
---|
4861 | |
---|
4862 | nextVisible : function(h){ |
---|
4863 | var v = this.view, cm = this.grid.colModel; |
---|
4864 | h = h.nextSibling; |
---|
4865 | while(h){ |
---|
4866 | if(!cm.isHidden(v.getCellIndex(h))){ |
---|
4867 | return h; |
---|
4868 | } |
---|
4869 | h = h.nextSibling; |
---|
4870 | } |
---|
4871 | return null; |
---|
4872 | }, |
---|
4873 | |
---|
4874 | prevVisible : function(h){ |
---|
4875 | var v = this.view, cm = this.grid.colModel; |
---|
4876 | h = h.prevSibling; |
---|
4877 | while(h){ |
---|
4878 | if(!cm.isHidden(v.getCellIndex(h))){ |
---|
4879 | return h; |
---|
4880 | } |
---|
4881 | h = h.prevSibling; |
---|
4882 | } |
---|
4883 | return null; |
---|
4884 | }, |
---|
4885 | |
---|
4886 | positionIndicator : function(h, n, e){ |
---|
4887 | var x = Ext.lib.Event.getPageX(e), |
---|
4888 | r = Ext.lib.Dom.getRegion(n.firstChild), |
---|
4889 | px, |
---|
4890 | pt, |
---|
4891 | py = r.top + this.proxyOffsets[1]; |
---|
4892 | if((r.right - x) <= (r.right-r.left)/2){ |
---|
4893 | px = r.right+this.view.borderWidth; |
---|
4894 | pt = "after"; |
---|
4895 | }else{ |
---|
4896 | px = r.left; |
---|
4897 | pt = "before"; |
---|
4898 | } |
---|
4899 | |
---|
4900 | if(this.grid.colModel.isFixed(this.view.getCellIndex(n))){ |
---|
4901 | return false; |
---|
4902 | } |
---|
4903 | |
---|
4904 | px += this.proxyOffsets[0]; |
---|
4905 | this.proxyTop.setLeftTop(px, py); |
---|
4906 | this.proxyTop.show(); |
---|
4907 | if(!this.bottomOffset){ |
---|
4908 | this.bottomOffset = this.view.mainHd.getHeight(); |
---|
4909 | } |
---|
4910 | this.proxyBottom.setLeftTop(px, py+this.proxyTop.dom.offsetHeight+this.bottomOffset); |
---|
4911 | this.proxyBottom.show(); |
---|
4912 | return pt; |
---|
4913 | }, |
---|
4914 | |
---|
4915 | onNodeEnter : function(n, dd, e, data){ |
---|
4916 | if(data.header != n){ |
---|
4917 | this.positionIndicator(data.header, n, e); |
---|
4918 | } |
---|
4919 | }, |
---|
4920 | |
---|
4921 | onNodeOver : function(n, dd, e, data){ |
---|
4922 | var result = false; |
---|
4923 | if(data.header != n){ |
---|
4924 | result = this.positionIndicator(data.header, n, e); |
---|
4925 | } |
---|
4926 | if(!result){ |
---|
4927 | this.proxyTop.hide(); |
---|
4928 | this.proxyBottom.hide(); |
---|
4929 | } |
---|
4930 | return result ? this.dropAllowed : this.dropNotAllowed; |
---|
4931 | }, |
---|
4932 | |
---|
4933 | onNodeOut : function(n, dd, e, data){ |
---|
4934 | this.proxyTop.hide(); |
---|
4935 | this.proxyBottom.hide(); |
---|
4936 | }, |
---|
4937 | |
---|
4938 | onNodeDrop : function(n, dd, e, data){ |
---|
4939 | var h = data.header; |
---|
4940 | if(h != n){ |
---|
4941 | var cm = this.grid.colModel, |
---|
4942 | x = Ext.lib.Event.getPageX(e), |
---|
4943 | r = Ext.lib.Dom.getRegion(n.firstChild), |
---|
4944 | pt = (r.right - x) <= ((r.right-r.left)/2) ? "after" : "before", |
---|
4945 | oldIndex = this.view.getCellIndex(h), |
---|
4946 | newIndex = this.view.getCellIndex(n); |
---|
4947 | if(pt == "after"){ |
---|
4948 | newIndex++; |
---|
4949 | } |
---|
4950 | if(oldIndex < newIndex){ |
---|
4951 | newIndex--; |
---|
4952 | } |
---|
4953 | cm.moveColumn(oldIndex, newIndex); |
---|
4954 | return true; |
---|
4955 | } |
---|
4956 | return false; |
---|
4957 | } |
---|
4958 | }); |
---|
4959 | |
---|
4960 | Ext.grid.GridView.ColumnDragZone = Ext.extend(Ext.grid.HeaderDragZone, { |
---|
4961 | |
---|
4962 | constructor : function(grid, hd){ |
---|
4963 | Ext.grid.GridView.ColumnDragZone.superclass.constructor.call(this, grid, hd, null); |
---|
4964 | this.proxy.el.addClass('x-grid3-col-dd'); |
---|
4965 | }, |
---|
4966 | |
---|
4967 | handleMouseDown : function(e){ |
---|
4968 | }, |
---|
4969 | |
---|
4970 | callHandleMouseDown : function(e){ |
---|
4971 | Ext.grid.GridView.ColumnDragZone.superclass.handleMouseDown.call(this, e); |
---|
4972 | } |
---|
4973 | });// private |
---|
4974 | // This is a support class used internally by the Grid components |
---|
4975 | Ext.grid.SplitDragZone = Ext.extend(Ext.dd.DDProxy, { |
---|
4976 | fly: Ext.Element.fly, |
---|
4977 | |
---|
4978 | constructor : function(grid, hd, hd2){ |
---|
4979 | this.grid = grid; |
---|
4980 | this.view = grid.getView(); |
---|
4981 | this.proxy = this.view.resizeProxy; |
---|
4982 | Ext.grid.SplitDragZone.superclass.constructor.call(this, hd, |
---|
4983 | "gridSplitters" + this.grid.getGridEl().id, { |
---|
4984 | dragElId : Ext.id(this.proxy.dom), resizeFrame:false |
---|
4985 | }); |
---|
4986 | this.setHandleElId(Ext.id(hd)); |
---|
4987 | this.setOuterHandleElId(Ext.id(hd2)); |
---|
4988 | this.scroll = false; |
---|
4989 | }, |
---|
4990 | |
---|
4991 | b4StartDrag : function(x, y){ |
---|
4992 | this.view.headersDisabled = true; |
---|
4993 | this.proxy.setHeight(this.view.mainWrap.getHeight()); |
---|
4994 | var w = this.cm.getColumnWidth(this.cellIndex); |
---|
4995 | var minw = Math.max(w-this.grid.minColumnWidth, 0); |
---|
4996 | this.resetConstraints(); |
---|
4997 | this.setXConstraint(minw, 1000); |
---|
4998 | this.setYConstraint(0, 0); |
---|
4999 | this.minX = x - minw; |
---|
5000 | this.maxX = x + 1000; |
---|
5001 | this.startPos = x; |
---|
5002 | Ext.dd.DDProxy.prototype.b4StartDrag.call(this, x, y); |
---|
5003 | }, |
---|
5004 | |
---|
5005 | |
---|
5006 | handleMouseDown : function(e){ |
---|
5007 | var ev = Ext.EventObject.setEvent(e); |
---|
5008 | var t = this.fly(ev.getTarget()); |
---|
5009 | if(t.hasClass("x-grid-split")){ |
---|
5010 | this.cellIndex = this.view.getCellIndex(t.dom); |
---|
5011 | this.split = t.dom; |
---|
5012 | this.cm = this.grid.colModel; |
---|
5013 | if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){ |
---|
5014 | Ext.grid.SplitDragZone.superclass.handleMouseDown.apply(this, arguments); |
---|
5015 | } |
---|
5016 | } |
---|
5017 | }, |
---|
5018 | |
---|
5019 | endDrag : function(e){ |
---|
5020 | this.view.headersDisabled = false; |
---|
5021 | var endX = Math.max(this.minX, Ext.lib.Event.getPageX(e)); |
---|
5022 | var diff = endX - this.startPos; |
---|
5023 | this.view.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff); |
---|
5024 | }, |
---|
5025 | |
---|
5026 | autoOffset : function(){ |
---|
5027 | this.setDelta(0,0); |
---|
5028 | } |
---|
5029 | });/** |
---|
5030 | * @class Ext.grid.GridDragZone |
---|
5031 | * @extends Ext.dd.DragZone |
---|
5032 | * <p>A customized implementation of a {@link Ext.dd.DragZone DragZone} which provides default implementations of two of the |
---|
5033 | * template methods of DragZone to enable dragging of the selected rows of a GridPanel.</p> |
---|
5034 | * <p>A cooperating {@link Ext.dd.DropZone DropZone} must be created who's template method implementations of |
---|
5035 | * {@link Ext.dd.DropZone#onNodeEnter onNodeEnter}, {@link Ext.dd.DropZone#onNodeOver onNodeOver}, |
---|
5036 | * {@link Ext.dd.DropZone#onNodeOut onNodeOut} and {@link Ext.dd.DropZone#onNodeDrop onNodeDrop}</p> are able |
---|
5037 | * to process the {@link #getDragData data} which is provided. |
---|
5038 | */ |
---|
5039 | Ext.grid.GridDragZone = function(grid, config){ |
---|
5040 | this.view = grid.getView(); |
---|
5041 | Ext.grid.GridDragZone.superclass.constructor.call(this, this.view.mainBody.dom, config); |
---|
5042 | this.scroll = false; |
---|
5043 | this.grid = grid; |
---|
5044 | this.ddel = document.createElement('div'); |
---|
5045 | this.ddel.className = 'x-grid-dd-wrap'; |
---|
5046 | }; |
---|
5047 | |
---|
5048 | Ext.extend(Ext.grid.GridDragZone, Ext.dd.DragZone, { |
---|
5049 | ddGroup : "GridDD", |
---|
5050 | |
---|
5051 | /** |
---|
5052 | * <p>The provided implementation of the getDragData method which collects the data to be dragged from the GridPanel on mousedown.</p> |
---|
5053 | * <p>This data is available for processing in the {@link Ext.dd.DropZone#onNodeEnter onNodeEnter}, {@link Ext.dd.DropZone#onNodeOver onNodeOver}, |
---|
5054 | * {@link Ext.dd.DropZone#onNodeOut onNodeOut} and {@link Ext.dd.DropZone#onNodeDrop onNodeDrop} methods of a cooperating {@link Ext.dd.DropZone DropZone}.</p> |
---|
5055 | * <p>The data object contains the following properties:<ul> |
---|
5056 | * <li><b>grid</b> : Ext.Grid.GridPanel<div class="sub-desc">The GridPanel from which the data is being dragged.</div></li> |
---|
5057 | * <li><b>ddel</b> : htmlElement<div class="sub-desc">An htmlElement which provides the "picture" of the data being dragged.</div></li> |
---|
5058 | * <li><b>rowIndex</b> : Number<div class="sub-desc">The index of the row which receieved the mousedown gesture which triggered the drag.</div></li> |
---|
5059 | * <li><b>selections</b> : Array<div class="sub-desc">An Array of the selected Records which are being dragged from the GridPanel.</div></li> |
---|
5060 | * </ul></p> |
---|
5061 | */ |
---|
5062 | getDragData : function(e){ |
---|
5063 | var t = Ext.lib.Event.getTarget(e); |
---|
5064 | var rowIndex = this.view.findRowIndex(t); |
---|
5065 | if(rowIndex !== false){ |
---|
5066 | var sm = this.grid.selModel; |
---|
5067 | if(!sm.isSelected(rowIndex) || e.hasModifier()){ |
---|
5068 | sm.handleMouseDown(this.grid, rowIndex, e); |
---|
5069 | } |
---|
5070 | return {grid: this.grid, ddel: this.ddel, rowIndex: rowIndex, selections:sm.getSelections()}; |
---|
5071 | } |
---|
5072 | return false; |
---|
5073 | }, |
---|
5074 | |
---|
5075 | /** |
---|
5076 | * <p>The provided implementation of the onInitDrag method. Sets the <tt>innerHTML</tt> of the drag proxy which provides the "picture" |
---|
5077 | * of the data being dragged.</p> |
---|
5078 | * <p>The <tt>innerHTML</tt> data is found by calling the owning GridPanel's {@link Ext.grid.GridPanel#getDragDropText getDragDropText}.</p> |
---|
5079 | */ |
---|
5080 | onInitDrag : function(e){ |
---|
5081 | var data = this.dragData; |
---|
5082 | this.ddel.innerHTML = this.grid.getDragDropText(); |
---|
5083 | this.proxy.update(this.ddel); |
---|
5084 | // fire start drag? |
---|
5085 | }, |
---|
5086 | |
---|
5087 | /** |
---|
5088 | * An empty immplementation. Implement this to provide behaviour after a repair of an invalid drop. An implementation might highlight |
---|
5089 | * the selected rows to show that they have not been dragged. |
---|
5090 | */ |
---|
5091 | afterRepair : function(){ |
---|
5092 | this.dragging = false; |
---|
5093 | }, |
---|
5094 | |
---|
5095 | /** |
---|
5096 | * <p>An empty implementation. Implement this to provide coordinates for the drag proxy to slide back to after an invalid drop.</p> |
---|
5097 | * <p>Called before a repair of an invalid drop to get the XY to animate to.</p> |
---|
5098 | * @param {EventObject} e The mouse up event |
---|
5099 | * @return {Array} The xy location (e.g. [100, 200]) |
---|
5100 | */ |
---|
5101 | getRepairXY : function(e, data){ |
---|
5102 | return false; |
---|
5103 | }, |
---|
5104 | |
---|
5105 | onEndDrag : function(data, e){ |
---|
5106 | // fire end drag? |
---|
5107 | }, |
---|
5108 | |
---|
5109 | onValidDrop : function(dd, e, id){ |
---|
5110 | // fire drag drop? |
---|
5111 | this.hideProxy(); |
---|
5112 | }, |
---|
5113 | |
---|
5114 | beforeInvalidDrop : function(e, id){ |
---|
5115 | |
---|
5116 | } |
---|
5117 | }); |
---|
5118 | /** |
---|
5119 | * @class Ext.grid.ColumnModel |
---|
5120 | * @extends Ext.util.Observable |
---|
5121 | * <p>After the data has been read into the client side cache (<b>{@link Ext.data.Store Store}</b>), |
---|
5122 | * the ColumnModel is used to configure how and what parts of that data will be displayed in the |
---|
5123 | * vertical slices (columns) of the grid. The Ext.grid.ColumnModel Class is the default implementation |
---|
5124 | * of a ColumnModel used by implentations of {@link Ext.grid.GridPanel GridPanel}.</p> |
---|
5125 | * <p>Data is mapped into the store's records and then indexed into the ColumnModel using the |
---|
5126 | * <tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt>:</p> |
---|
5127 | * <pre><code> |
---|
5128 | {data source} == mapping ==> {data store} == <b><tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt></b> ==> {ColumnModel} |
---|
5129 | * </code></pre> |
---|
5130 | * <p>Each {@link Ext.grid.Column Column} in the grid's ColumnModel is configured with a |
---|
5131 | * <tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt> to specify how the data within |
---|
5132 | * each record in the store is indexed into the ColumnModel.</p> |
---|
5133 | * <p>There are two ways to initialize the ColumnModel class:</p> |
---|
5134 | * <p><u>Initialization Method 1: an Array</u></p> |
---|
5135 | <pre><code> |
---|
5136 | var colModel = new Ext.grid.ColumnModel([ |
---|
5137 | { header: "Ticker", width: 60, sortable: true}, |
---|
5138 | { header: "Company Name", width: 150, sortable: true, id: 'company'}, |
---|
5139 | { header: "Market Cap.", width: 100, sortable: true}, |
---|
5140 | { header: "$ Sales", width: 100, sortable: true, renderer: money}, |
---|
5141 | { header: "Employees", width: 100, sortable: true, resizable: false} |
---|
5142 | ]); |
---|
5143 | </code></pre> |
---|
5144 | * <p>The ColumnModel may be initialized with an Array of {@link Ext.grid.Column} column configuration |
---|
5145 | * objects to define the initial layout / display of the columns in the Grid. The order of each |
---|
5146 | * {@link Ext.grid.Column} column configuration object within the specified Array defines the initial |
---|
5147 | * order of the column display. A Column's display may be initially hidden using the |
---|
5148 | * <tt>{@link Ext.grid.Column#hidden hidden}</tt></b> config property (and then shown using the column |
---|
5149 | * header menu). Fields that are not included in the ColumnModel will not be displayable at all.</p> |
---|
5150 | * <p>How each column in the grid correlates (maps) to the {@link Ext.data.Record} field in the |
---|
5151 | * {@link Ext.data.Store Store} the column draws its data from is configured through the |
---|
5152 | * <b><tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt></b>. If the |
---|
5153 | * <b><tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt></b> is not explicitly defined (as shown in the |
---|
5154 | * example above) it will use the column configuration's index in the Array as the index.</p> |
---|
5155 | * <p>See <b><tt>{@link Ext.grid.Column}</tt></b> for additional configuration options for each column.</p> |
---|
5156 | * <p><u>Initialization Method 2: an Object</u></p> |
---|
5157 | * <p>In order to use configuration options from <tt>Ext.grid.ColumnModel</tt>, an Object may be used to |
---|
5158 | * initialize the ColumnModel. The column configuration Array will be specified in the <tt><b>{@link #columns}</b></tt> |
---|
5159 | * config property. The <tt><b>{@link #defaults}</b></tt> config property can be used to apply defaults |
---|
5160 | * for all columns, e.g.:</p><pre><code> |
---|
5161 | var colModel = new Ext.grid.ColumnModel({ |
---|
5162 | columns: [ |
---|
5163 | { header: "Ticker", width: 60, menuDisabled: false}, |
---|
5164 | { header: "Company Name", width: 150, id: 'company'}, |
---|
5165 | { header: "Market Cap."}, |
---|
5166 | { header: "$ Sales", renderer: money}, |
---|
5167 | { header: "Employees", resizable: false} |
---|
5168 | ], |
---|
5169 | defaults: { |
---|
5170 | sortable: true, |
---|
5171 | menuDisabled: true, |
---|
5172 | width: 100 |
---|
5173 | }, |
---|
5174 | listeners: { |
---|
5175 | {@link #hiddenchange}: function(cm, colIndex, hidden) { |
---|
5176 | saveConfig(colIndex, hidden); |
---|
5177 | } |
---|
5178 | } |
---|
5179 | }); |
---|
5180 | </code></pre> |
---|
5181 | * <p>In both examples above, the ability to apply a CSS class to all cells in a column (including the |
---|
5182 | * header) is demonstrated through the use of the <b><tt>{@link Ext.grid.Column#id id}</tt></b> config |
---|
5183 | * option. This column could be styled by including the following css:</p><pre><code> |
---|
5184 | //add this css *after* the core css is loaded |
---|
5185 | .x-grid3-td-company { |
---|
5186 | color: red; // entire column will have red font |
---|
5187 | } |
---|
5188 | // modify the header row only, adding an icon to the column header |
---|
5189 | .x-grid3-hd-company { |
---|
5190 | background: transparent |
---|
5191 | url(../../resources/images/icons/silk/building.png) |
---|
5192 | no-repeat 3px 3px ! important; |
---|
5193 | padding-left:20px; |
---|
5194 | } |
---|
5195 | </code></pre> |
---|
5196 | * Note that the "Company Name" column could be specified as the |
---|
5197 | * <b><tt>{@link Ext.grid.GridPanel}.{@link Ext.grid.GridPanel#autoExpandColumn autoExpandColumn}</tt></b>. |
---|
5198 | * @constructor |
---|
5199 | * @param {Mixed} config Specify either an Array of {@link Ext.grid.Column} configuration objects or specify |
---|
5200 | * a configuration Object (see introductory section discussion utilizing Initialization Method 2 above). |
---|
5201 | */ |
---|
5202 | Ext.grid.ColumnModel = Ext.extend(Ext.util.Observable, { |
---|
5203 | /** |
---|
5204 | * @cfg {Number} defaultWidth (optional) The width of columns which have no <tt>{@link #width}</tt> |
---|
5205 | * specified (defaults to <tt>100</tt>). This property shall preferably be configured through the |
---|
5206 | * <tt><b>{@link #defaults}</b></tt> config property. |
---|
5207 | */ |
---|
5208 | defaultWidth: 100, |
---|
5209 | |
---|
5210 | /** |
---|
5211 | * @cfg {Boolean} defaultSortable (optional) Default sortable of columns which have no |
---|
5212 | * sortable specified (defaults to <tt>false</tt>). This property shall preferably be configured |
---|
5213 | * through the <tt><b>{@link #defaults}</b></tt> config property. |
---|
5214 | */ |
---|
5215 | defaultSortable: false, |
---|
5216 | |
---|
5217 | /** |
---|
5218 | * @cfg {Array} columns An Array of object literals. The config options defined by |
---|
5219 | * <b>{@link Ext.grid.Column}</b> are the options which may appear in the object literal for each |
---|
5220 | * individual column definition. |
---|
5221 | */ |
---|
5222 | |
---|
5223 | /** |
---|
5224 | * @cfg {Object} defaults Object literal which will be used to apply {@link Ext.grid.Column} |
---|
5225 | * configuration options to all <tt><b>{@link #columns}</b></tt>. Configuration options specified with |
---|
5226 | * individual {@link Ext.grid.Column column} configs will supersede these <tt><b>{@link #defaults}</b></tt>. |
---|
5227 | */ |
---|
5228 | |
---|
5229 | constructor : function(config) { |
---|
5230 | /** |
---|
5231 | * An Array of {@link Ext.grid.Column Column definition} objects representing the configuration |
---|
5232 | * of this ColumnModel. See {@link Ext.grid.Column} for the configuration properties that may |
---|
5233 | * be specified. |
---|
5234 | * @property config |
---|
5235 | * @type Array |
---|
5236 | */ |
---|
5237 | if (config.columns) { |
---|
5238 | Ext.apply(this, config); |
---|
5239 | this.setConfig(config.columns, true); |
---|
5240 | } else { |
---|
5241 | this.setConfig(config, true); |
---|
5242 | } |
---|
5243 | |
---|
5244 | this.addEvents( |
---|
5245 | /** |
---|
5246 | * @event widthchange |
---|
5247 | * Fires when the width of a column is programmaticially changed using |
---|
5248 | * <code>{@link #setColumnWidth}</code>. |
---|
5249 | * Note internal resizing suppresses the event from firing. See also |
---|
5250 | * {@link Ext.grid.GridPanel}.<code>{@link #columnresize}</code>. |
---|
5251 | * @param {ColumnModel} this |
---|
5252 | * @param {Number} columnIndex The column index |
---|
5253 | * @param {Number} newWidth The new width |
---|
5254 | */ |
---|
5255 | "widthchange", |
---|
5256 | |
---|
5257 | /** |
---|
5258 | * @event headerchange |
---|
5259 | * Fires when the text of a header changes. |
---|
5260 | * @param {ColumnModel} this |
---|
5261 | * @param {Number} columnIndex The column index |
---|
5262 | * @param {String} newText The new header text |
---|
5263 | */ |
---|
5264 | "headerchange", |
---|
5265 | |
---|
5266 | /** |
---|
5267 | * @event hiddenchange |
---|
5268 | * Fires when a column is hidden or "unhidden". |
---|
5269 | * @param {ColumnModel} this |
---|
5270 | * @param {Number} columnIndex The column index |
---|
5271 | * @param {Boolean} hidden true if hidden, false otherwise |
---|
5272 | */ |
---|
5273 | "hiddenchange", |
---|
5274 | |
---|
5275 | /** |
---|
5276 | * @event columnmoved |
---|
5277 | * Fires when a column is moved. |
---|
5278 | * @param {ColumnModel} this |
---|
5279 | * @param {Number} oldIndex |
---|
5280 | * @param {Number} newIndex |
---|
5281 | */ |
---|
5282 | "columnmoved", |
---|
5283 | |
---|
5284 | /** |
---|
5285 | * @event configchange |
---|
5286 | * Fires when the configuration is changed |
---|
5287 | * @param {ColumnModel} this |
---|
5288 | */ |
---|
5289 | "configchange" |
---|
5290 | ); |
---|
5291 | |
---|
5292 | Ext.grid.ColumnModel.superclass.constructor.call(this); |
---|
5293 | }, |
---|
5294 | |
---|
5295 | /** |
---|
5296 | * Returns the id of the column at the specified index. |
---|
5297 | * @param {Number} index The column index |
---|
5298 | * @return {String} the id |
---|
5299 | */ |
---|
5300 | getColumnId : function(index) { |
---|
5301 | return this.config[index].id; |
---|
5302 | }, |
---|
5303 | |
---|
5304 | getColumnAt : function(index) { |
---|
5305 | return this.config[index]; |
---|
5306 | }, |
---|
5307 | |
---|
5308 | /** |
---|
5309 | * <p>Reconfigures this column model according to the passed Array of column definition objects. |
---|
5310 | * For a description of the individual properties of a column definition object, see the |
---|
5311 | * <a href="#Ext.grid.ColumnModel-configs">Config Options</a>.</p> |
---|
5312 | * <p>Causes the {@link #configchange} event to be fired. A {@link Ext.grid.GridPanel GridPanel} |
---|
5313 | * using this ColumnModel will listen for this event and refresh its UI automatically.</p> |
---|
5314 | * @param {Array} config Array of Column definition objects. |
---|
5315 | * @param {Boolean} initial Specify <tt>true</tt> to bypass cleanup which deletes the <tt>totalWidth</tt> |
---|
5316 | * and destroys existing editors. |
---|
5317 | */ |
---|
5318 | setConfig : function(config, initial) { |
---|
5319 | var i, c, len; |
---|
5320 | |
---|
5321 | if (!initial) { // cleanup |
---|
5322 | delete this.totalWidth; |
---|
5323 | |
---|
5324 | for (i = 0, len = this.config.length; i < len; i++) { |
---|
5325 | c = this.config[i]; |
---|
5326 | |
---|
5327 | if (c.setEditor) { |
---|
5328 | //check here, in case we have a special column like a CheckboxSelectionModel |
---|
5329 | c.setEditor(null); |
---|
5330 | } |
---|
5331 | } |
---|
5332 | } |
---|
5333 | |
---|
5334 | // backward compatibility |
---|
5335 | this.defaults = Ext.apply({ |
---|
5336 | width: this.defaultWidth, |
---|
5337 | sortable: this.defaultSortable |
---|
5338 | }, this.defaults); |
---|
5339 | |
---|
5340 | this.config = config; |
---|
5341 | this.lookup = {}; |
---|
5342 | |
---|
5343 | for (i = 0, len = config.length; i < len; i++) { |
---|
5344 | c = Ext.applyIf(config[i], this.defaults); |
---|
5345 | |
---|
5346 | // if no id, create one using column's ordinal position |
---|
5347 | if (Ext.isEmpty(c.id)) { |
---|
5348 | c.id = i; |
---|
5349 | } |
---|
5350 | |
---|
5351 | if (!c.isColumn) { |
---|
5352 | var Cls = Ext.grid.Column.types[c.xtype || 'gridcolumn']; |
---|
5353 | c = new Cls(c); |
---|
5354 | config[i] = c; |
---|
5355 | } |
---|
5356 | |
---|
5357 | this.lookup[c.id] = c; |
---|
5358 | } |
---|
5359 | |
---|
5360 | if (!initial) { |
---|
5361 | this.fireEvent('configchange', this); |
---|
5362 | } |
---|
5363 | }, |
---|
5364 | |
---|
5365 | /** |
---|
5366 | * Returns the column for a specified id. |
---|
5367 | * @param {String} id The column id |
---|
5368 | * @return {Object} the column |
---|
5369 | */ |
---|
5370 | getColumnById : function(id) { |
---|
5371 | return this.lookup[id]; |
---|
5372 | }, |
---|
5373 | |
---|
5374 | /** |
---|
5375 | * Returns the index for a specified column id. |
---|
5376 | * @param {String} id The column id |
---|
5377 | * @return {Number} the index, or -1 if not found |
---|
5378 | */ |
---|
5379 | getIndexById : function(id) { |
---|
5380 | for (var i = 0, len = this.config.length; i < len; i++) { |
---|
5381 | if (this.config[i].id == id) { |
---|
5382 | return i; |
---|
5383 | } |
---|
5384 | } |
---|
5385 | return -1; |
---|
5386 | }, |
---|
5387 | |
---|
5388 | /** |
---|
5389 | * Moves a column from one position to another. |
---|
5390 | * @param {Number} oldIndex The index of the column to move. |
---|
5391 | * @param {Number} newIndex The position at which to reinsert the coolumn. |
---|
5392 | */ |
---|
5393 | moveColumn : function(oldIndex, newIndex) { |
---|
5394 | var config = this.config, |
---|
5395 | c = config[oldIndex]; |
---|
5396 | |
---|
5397 | config.splice(oldIndex, 1); |
---|
5398 | config.splice(newIndex, 0, c); |
---|
5399 | this.dataMap = null; |
---|
5400 | this.fireEvent("columnmoved", this, oldIndex, newIndex); |
---|
5401 | }, |
---|
5402 | |
---|
5403 | /** |
---|
5404 | * Returns the number of columns. |
---|
5405 | * @param {Boolean} visibleOnly Optional. Pass as true to only include visible columns. |
---|
5406 | * @return {Number} |
---|
5407 | */ |
---|
5408 | getColumnCount : function(visibleOnly) { |
---|
5409 | var length = this.config.length, |
---|
5410 | c = 0, |
---|
5411 | i; |
---|
5412 | |
---|
5413 | if (visibleOnly === true) { |
---|
5414 | for (i = 0; i < length; i++) { |
---|
5415 | if (!this.isHidden(i)) { |
---|
5416 | c++; |
---|
5417 | } |
---|
5418 | } |
---|
5419 | |
---|
5420 | return c; |
---|
5421 | } |
---|
5422 | |
---|
5423 | return length; |
---|
5424 | }, |
---|
5425 | |
---|
5426 | /** |
---|
5427 | * Returns the column configs that return true by the passed function that is called |
---|
5428 | * with (columnConfig, index) |
---|
5429 | <pre><code> |
---|
5430 | // returns an array of column config objects for all hidden columns |
---|
5431 | var columns = grid.getColumnModel().getColumnsBy(function(c){ |
---|
5432 | return c.hidden; |
---|
5433 | }); |
---|
5434 | </code></pre> |
---|
5435 | * @param {Function} fn A function which, when passed a {@link Ext.grid.Column Column} object, must |
---|
5436 | * return <code>true</code> if the column is to be included in the returned Array. |
---|
5437 | * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function |
---|
5438 | * is executed. Defaults to this ColumnModel. |
---|
5439 | * @return {Array} result |
---|
5440 | */ |
---|
5441 | getColumnsBy : function(fn, scope) { |
---|
5442 | var config = this.config, |
---|
5443 | length = config.length, |
---|
5444 | result = [], |
---|
5445 | i, c; |
---|
5446 | |
---|
5447 | for (i = 0; i < length; i++){ |
---|
5448 | c = config[i]; |
---|
5449 | |
---|
5450 | if (fn.call(scope || this, c, i) === true) { |
---|
5451 | result[result.length] = c; |
---|
5452 | } |
---|
5453 | } |
---|
5454 | |
---|
5455 | return result; |
---|
5456 | }, |
---|
5457 | |
---|
5458 | /** |
---|
5459 | * Returns true if the specified column is sortable. |
---|
5460 | * @param {Number} col The column index |
---|
5461 | * @return {Boolean} |
---|
5462 | */ |
---|
5463 | isSortable : function(col) { |
---|
5464 | return !!this.config[col].sortable; |
---|
5465 | }, |
---|
5466 | |
---|
5467 | /** |
---|
5468 | * Returns true if the specified column menu is disabled. |
---|
5469 | * @param {Number} col The column index |
---|
5470 | * @return {Boolean} |
---|
5471 | */ |
---|
5472 | isMenuDisabled : function(col) { |
---|
5473 | return !!this.config[col].menuDisabled; |
---|
5474 | }, |
---|
5475 | |
---|
5476 | /** |
---|
5477 | * Returns the rendering (formatting) function defined for the column. |
---|
5478 | * @param {Number} col The column index. |
---|
5479 | * @return {Function} The function used to render the cell. See {@link #setRenderer}. |
---|
5480 | */ |
---|
5481 | getRenderer : function(col) { |
---|
5482 | return this.config[col].renderer || Ext.grid.ColumnModel.defaultRenderer; |
---|
5483 | }, |
---|
5484 | |
---|
5485 | getRendererScope : function(col) { |
---|
5486 | return this.config[col].scope; |
---|
5487 | }, |
---|
5488 | |
---|
5489 | /** |
---|
5490 | * Sets the rendering (formatting) function for a column. See {@link Ext.util.Format} for some |
---|
5491 | * default formatting functions. |
---|
5492 | * @param {Number} col The column index |
---|
5493 | * @param {Function} fn The function to use to process the cell's raw data |
---|
5494 | * to return HTML markup for the grid view. The render function is called with |
---|
5495 | * the following parameters:<ul> |
---|
5496 | * <li><b>value</b> : Object<p class="sub-desc">The data value for the cell.</p></li> |
---|
5497 | * <li><b>metadata</b> : Object<p class="sub-desc">An object in which you may set the following attributes:<ul> |
---|
5498 | * <li><b>css</b> : String<p class="sub-desc">A CSS class name to add to the cell's TD element.</p></li> |
---|
5499 | * <li><b>attr</b> : String<p class="sub-desc">An HTML attribute definition string to apply to the data container element <i>within</i> the table cell |
---|
5500 | * (e.g. 'style="color:red;"').</p></li></ul></p></li> |
---|
5501 | * <li><b>record</b> : Ext.data.record<p class="sub-desc">The {@link Ext.data.Record} from which the data was extracted.</p></li> |
---|
5502 | * <li><b>rowIndex</b> : Number<p class="sub-desc">Row index</p></li> |
---|
5503 | * <li><b>colIndex</b> : Number<p class="sub-desc">Column index</p></li> |
---|
5504 | * <li><b>store</b> : Ext.data.Store<p class="sub-desc">The {@link Ext.data.Store} object from which the Record was extracted.</p></li></ul> |
---|
5505 | */ |
---|
5506 | setRenderer : function(col, fn) { |
---|
5507 | this.config[col].renderer = fn; |
---|
5508 | }, |
---|
5509 | |
---|
5510 | /** |
---|
5511 | * Returns the width for the specified column. |
---|
5512 | * @param {Number} col The column index |
---|
5513 | * @return {Number} |
---|
5514 | */ |
---|
5515 | getColumnWidth : function(col) { |
---|
5516 | var width = this.config[col].width; |
---|
5517 | if(typeof width != 'number'){ |
---|
5518 | width = this.defaultWidth; |
---|
5519 | } |
---|
5520 | return width; |
---|
5521 | }, |
---|
5522 | |
---|
5523 | /** |
---|
5524 | * Sets the width for a column. |
---|
5525 | * @param {Number} col The column index |
---|
5526 | * @param {Number} width The new width |
---|
5527 | * @param {Boolean} suppressEvent True to suppress firing the <code>{@link #widthchange}</code> |
---|
5528 | * event. Defaults to false. |
---|
5529 | */ |
---|
5530 | setColumnWidth : function(col, width, suppressEvent) { |
---|
5531 | this.config[col].width = width; |
---|
5532 | this.totalWidth = null; |
---|
5533 | |
---|
5534 | if (!suppressEvent) { |
---|
5535 | this.fireEvent("widthchange", this, col, width); |
---|
5536 | } |
---|
5537 | }, |
---|
5538 | |
---|
5539 | /** |
---|
5540 | * Returns the total width of all columns. |
---|
5541 | * @param {Boolean} includeHidden True to include hidden column widths |
---|
5542 | * @return {Number} |
---|
5543 | */ |
---|
5544 | getTotalWidth : function(includeHidden) { |
---|
5545 | if (!this.totalWidth) { |
---|
5546 | this.totalWidth = 0; |
---|
5547 | for (var i = 0, len = this.config.length; i < len; i++) { |
---|
5548 | if (includeHidden || !this.isHidden(i)) { |
---|
5549 | this.totalWidth += this.getColumnWidth(i); |
---|
5550 | } |
---|
5551 | } |
---|
5552 | } |
---|
5553 | return this.totalWidth; |
---|
5554 | }, |
---|
5555 | |
---|
5556 | /** |
---|
5557 | * Returns the header for the specified column. |
---|
5558 | * @param {Number} col The column index |
---|
5559 | * @return {String} |
---|
5560 | */ |
---|
5561 | getColumnHeader : function(col) { |
---|
5562 | return this.config[col].header; |
---|
5563 | }, |
---|
5564 | |
---|
5565 | /** |
---|
5566 | * Sets the header for a column. |
---|
5567 | * @param {Number} col The column index |
---|
5568 | * @param {String} header The new header |
---|
5569 | */ |
---|
5570 | setColumnHeader : function(col, header) { |
---|
5571 | this.config[col].header = header; |
---|
5572 | this.fireEvent("headerchange", this, col, header); |
---|
5573 | }, |
---|
5574 | |
---|
5575 | /** |
---|
5576 | * Returns the tooltip for the specified column. |
---|
5577 | * @param {Number} col The column index |
---|
5578 | * @return {String} |
---|
5579 | */ |
---|
5580 | getColumnTooltip : function(col) { |
---|
5581 | return this.config[col].tooltip; |
---|
5582 | }, |
---|
5583 | /** |
---|
5584 | * Sets the tooltip for a column. |
---|
5585 | * @param {Number} col The column index |
---|
5586 | * @param {String} tooltip The new tooltip |
---|
5587 | */ |
---|
5588 | setColumnTooltip : function(col, tooltip) { |
---|
5589 | this.config[col].tooltip = tooltip; |
---|
5590 | }, |
---|
5591 | |
---|
5592 | /** |
---|
5593 | * Returns the dataIndex for the specified column. |
---|
5594 | <pre><code> |
---|
5595 | // Get field name for the column |
---|
5596 | var fieldName = grid.getColumnModel().getDataIndex(columnIndex); |
---|
5597 | </code></pre> |
---|
5598 | * @param {Number} col The column index |
---|
5599 | * @return {String} The column's dataIndex |
---|
5600 | */ |
---|
5601 | getDataIndex : function(col) { |
---|
5602 | return this.config[col].dataIndex; |
---|
5603 | }, |
---|
5604 | |
---|
5605 | /** |
---|
5606 | * Sets the dataIndex for a column. |
---|
5607 | * @param {Number} col The column index |
---|
5608 | * @param {String} dataIndex The new dataIndex |
---|
5609 | */ |
---|
5610 | setDataIndex : function(col, dataIndex) { |
---|
5611 | this.config[col].dataIndex = dataIndex; |
---|
5612 | }, |
---|
5613 | |
---|
5614 | /** |
---|
5615 | * Finds the index of the first matching column for the given dataIndex. |
---|
5616 | * @param {String} col The dataIndex to find |
---|
5617 | * @return {Number} The column index, or -1 if no match was found |
---|
5618 | */ |
---|
5619 | findColumnIndex : function(dataIndex) { |
---|
5620 | var c = this.config; |
---|
5621 | for(var i = 0, len = c.length; i < len; i++){ |
---|
5622 | if(c[i].dataIndex == dataIndex){ |
---|
5623 | return i; |
---|
5624 | } |
---|
5625 | } |
---|
5626 | return -1; |
---|
5627 | }, |
---|
5628 | |
---|
5629 | /** |
---|
5630 | * Returns true if the cell is editable. |
---|
5631 | <pre><code> |
---|
5632 | var store = new Ext.data.Store({...}); |
---|
5633 | var colModel = new Ext.grid.ColumnModel({ |
---|
5634 | columns: [...], |
---|
5635 | isCellEditable: function(col, row) { |
---|
5636 | var record = store.getAt(row); |
---|
5637 | if (record.get('readonly')) { // replace with your condition |
---|
5638 | return false; |
---|
5639 | } |
---|
5640 | return Ext.grid.ColumnModel.prototype.isCellEditable.call(this, col, row); |
---|
5641 | } |
---|
5642 | }); |
---|
5643 | var grid = new Ext.grid.GridPanel({ |
---|
5644 | store: store, |
---|
5645 | colModel: colModel, |
---|
5646 | ... |
---|
5647 | }); |
---|
5648 | </code></pre> |
---|
5649 | * @param {Number} colIndex The column index |
---|
5650 | * @param {Number} rowIndex The row index |
---|
5651 | * @return {Boolean} |
---|
5652 | */ |
---|
5653 | isCellEditable : function(colIndex, rowIndex) { |
---|
5654 | var c = this.config[colIndex], |
---|
5655 | ed = c.editable; |
---|
5656 | |
---|
5657 | //force boolean |
---|
5658 | return !!(ed || (!Ext.isDefined(ed) && c.editor)); |
---|
5659 | }, |
---|
5660 | |
---|
5661 | /** |
---|
5662 | * Returns the editor defined for the cell/column. |
---|
5663 | * @param {Number} colIndex The column index |
---|
5664 | * @param {Number} rowIndex The row index |
---|
5665 | * @return {Ext.Editor} The {@link Ext.Editor Editor} that was created to wrap |
---|
5666 | * the {@link Ext.form.Field Field} used to edit the cell. |
---|
5667 | */ |
---|
5668 | getCellEditor : function(colIndex, rowIndex) { |
---|
5669 | return this.config[colIndex].getCellEditor(rowIndex); |
---|
5670 | }, |
---|
5671 | |
---|
5672 | /** |
---|
5673 | * Sets if a column is editable. |
---|
5674 | * @param {Number} col The column index |
---|
5675 | * @param {Boolean} editable True if the column is editable |
---|
5676 | */ |
---|
5677 | setEditable : function(col, editable) { |
---|
5678 | this.config[col].editable = editable; |
---|
5679 | }, |
---|
5680 | |
---|
5681 | /** |
---|
5682 | * Returns <tt>true</tt> if the column is <code>{@link Ext.grid.Column#hidden hidden}</code>, |
---|
5683 | * <tt>false</tt> otherwise. |
---|
5684 | * @param {Number} colIndex The column index |
---|
5685 | * @return {Boolean} |
---|
5686 | */ |
---|
5687 | isHidden : function(colIndex) { |
---|
5688 | return !!this.config[colIndex].hidden; // ensure returns boolean |
---|
5689 | }, |
---|
5690 | |
---|
5691 | /** |
---|
5692 | * Returns <tt>true</tt> if the column is <code>{@link Ext.grid.Column#fixed fixed}</code>, |
---|
5693 | * <tt>false</tt> otherwise. |
---|
5694 | * @param {Number} colIndex The column index |
---|
5695 | * @return {Boolean} |
---|
5696 | */ |
---|
5697 | isFixed : function(colIndex) { |
---|
5698 | return !!this.config[colIndex].fixed; |
---|
5699 | }, |
---|
5700 | |
---|
5701 | /** |
---|
5702 | * Returns true if the column can be resized |
---|
5703 | * @return {Boolean} |
---|
5704 | */ |
---|
5705 | isResizable : function(colIndex) { |
---|
5706 | return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true; |
---|
5707 | }, |
---|
5708 | |
---|
5709 | /** |
---|
5710 | * Sets if a column is hidden. |
---|
5711 | <pre><code> |
---|
5712 | myGrid.getColumnModel().setHidden(0, true); // hide column 0 (0 = the first column). |
---|
5713 | </code></pre> |
---|
5714 | * @param {Number} colIndex The column index |
---|
5715 | * @param {Boolean} hidden True if the column is hidden |
---|
5716 | */ |
---|
5717 | setHidden : function(colIndex, hidden) { |
---|
5718 | var c = this.config[colIndex]; |
---|
5719 | if(c.hidden !== hidden){ |
---|
5720 | c.hidden = hidden; |
---|
5721 | this.totalWidth = null; |
---|
5722 | this.fireEvent("hiddenchange", this, colIndex, hidden); |
---|
5723 | } |
---|
5724 | }, |
---|
5725 | |
---|
5726 | /** |
---|
5727 | * Sets the editor for a column and destroys the prior editor. |
---|
5728 | * @param {Number} col The column index |
---|
5729 | * @param {Object} editor The editor object |
---|
5730 | */ |
---|
5731 | setEditor : function(col, editor) { |
---|
5732 | this.config[col].setEditor(editor); |
---|
5733 | }, |
---|
5734 | |
---|
5735 | /** |
---|
5736 | * Destroys this column model by purging any event listeners. Destroys and dereferences all Columns. |
---|
5737 | */ |
---|
5738 | destroy : function() { |
---|
5739 | var length = this.config.length, |
---|
5740 | i = 0; |
---|
5741 | |
---|
5742 | for (; i < length; i++){ |
---|
5743 | this.config[i].destroy(); // Column's destroy encapsulates all cleanup. |
---|
5744 | } |
---|
5745 | delete this.config; |
---|
5746 | delete this.lookup; |
---|
5747 | this.purgeListeners(); |
---|
5748 | }, |
---|
5749 | |
---|
5750 | /** |
---|
5751 | * @private |
---|
5752 | * Setup any saved state for the column, ensures that defaults are applied. |
---|
5753 | */ |
---|
5754 | setState : function(col, state) { |
---|
5755 | state = Ext.applyIf(state, this.defaults); |
---|
5756 | Ext.apply(this.config[col], state); |
---|
5757 | } |
---|
5758 | }); |
---|
5759 | |
---|
5760 | // private |
---|
5761 | Ext.grid.ColumnModel.defaultRenderer = function(value) { |
---|
5762 | if (typeof value == "string" && value.length < 1) { |
---|
5763 | return " "; |
---|
5764 | } |
---|
5765 | return value; |
---|
5766 | };/** |
---|
5767 | * @class Ext.grid.AbstractSelectionModel |
---|
5768 | * @extends Ext.util.Observable |
---|
5769 | * Abstract base class for grid SelectionModels. It provides the interface that should be |
---|
5770 | * implemented by descendant classes. This class should not be directly instantiated. |
---|
5771 | * @constructor |
---|
5772 | */ |
---|
5773 | Ext.grid.AbstractSelectionModel = Ext.extend(Ext.util.Observable, { |
---|
5774 | /** |
---|
5775 | * The GridPanel for which this SelectionModel is handling selection. Read-only. |
---|
5776 | * @type Object |
---|
5777 | * @property grid |
---|
5778 | */ |
---|
5779 | |
---|
5780 | constructor : function(){ |
---|
5781 | this.locked = false; |
---|
5782 | Ext.grid.AbstractSelectionModel.superclass.constructor.call(this); |
---|
5783 | }, |
---|
5784 | |
---|
5785 | /** @ignore Called by the grid automatically. Do not call directly. */ |
---|
5786 | init : function(grid){ |
---|
5787 | this.grid = grid; |
---|
5788 | if(this.lockOnInit){ |
---|
5789 | delete this.lockOnInit; |
---|
5790 | this.locked = false; |
---|
5791 | this.lock(); |
---|
5792 | } |
---|
5793 | this.initEvents(); |
---|
5794 | }, |
---|
5795 | |
---|
5796 | /** |
---|
5797 | * Locks the selections. |
---|
5798 | */ |
---|
5799 | lock : function(){ |
---|
5800 | if(!this.locked){ |
---|
5801 | this.locked = true; |
---|
5802 | // If the grid has been set, then the view is already initialized. |
---|
5803 | var g = this.grid; |
---|
5804 | if(g){ |
---|
5805 | g.getView().on({ |
---|
5806 | scope: this, |
---|
5807 | beforerefresh: this.sortUnLock, |
---|
5808 | refresh: this.sortLock |
---|
5809 | }); |
---|
5810 | }else{ |
---|
5811 | this.lockOnInit = true; |
---|
5812 | } |
---|
5813 | } |
---|
5814 | }, |
---|
5815 | |
---|
5816 | // set the lock states before and after a view refresh |
---|
5817 | sortLock : function() { |
---|
5818 | this.locked = true; |
---|
5819 | }, |
---|
5820 | |
---|
5821 | // set the lock states before and after a view refresh |
---|
5822 | sortUnLock : function() { |
---|
5823 | this.locked = false; |
---|
5824 | }, |
---|
5825 | |
---|
5826 | /** |
---|
5827 | * Unlocks the selections. |
---|
5828 | */ |
---|
5829 | unlock : function(){ |
---|
5830 | if(this.locked){ |
---|
5831 | this.locked = false; |
---|
5832 | var g = this.grid, |
---|
5833 | gv; |
---|
5834 | |
---|
5835 | // If the grid has been set, then the view is already initialized. |
---|
5836 | if(g){ |
---|
5837 | gv = g.getView(); |
---|
5838 | gv.un('beforerefresh', this.sortUnLock, this); |
---|
5839 | gv.un('refresh', this.sortLock, this); |
---|
5840 | }else{ |
---|
5841 | delete this.lockOnInit; |
---|
5842 | } |
---|
5843 | } |
---|
5844 | }, |
---|
5845 | |
---|
5846 | /** |
---|
5847 | * Returns true if the selections are locked. |
---|
5848 | * @return {Boolean} |
---|
5849 | */ |
---|
5850 | isLocked : function(){ |
---|
5851 | return this.locked; |
---|
5852 | }, |
---|
5853 | |
---|
5854 | destroy: function(){ |
---|
5855 | this.unlock(); |
---|
5856 | this.purgeListeners(); |
---|
5857 | } |
---|
5858 | });/** |
---|
5859 | * @class Ext.grid.RowSelectionModel |
---|
5860 | * @extends Ext.grid.AbstractSelectionModel |
---|
5861 | * The default SelectionModel used by {@link Ext.grid.GridPanel}. |
---|
5862 | * It supports multiple selections and keyboard selection/navigation. The objects stored |
---|
5863 | * as selections and returned by {@link #getSelected}, and {@link #getSelections} are |
---|
5864 | * the {@link Ext.data.Record Record}s which provide the data for the selected rows. |
---|
5865 | * @constructor |
---|
5866 | * @param {Object} config |
---|
5867 | */ |
---|
5868 | Ext.grid.RowSelectionModel = Ext.extend(Ext.grid.AbstractSelectionModel, { |
---|
5869 | /** |
---|
5870 | * @cfg {Boolean} singleSelect |
---|
5871 | * <tt>true</tt> to allow selection of only one row at a time (defaults to <tt>false</tt> |
---|
5872 | * allowing multiple selections) |
---|
5873 | */ |
---|
5874 | singleSelect : false, |
---|
5875 | |
---|
5876 | constructor : function(config){ |
---|
5877 | Ext.apply(this, config); |
---|
5878 | this.selections = new Ext.util.MixedCollection(false, function(o){ |
---|
5879 | return o.id; |
---|
5880 | }); |
---|
5881 | |
---|
5882 | this.last = false; |
---|
5883 | this.lastActive = false; |
---|
5884 | |
---|
5885 | this.addEvents( |
---|
5886 | /** |
---|
5887 | * @event selectionchange |
---|
5888 | * Fires when the selection changes |
---|
5889 | * @param {SelectionModel} this |
---|
5890 | */ |
---|
5891 | 'selectionchange', |
---|
5892 | /** |
---|
5893 | * @event beforerowselect |
---|
5894 | * Fires before a row is selected, return false to cancel the selection. |
---|
5895 | * @param {SelectionModel} this |
---|
5896 | * @param {Number} rowIndex The index to be selected |
---|
5897 | * @param {Boolean} keepExisting False if other selections will be cleared |
---|
5898 | * @param {Record} record The record to be selected |
---|
5899 | */ |
---|
5900 | 'beforerowselect', |
---|
5901 | /** |
---|
5902 | * @event rowselect |
---|
5903 | * Fires when a row is selected. |
---|
5904 | * @param {SelectionModel} this |
---|
5905 | * @param {Number} rowIndex The selected index |
---|
5906 | * @param {Ext.data.Record} r The selected record |
---|
5907 | */ |
---|
5908 | 'rowselect', |
---|
5909 | /** |
---|
5910 | * @event rowdeselect |
---|
5911 | * Fires when a row is deselected. To prevent deselection |
---|
5912 | * {@link Ext.grid.AbstractSelectionModel#lock lock the selections}. |
---|
5913 | * @param {SelectionModel} this |
---|
5914 | * @param {Number} rowIndex |
---|
5915 | * @param {Record} record |
---|
5916 | */ |
---|
5917 | 'rowdeselect' |
---|
5918 | ); |
---|
5919 | Ext.grid.RowSelectionModel.superclass.constructor.call(this); |
---|
5920 | }, |
---|
5921 | |
---|
5922 | /** |
---|
5923 | * @cfg {Boolean} moveEditorOnEnter |
---|
5924 | * <tt>false</tt> to turn off moving the editor to the next row down when the enter key is pressed |
---|
5925 | * or the next row up when shift + enter keys are pressed. |
---|
5926 | */ |
---|
5927 | // private |
---|
5928 | initEvents : function(){ |
---|
5929 | |
---|
5930 | if(!this.grid.enableDragDrop && !this.grid.enableDrag){ |
---|
5931 | this.grid.on('rowmousedown', this.handleMouseDown, this); |
---|
5932 | } |
---|
5933 | |
---|
5934 | this.rowNav = new Ext.KeyNav(this.grid.getGridEl(), { |
---|
5935 | up: this.onKeyPress, |
---|
5936 | down: this.onKeyPress, |
---|
5937 | scope: this |
---|
5938 | }); |
---|
5939 | |
---|
5940 | this.grid.getView().on({ |
---|
5941 | scope: this, |
---|
5942 | refresh: this.onRefresh, |
---|
5943 | rowupdated: this.onRowUpdated, |
---|
5944 | rowremoved: this.onRemove |
---|
5945 | }); |
---|
5946 | }, |
---|
5947 | |
---|
5948 | onKeyPress : function(e, name){ |
---|
5949 | var up = name == 'up', |
---|
5950 | method = up ? 'selectPrevious' : 'selectNext', |
---|
5951 | add = up ? -1 : 1, |
---|
5952 | last; |
---|
5953 | if(!e.shiftKey || this.singleSelect){ |
---|
5954 | this[method](false); |
---|
5955 | }else if(this.last !== false && this.lastActive !== false){ |
---|
5956 | last = this.last; |
---|
5957 | this.selectRange(this.last, this.lastActive + add); |
---|
5958 | this.grid.getView().focusRow(this.lastActive); |
---|
5959 | if(last !== false){ |
---|
5960 | this.last = last; |
---|
5961 | } |
---|
5962 | }else{ |
---|
5963 | this.selectFirstRow(); |
---|
5964 | } |
---|
5965 | }, |
---|
5966 | |
---|
5967 | // private |
---|
5968 | onRefresh : function(){ |
---|
5969 | var ds = this.grid.store, |
---|
5970 | s = this.getSelections(), |
---|
5971 | i = 0, |
---|
5972 | len = s.length, |
---|
5973 | index, r; |
---|
5974 | |
---|
5975 | this.silent = true; |
---|
5976 | this.clearSelections(true); |
---|
5977 | for(; i < len; i++){ |
---|
5978 | r = s[i]; |
---|
5979 | if((index = ds.indexOfId(r.id)) != -1){ |
---|
5980 | this.selectRow(index, true); |
---|
5981 | } |
---|
5982 | } |
---|
5983 | if(s.length != this.selections.getCount()){ |
---|
5984 | this.fireEvent('selectionchange', this); |
---|
5985 | } |
---|
5986 | this.silent = false; |
---|
5987 | }, |
---|
5988 | |
---|
5989 | // private |
---|
5990 | onRemove : function(v, index, r){ |
---|
5991 | if(this.selections.remove(r) !== false){ |
---|
5992 | this.fireEvent('selectionchange', this); |
---|
5993 | } |
---|
5994 | }, |
---|
5995 | |
---|
5996 | // private |
---|
5997 | onRowUpdated : function(v, index, r){ |
---|
5998 | if(this.isSelected(r)){ |
---|
5999 | v.onRowSelect(index); |
---|
6000 | } |
---|
6001 | }, |
---|
6002 | |
---|
6003 | /** |
---|
6004 | * Select records. |
---|
6005 | * @param {Array} records The records to select |
---|
6006 | * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections |
---|
6007 | */ |
---|
6008 | selectRecords : function(records, keepExisting){ |
---|
6009 | if(!keepExisting){ |
---|
6010 | this.clearSelections(); |
---|
6011 | } |
---|
6012 | var ds = this.grid.store, |
---|
6013 | i = 0, |
---|
6014 | len = records.length; |
---|
6015 | for(; i < len; i++){ |
---|
6016 | this.selectRow(ds.indexOf(records[i]), true); |
---|
6017 | } |
---|
6018 | }, |
---|
6019 | |
---|
6020 | /** |
---|
6021 | * Gets the number of selected rows. |
---|
6022 | * @return {Number} |
---|
6023 | */ |
---|
6024 | getCount : function(){ |
---|
6025 | return this.selections.length; |
---|
6026 | }, |
---|
6027 | |
---|
6028 | /** |
---|
6029 | * Selects the first row in the grid. |
---|
6030 | */ |
---|
6031 | selectFirstRow : function(){ |
---|
6032 | this.selectRow(0); |
---|
6033 | }, |
---|
6034 | |
---|
6035 | /** |
---|
6036 | * Select the last row. |
---|
6037 | * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections |
---|
6038 | */ |
---|
6039 | selectLastRow : function(keepExisting){ |
---|
6040 | this.selectRow(this.grid.store.getCount() - 1, keepExisting); |
---|
6041 | }, |
---|
6042 | |
---|
6043 | /** |
---|
6044 | * Selects the row immediately following the last selected row. |
---|
6045 | * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections |
---|
6046 | * @return {Boolean} <tt>true</tt> if there is a next row, else <tt>false</tt> |
---|
6047 | */ |
---|
6048 | selectNext : function(keepExisting){ |
---|
6049 | if(this.hasNext()){ |
---|
6050 | this.selectRow(this.last+1, keepExisting); |
---|
6051 | this.grid.getView().focusRow(this.last); |
---|
6052 | return true; |
---|
6053 | } |
---|
6054 | return false; |
---|
6055 | }, |
---|
6056 | |
---|
6057 | /** |
---|
6058 | * Selects the row that precedes the last selected row. |
---|
6059 | * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections |
---|
6060 | * @return {Boolean} <tt>true</tt> if there is a previous row, else <tt>false</tt> |
---|
6061 | */ |
---|
6062 | selectPrevious : function(keepExisting){ |
---|
6063 | if(this.hasPrevious()){ |
---|
6064 | this.selectRow(this.last-1, keepExisting); |
---|
6065 | this.grid.getView().focusRow(this.last); |
---|
6066 | return true; |
---|
6067 | } |
---|
6068 | return false; |
---|
6069 | }, |
---|
6070 | |
---|
6071 | /** |
---|
6072 | * Returns true if there is a next record to select |
---|
6073 | * @return {Boolean} |
---|
6074 | */ |
---|
6075 | hasNext : function(){ |
---|
6076 | return this.last !== false && (this.last+1) < this.grid.store.getCount(); |
---|
6077 | }, |
---|
6078 | |
---|
6079 | /** |
---|
6080 | * Returns true if there is a previous record to select |
---|
6081 | * @return {Boolean} |
---|
6082 | */ |
---|
6083 | hasPrevious : function(){ |
---|
6084 | return !!this.last; |
---|
6085 | }, |
---|
6086 | |
---|
6087 | |
---|
6088 | /** |
---|
6089 | * Returns the selected records |
---|
6090 | * @return {Array} Array of selected records |
---|
6091 | */ |
---|
6092 | getSelections : function(){ |
---|
6093 | return [].concat(this.selections.items); |
---|
6094 | }, |
---|
6095 | |
---|
6096 | /** |
---|
6097 | * Returns the first selected record. |
---|
6098 | * @return {Record} |
---|
6099 | */ |
---|
6100 | getSelected : function(){ |
---|
6101 | return this.selections.itemAt(0); |
---|
6102 | }, |
---|
6103 | |
---|
6104 | /** |
---|
6105 | * Calls the passed function with each selection. If the function returns |
---|
6106 | * <tt>false</tt>, iteration is stopped and this function returns |
---|
6107 | * <tt>false</tt>. Otherwise it returns <tt>true</tt>. |
---|
6108 | * @param {Function} fn The function to call upon each iteration. It is passed the selected {@link Ext.data.Record Record}. |
---|
6109 | * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this RowSelectionModel. |
---|
6110 | * @return {Boolean} true if all selections were iterated |
---|
6111 | */ |
---|
6112 | each : function(fn, scope){ |
---|
6113 | var s = this.getSelections(), |
---|
6114 | i = 0, |
---|
6115 | len = s.length; |
---|
6116 | |
---|
6117 | for(; i < len; i++){ |
---|
6118 | if(fn.call(scope || this, s[i], i) === false){ |
---|
6119 | return false; |
---|
6120 | } |
---|
6121 | } |
---|
6122 | return true; |
---|
6123 | }, |
---|
6124 | |
---|
6125 | /** |
---|
6126 | * Clears all selections if the selection model |
---|
6127 | * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}. |
---|
6128 | * @param {Boolean} fast (optional) <tt>true</tt> to bypass the |
---|
6129 | * conditional checks and events described in {@link #deselectRow}. |
---|
6130 | */ |
---|
6131 | clearSelections : function(fast){ |
---|
6132 | if(this.isLocked()){ |
---|
6133 | return; |
---|
6134 | } |
---|
6135 | if(fast !== true){ |
---|
6136 | var ds = this.grid.store, |
---|
6137 | s = this.selections; |
---|
6138 | s.each(function(r){ |
---|
6139 | this.deselectRow(ds.indexOfId(r.id)); |
---|
6140 | }, this); |
---|
6141 | s.clear(); |
---|
6142 | }else{ |
---|
6143 | this.selections.clear(); |
---|
6144 | } |
---|
6145 | this.last = false; |
---|
6146 | }, |
---|
6147 | |
---|
6148 | |
---|
6149 | /** |
---|
6150 | * Selects all rows if the selection model |
---|
6151 | * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}. |
---|
6152 | */ |
---|
6153 | selectAll : function(){ |
---|
6154 | if(this.isLocked()){ |
---|
6155 | return; |
---|
6156 | } |
---|
6157 | this.selections.clear(); |
---|
6158 | for(var i = 0, len = this.grid.store.getCount(); i < len; i++){ |
---|
6159 | this.selectRow(i, true); |
---|
6160 | } |
---|
6161 | }, |
---|
6162 | |
---|
6163 | /** |
---|
6164 | * Returns <tt>true</tt> if there is a selection. |
---|
6165 | * @return {Boolean} |
---|
6166 | */ |
---|
6167 | hasSelection : function(){ |
---|
6168 | return this.selections.length > 0; |
---|
6169 | }, |
---|
6170 | |
---|
6171 | /** |
---|
6172 | * Returns <tt>true</tt> if the specified row is selected. |
---|
6173 | * @param {Number/Record} index The record or index of the record to check |
---|
6174 | * @return {Boolean} |
---|
6175 | */ |
---|
6176 | isSelected : function(index){ |
---|
6177 | var r = Ext.isNumber(index) ? this.grid.store.getAt(index) : index; |
---|
6178 | return (r && this.selections.key(r.id) ? true : false); |
---|
6179 | }, |
---|
6180 | |
---|
6181 | /** |
---|
6182 | * Returns <tt>true</tt> if the specified record id is selected. |
---|
6183 | * @param {String} id The id of record to check |
---|
6184 | * @return {Boolean} |
---|
6185 | */ |
---|
6186 | isIdSelected : function(id){ |
---|
6187 | return (this.selections.key(id) ? true : false); |
---|
6188 | }, |
---|
6189 | |
---|
6190 | // private |
---|
6191 | handleMouseDown : function(g, rowIndex, e){ |
---|
6192 | if(e.button !== 0 || this.isLocked()){ |
---|
6193 | return; |
---|
6194 | } |
---|
6195 | var view = this.grid.getView(); |
---|
6196 | if(e.shiftKey && !this.singleSelect && this.last !== false){ |
---|
6197 | var last = this.last; |
---|
6198 | this.selectRange(last, rowIndex, e.ctrlKey); |
---|
6199 | this.last = last; // reset the last |
---|
6200 | view.focusRow(rowIndex); |
---|
6201 | }else{ |
---|
6202 | var isSelected = this.isSelected(rowIndex); |
---|
6203 | if(e.ctrlKey && isSelected){ |
---|
6204 | this.deselectRow(rowIndex); |
---|
6205 | }else if(!isSelected || this.getCount() > 1){ |
---|
6206 | this.selectRow(rowIndex, e.ctrlKey || e.shiftKey); |
---|
6207 | view.focusRow(rowIndex); |
---|
6208 | } |
---|
6209 | } |
---|
6210 | }, |
---|
6211 | |
---|
6212 | /** |
---|
6213 | * Selects multiple rows. |
---|
6214 | * @param {Array} rows Array of the indexes of the row to select |
---|
6215 | * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep |
---|
6216 | * existing selections (defaults to <tt>false</tt>) |
---|
6217 | */ |
---|
6218 | selectRows : function(rows, keepExisting){ |
---|
6219 | if(!keepExisting){ |
---|
6220 | this.clearSelections(); |
---|
6221 | } |
---|
6222 | for(var i = 0, len = rows.length; i < len; i++){ |
---|
6223 | this.selectRow(rows[i], true); |
---|
6224 | } |
---|
6225 | }, |
---|
6226 | |
---|
6227 | /** |
---|
6228 | * Selects a range of rows if the selection model |
---|
6229 | * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}. |
---|
6230 | * All rows in between startRow and endRow are also selected. |
---|
6231 | * @param {Number} startRow The index of the first row in the range |
---|
6232 | * @param {Number} endRow The index of the last row in the range |
---|
6233 | * @param {Boolean} keepExisting (optional) True to retain existing selections |
---|
6234 | */ |
---|
6235 | selectRange : function(startRow, endRow, keepExisting){ |
---|
6236 | var i; |
---|
6237 | if(this.isLocked()){ |
---|
6238 | return; |
---|
6239 | } |
---|
6240 | if(!keepExisting){ |
---|
6241 | this.clearSelections(); |
---|
6242 | } |
---|
6243 | if(startRow <= endRow){ |
---|
6244 | for(i = startRow; i <= endRow; i++){ |
---|
6245 | this.selectRow(i, true); |
---|
6246 | } |
---|
6247 | }else{ |
---|
6248 | for(i = startRow; i >= endRow; i--){ |
---|
6249 | this.selectRow(i, true); |
---|
6250 | } |
---|
6251 | } |
---|
6252 | }, |
---|
6253 | |
---|
6254 | /** |
---|
6255 | * Deselects a range of rows if the selection model |
---|
6256 | * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}. |
---|
6257 | * All rows in between startRow and endRow are also deselected. |
---|
6258 | * @param {Number} startRow The index of the first row in the range |
---|
6259 | * @param {Number} endRow The index of the last row in the range |
---|
6260 | */ |
---|
6261 | deselectRange : function(startRow, endRow, preventViewNotify){ |
---|
6262 | if(this.isLocked()){ |
---|
6263 | return; |
---|
6264 | } |
---|
6265 | for(var i = startRow; i <= endRow; i++){ |
---|
6266 | this.deselectRow(i, preventViewNotify); |
---|
6267 | } |
---|
6268 | }, |
---|
6269 | |
---|
6270 | /** |
---|
6271 | * Selects a row. Before selecting a row, checks if the selection model |
---|
6272 | * {@link Ext.grid.AbstractSelectionModel#isLocked is locked} and fires the |
---|
6273 | * {@link #beforerowselect} event. If these checks are satisfied the row |
---|
6274 | * will be selected and followed up by firing the {@link #rowselect} and |
---|
6275 | * {@link #selectionchange} events. |
---|
6276 | * @param {Number} row The index of the row to select |
---|
6277 | * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections |
---|
6278 | * @param {Boolean} preventViewNotify (optional) Specify <tt>true</tt> to |
---|
6279 | * prevent notifying the view (disables updating the selected appearance) |
---|
6280 | */ |
---|
6281 | selectRow : function(index, keepExisting, preventViewNotify){ |
---|
6282 | if(this.isLocked() || (index < 0 || index >= this.grid.store.getCount()) || (keepExisting && this.isSelected(index))){ |
---|
6283 | return; |
---|
6284 | } |
---|
6285 | var r = this.grid.store.getAt(index); |
---|
6286 | if(r && this.fireEvent('beforerowselect', this, index, keepExisting, r) !== false){ |
---|
6287 | if(!keepExisting || this.singleSelect){ |
---|
6288 | this.clearSelections(); |
---|
6289 | } |
---|
6290 | this.selections.add(r); |
---|
6291 | this.last = this.lastActive = index; |
---|
6292 | if(!preventViewNotify){ |
---|
6293 | this.grid.getView().onRowSelect(index); |
---|
6294 | } |
---|
6295 | if(!this.silent){ |
---|
6296 | this.fireEvent('rowselect', this, index, r); |
---|
6297 | this.fireEvent('selectionchange', this); |
---|
6298 | } |
---|
6299 | } |
---|
6300 | }, |
---|
6301 | |
---|
6302 | /** |
---|
6303 | * Deselects a row. Before deselecting a row, checks if the selection model |
---|
6304 | * {@link Ext.grid.AbstractSelectionModel#isLocked is locked}. |
---|
6305 | * If this check is satisfied the row will be deselected and followed up by |
---|
6306 | * firing the {@link #rowdeselect} and {@link #selectionchange} events. |
---|
6307 | * @param {Number} row The index of the row to deselect |
---|
6308 | * @param {Boolean} preventViewNotify (optional) Specify <tt>true</tt> to |
---|
6309 | * prevent notifying the view (disables updating the selected appearance) |
---|
6310 | */ |
---|
6311 | deselectRow : function(index, preventViewNotify){ |
---|
6312 | if(this.isLocked()){ |
---|
6313 | return; |
---|
6314 | } |
---|
6315 | if(this.last == index){ |
---|
6316 | this.last = false; |
---|
6317 | } |
---|
6318 | if(this.lastActive == index){ |
---|
6319 | this.lastActive = false; |
---|
6320 | } |
---|
6321 | var r = this.grid.store.getAt(index); |
---|
6322 | if(r){ |
---|
6323 | this.selections.remove(r); |
---|
6324 | if(!preventViewNotify){ |
---|
6325 | this.grid.getView().onRowDeselect(index); |
---|
6326 | } |
---|
6327 | this.fireEvent('rowdeselect', this, index, r); |
---|
6328 | this.fireEvent('selectionchange', this); |
---|
6329 | } |
---|
6330 | }, |
---|
6331 | |
---|
6332 | // private |
---|
6333 | acceptsNav : function(row, col, cm){ |
---|
6334 | return !cm.isHidden(col) && cm.isCellEditable(col, row); |
---|
6335 | }, |
---|
6336 | |
---|
6337 | // private |
---|
6338 | onEditorKey : function(field, e){ |
---|
6339 | var k = e.getKey(), |
---|
6340 | newCell, |
---|
6341 | g = this.grid, |
---|
6342 | last = g.lastEdit, |
---|
6343 | ed = g.activeEditor, |
---|
6344 | shift = e.shiftKey, |
---|
6345 | ae, last, r, c; |
---|
6346 | |
---|
6347 | if(k == e.TAB){ |
---|
6348 | e.stopEvent(); |
---|
6349 | ed.completeEdit(); |
---|
6350 | if(shift){ |
---|
6351 | newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this); |
---|
6352 | }else{ |
---|
6353 | newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this); |
---|
6354 | } |
---|
6355 | }else if(k == e.ENTER){ |
---|
6356 | if(this.moveEditorOnEnter !== false){ |
---|
6357 | if(shift){ |
---|
6358 | newCell = g.walkCells(last.row - 1, last.col, -1, this.acceptsNav, this); |
---|
6359 | }else{ |
---|
6360 | newCell = g.walkCells(last.row + 1, last.col, 1, this.acceptsNav, this); |
---|
6361 | } |
---|
6362 | } |
---|
6363 | } |
---|
6364 | if(newCell){ |
---|
6365 | r = newCell[0]; |
---|
6366 | c = newCell[1]; |
---|
6367 | |
---|
6368 | this.onEditorSelect(r, last.row); |
---|
6369 | |
---|
6370 | if(g.isEditor && g.editing){ // *** handle tabbing while editorgrid is in edit mode |
---|
6371 | ae = g.activeEditor; |
---|
6372 | if(ae && ae.field.triggerBlur){ |
---|
6373 | // *** if activeEditor is a TriggerField, explicitly call its triggerBlur() method |
---|
6374 | ae.field.triggerBlur(); |
---|
6375 | } |
---|
6376 | } |
---|
6377 | g.startEditing(r, c); |
---|
6378 | } |
---|
6379 | }, |
---|
6380 | |
---|
6381 | onEditorSelect: function(row, lastRow){ |
---|
6382 | if(lastRow != row){ |
---|
6383 | this.selectRow(row); // *** highlight newly-selected cell and update selection |
---|
6384 | } |
---|
6385 | }, |
---|
6386 | |
---|
6387 | destroy : function(){ |
---|
6388 | Ext.destroy(this.rowNav); |
---|
6389 | this.rowNav = null; |
---|
6390 | Ext.grid.RowSelectionModel.superclass.destroy.call(this); |
---|
6391 | } |
---|
6392 | }); |
---|
6393 | /** |
---|
6394 | * @class Ext.grid.Column |
---|
6395 | * <p>This class encapsulates column configuration data to be used in the initialization of a |
---|
6396 | * {@link Ext.grid.ColumnModel ColumnModel}.</p> |
---|
6397 | * <p>While subclasses are provided to render data in different ways, this class renders a passed |
---|
6398 | * data field unchanged and is usually used for textual columns.</p> |
---|
6399 | */ |
---|
6400 | Ext.grid.Column = Ext.extend(Ext.util.Observable, { |
---|
6401 | /** |
---|
6402 | * @cfg {Boolean} editable Optional. Defaults to <tt>true</tt>, enabling the configured |
---|
6403 | * <tt>{@link #editor}</tt>. Set to <tt>false</tt> to initially disable editing on this column. |
---|
6404 | * The initial configuration may be dynamically altered using |
---|
6405 | * {@link Ext.grid.ColumnModel}.{@link Ext.grid.ColumnModel#setEditable setEditable()}. |
---|
6406 | */ |
---|
6407 | /** |
---|
6408 | * @cfg {String} id Optional. A name which identifies this column (defaults to the column's initial |
---|
6409 | * ordinal position.) The <tt>id</tt> is used to create a CSS <b>class</b> name which is applied to all |
---|
6410 | * table cells (including headers) in that column (in this context the <tt>id</tt> does not need to be |
---|
6411 | * unique). The class name takes the form of <pre>x-grid3-td-<b>id</b></pre> |
---|
6412 | * Header cells will also receive this class name, but will also have the class <pre>x-grid3-hd</pre> |
---|
6413 | * So, to target header cells, use CSS selectors such as:<pre>.x-grid3-hd-row .x-grid3-td-<b>id</b></pre> |
---|
6414 | * The {@link Ext.grid.GridPanel#autoExpandColumn} grid config option references the column via this |
---|
6415 | * unique identifier. |
---|
6416 | */ |
---|
6417 | /** |
---|
6418 | * @cfg {String} header Optional. The header text to be used as innerHTML |
---|
6419 | * (html tags are accepted) to display in the Grid view. <b>Note</b>: to |
---|
6420 | * have a clickable header with no text displayed use <tt>'&#160;'</tt>. |
---|
6421 | */ |
---|
6422 | /** |
---|
6423 | * @cfg {Boolean} groupable Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option |
---|
6424 | * may be used to disable the header menu item to group by the column selected. Defaults to <tt>true</tt>, |
---|
6425 | * which enables the header menu group option. Set to <tt>false</tt> to disable (but still show) the |
---|
6426 | * group option in the header menu for the column. See also <code>{@link #groupName}</code>. |
---|
6427 | */ |
---|
6428 | /** |
---|
6429 | * @cfg {String} groupName Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option |
---|
6430 | * may be used to specify the text with which to prefix the group field value in the group header line. |
---|
6431 | * See also {@link #groupRenderer} and |
---|
6432 | * {@link Ext.grid.GroupingView}.{@link Ext.grid.GroupingView#showGroupName showGroupName}. |
---|
6433 | */ |
---|
6434 | /** |
---|
6435 | * @cfg {Function} groupRenderer <p>Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option |
---|
6436 | * may be used to specify the function used to format the grouping field value for display in the group |
---|
6437 | * {@link #groupName header}. If a <tt><b>groupRenderer</b></tt> is not specified, the configured |
---|
6438 | * <tt><b>{@link #renderer}</b></tt> will be called; if a <tt><b>{@link #renderer}</b></tt> is also not specified |
---|
6439 | * the new value of the group field will be used.</p> |
---|
6440 | * <p>The called function (either the <tt><b>groupRenderer</b></tt> or <tt><b>{@link #renderer}</b></tt>) will be |
---|
6441 | * passed the following parameters: |
---|
6442 | * <div class="mdetail-params"><ul> |
---|
6443 | * <li><b>v</b> : Object<p class="sub-desc">The new value of the group field.</p></li> |
---|
6444 | * <li><b>unused</b> : undefined<p class="sub-desc">Unused parameter.</p></li> |
---|
6445 | * <li><b>r</b> : Ext.data.Record<p class="sub-desc">The Record providing the data |
---|
6446 | * for the row which caused group change.</p></li> |
---|
6447 | * <li><b>rowIndex</b> : Number<p class="sub-desc">The row index of the Record which caused group change.</p></li> |
---|
6448 | * <li><b>colIndex</b> : Number<p class="sub-desc">The column index of the group field.</p></li> |
---|
6449 | * <li><b>ds</b> : Ext.data.Store<p class="sub-desc">The Store which is providing the data Model.</p></li> |
---|
6450 | * </ul></div></p> |
---|
6451 | * <p>The function should return a string value.</p> |
---|
6452 | */ |
---|
6453 | /** |
---|
6454 | * @cfg {String} emptyGroupText Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option |
---|
6455 | * may be used to specify the text to display when there is an empty group value. Defaults to the |
---|
6456 | * {@link Ext.grid.GroupingView}.{@link Ext.grid.GroupingView#emptyGroupText emptyGroupText}. |
---|
6457 | */ |
---|
6458 | /** |
---|
6459 | * @cfg {String} dataIndex <p><b>Required</b>. The name of the field in the |
---|
6460 | * grid's {@link Ext.data.Store}'s {@link Ext.data.Record} definition from |
---|
6461 | * which to draw the column's value.</p> |
---|
6462 | */ |
---|
6463 | /** |
---|
6464 | * @cfg {Number} width |
---|
6465 | * Optional. The initial width in pixels of the column. |
---|
6466 | * The width of each column can also be affected if any of the following are configured: |
---|
6467 | * <div class="mdetail-params"><ul> |
---|
6468 | * <li>{@link Ext.grid.GridPanel}.<tt>{@link Ext.grid.GridPanel#autoExpandColumn autoExpandColumn}</tt></li> |
---|
6469 | * <li>{@link Ext.grid.GridView}.<tt>{@link Ext.grid.GridView#forceFit forceFit}</tt> |
---|
6470 | * <div class="sub-desc"> |
---|
6471 | * <p>By specifying <tt>forceFit:true</tt>, {@link #fixed non-fixed width} columns will be |
---|
6472 | * re-proportioned (based on the relative initial widths) to fill the width of the grid so |
---|
6473 | * that no horizontal scrollbar is shown.</p> |
---|
6474 | * </div></li> |
---|
6475 | * <li>{@link Ext.grid.GridView}.<tt>{@link Ext.grid.GridView#autoFill autoFill}</tt></li> |
---|
6476 | * <li>{@link Ext.grid.GridPanel}.<tt>{@link Ext.grid.GridPanel#minColumnWidth minColumnWidth}</tt></li> |
---|
6477 | * <br><p><b>Note</b>: when the width of each column is determined, a space on the right side |
---|
6478 | * is reserved for the vertical scrollbar. The |
---|
6479 | * {@link Ext.grid.GridView}.<tt>{@link Ext.grid.GridView#scrollOffset scrollOffset}</tt> |
---|
6480 | * can be modified to reduce or eliminate the reserved offset.</p> |
---|
6481 | */ |
---|
6482 | /** |
---|
6483 | * @cfg {Boolean} sortable Optional. <tt>true</tt> if sorting is to be allowed on this column. |
---|
6484 | * Defaults to the value of the <code>{@link Ext.grid.ColumnModel#defaultSortable}</code> property. |
---|
6485 | * Whether local/remote sorting is used is specified in <code>{@link Ext.data.Store#remoteSort}</code>. |
---|
6486 | */ |
---|
6487 | /** |
---|
6488 | * @cfg {Boolean} fixed Optional. <tt>true</tt> if the column width cannot be changed. Defaults to <tt>false</tt>. |
---|
6489 | */ |
---|
6490 | /** |
---|
6491 | * @cfg {Boolean} resizable Optional. <tt>false</tt> to disable column resizing. Defaults to <tt>true</tt>. |
---|
6492 | */ |
---|
6493 | /** |
---|
6494 | * @cfg {Boolean} menuDisabled Optional. <tt>true</tt> to disable the column menu. Defaults to <tt>false</tt>. |
---|
6495 | */ |
---|
6496 | /** |
---|
6497 | * @cfg {Boolean} hidden |
---|
6498 | * Optional. <tt>true</tt> to initially hide this column. Defaults to <tt>false</tt>. |
---|
6499 | * A hidden column {@link Ext.grid.GridPanel#enableColumnHide may be shown via the header row menu}. |
---|
6500 | * If a column is never to be shown, simply do not include this column in the Column Model at all. |
---|
6501 | */ |
---|
6502 | /** |
---|
6503 | * @cfg {String} tooltip Optional. A text string to use as the column header's tooltip. If Quicktips |
---|
6504 | * are enabled, this value will be used as the text of the quick tip, otherwise it will be set as the |
---|
6505 | * header's HTML title attribute. Defaults to ''. |
---|
6506 | */ |
---|
6507 | /** |
---|
6508 | * @cfg {Mixed} renderer |
---|
6509 | * <p>For an alternative to specifying a renderer see <code>{@link #xtype}</code></p> |
---|
6510 | * <p>Optional. A renderer is an 'interceptor' method which can be used transform data (value, |
---|
6511 | * appearance, etc.) before it is rendered). This may be specified in either of three ways: |
---|
6512 | * <div class="mdetail-params"><ul> |
---|
6513 | * <li>A renderer function used to return HTML markup for a cell given the cell's data value.</li> |
---|
6514 | * <li>A string which references a property name of the {@link Ext.util.Format} class which |
---|
6515 | * provides a renderer function.</li> |
---|
6516 | * <li>An object specifying both the renderer function, and its execution scope (<tt><b>this</b></tt> |
---|
6517 | * reference) e.g.:<pre style="margin-left:1.2em"><code> |
---|
6518 | { |
---|
6519 | fn: this.gridRenderer, |
---|
6520 | scope: this |
---|
6521 | } |
---|
6522 | </code></pre></li></ul></div> |
---|
6523 | * If not specified, the default renderer uses the raw data value.</p> |
---|
6524 | * <p>For information about the renderer function (passed parameters, etc.), see |
---|
6525 | * {@link Ext.grid.ColumnModel#setRenderer}. An example of specifying renderer function inline:</p><pre><code> |
---|
6526 | var companyColumn = { |
---|
6527 | header: 'Company Name', |
---|
6528 | dataIndex: 'company', |
---|
6529 | renderer: function(value, metaData, record, rowIndex, colIndex, store) { |
---|
6530 | // provide the logic depending on business rules |
---|
6531 | // name of your own choosing to manipulate the cell depending upon |
---|
6532 | // the data in the underlying Record object. |
---|
6533 | if (value == 'whatever') { |
---|
6534 | //metaData.css : String : A CSS class name to add to the TD element of the cell. |
---|
6535 | //metaData.attr : String : An html attribute definition string to apply to |
---|
6536 | // the data container element within the table |
---|
6537 | // cell (e.g. 'style="color:red;"'). |
---|
6538 | metaData.css = 'name-of-css-class-you-will-define'; |
---|
6539 | } |
---|
6540 | return value; |
---|
6541 | } |
---|
6542 | } |
---|
6543 | * </code></pre> |
---|
6544 | * See also {@link #scope}. |
---|
6545 | */ |
---|
6546 | /** |
---|
6547 | * @cfg {String} xtype Optional. A String which references a predefined {@link Ext.grid.Column} subclass |
---|
6548 | * type which is preconfigured with an appropriate <code>{@link #renderer}</code> to be easily |
---|
6549 | * configured into a ColumnModel. The predefined {@link Ext.grid.Column} subclass types are: |
---|
6550 | * <div class="mdetail-params"><ul> |
---|
6551 | * <li><b><tt>gridcolumn</tt></b> : {@link Ext.grid.Column} (<b>Default</b>)<p class="sub-desc"></p></li> |
---|
6552 | * <li><b><tt>booleancolumn</tt></b> : {@link Ext.grid.BooleanColumn}<p class="sub-desc"></p></li> |
---|
6553 | * <li><b><tt>numbercolumn</tt></b> : {@link Ext.grid.NumberColumn}<p class="sub-desc"></p></li> |
---|
6554 | * <li><b><tt>datecolumn</tt></b> : {@link Ext.grid.DateColumn}<p class="sub-desc"></p></li> |
---|
6555 | * <li><b><tt>templatecolumn</tt></b> : {@link Ext.grid.TemplateColumn}<p class="sub-desc"></p></li> |
---|
6556 | * </ul></div> |
---|
6557 | * <p>Configuration properties for the specified <code>xtype</code> may be specified with |
---|
6558 | * the Column configuration properties, for example:</p> |
---|
6559 | * <pre><code> |
---|
6560 | var grid = new Ext.grid.GridPanel({ |
---|
6561 | ... |
---|
6562 | columns: [{ |
---|
6563 | header: 'Last Updated', |
---|
6564 | dataIndex: 'lastChange', |
---|
6565 | width: 85, |
---|
6566 | sortable: true, |
---|
6567 | //renderer: Ext.util.Format.dateRenderer('m/d/Y'), |
---|
6568 | xtype: 'datecolumn', // use xtype instead of renderer |
---|
6569 | format: 'M/d/Y' // configuration property for {@link Ext.grid.DateColumn} |
---|
6570 | }, { |
---|
6571 | ... |
---|
6572 | }] |
---|
6573 | }); |
---|
6574 | * </code></pre> |
---|
6575 | */ |
---|
6576 | /** |
---|
6577 | * @cfg {Object} scope Optional. The scope (<tt><b>this</b></tt> reference) in which to execute the |
---|
6578 | * renderer. Defaults to the Column configuration object. |
---|
6579 | */ |
---|
6580 | /** |
---|
6581 | * @cfg {String} align Optional. Set the CSS text-align property of the column. Defaults to undefined. |
---|
6582 | */ |
---|
6583 | /** |
---|
6584 | * @cfg {String} css Optional. An inline style definition string which is applied to all table cells in the column |
---|
6585 | * (excluding headers). Defaults to undefined. |
---|
6586 | */ |
---|
6587 | /** |
---|
6588 | * @cfg {Boolean} hideable Optional. Specify as <tt>false</tt> to prevent the user from hiding this column |
---|
6589 | * (defaults to true). To disallow column hiding globally for all columns in the grid, use |
---|
6590 | * {@link Ext.grid.GridPanel#enableColumnHide} instead. |
---|
6591 | */ |
---|
6592 | /** |
---|
6593 | * @cfg {Ext.form.Field} editor Optional. The {@link Ext.form.Field} to use when editing values in this column |
---|
6594 | * if editing is supported by the grid. See <tt>{@link #editable}</tt> also. |
---|
6595 | */ |
---|
6596 | |
---|
6597 | /** |
---|
6598 | * @private |
---|
6599 | * @cfg {Boolean} isColumn |
---|
6600 | * Used by ColumnModel setConfig method to avoid reprocessing a Column |
---|
6601 | * if <code>isColumn</code> is not set ColumnModel will recreate a new Ext.grid.Column |
---|
6602 | * Defaults to true. |
---|
6603 | */ |
---|
6604 | isColumn : true, |
---|
6605 | |
---|
6606 | constructor : function(config){ |
---|
6607 | Ext.apply(this, config); |
---|
6608 | |
---|
6609 | if(Ext.isString(this.renderer)){ |
---|
6610 | this.renderer = Ext.util.Format[this.renderer]; |
---|
6611 | }else if(Ext.isObject(this.renderer)){ |
---|
6612 | this.scope = this.renderer.scope; |
---|
6613 | this.renderer = this.renderer.fn; |
---|
6614 | } |
---|
6615 | if(!this.scope){ |
---|
6616 | this.scope = this; |
---|
6617 | } |
---|
6618 | |
---|
6619 | var ed = this.editor; |
---|
6620 | delete this.editor; |
---|
6621 | this.setEditor(ed); |
---|
6622 | this.addEvents( |
---|
6623 | /** |
---|
6624 | * @event click |
---|
6625 | * Fires when this Column is clicked. |
---|
6626 | * @param {Column} this |
---|
6627 | * @param {Grid} The owning GridPanel |
---|
6628 | * @param {Number} rowIndex |
---|
6629 | * @param {Ext.EventObject} e |
---|
6630 | */ |
---|
6631 | 'click', |
---|
6632 | /** |
---|
6633 | * @event contextmenu |
---|
6634 | * Fires when this Column is right clicked. |
---|
6635 | * @param {Column} this |
---|
6636 | * @param {Grid} The owning GridPanel |
---|
6637 | * @param {Number} rowIndex |
---|
6638 | * @param {Ext.EventObject} e |
---|
6639 | */ |
---|
6640 | 'contextmenu', |
---|
6641 | /** |
---|
6642 | * @event dblclick |
---|
6643 | * Fires when this Column is double clicked. |
---|
6644 | * @param {Column} this |
---|
6645 | * @param {Grid} The owning GridPanel |
---|
6646 | * @param {Number} rowIndex |
---|
6647 | * @param {Ext.EventObject} e |
---|
6648 | */ |
---|
6649 | 'dblclick', |
---|
6650 | /** |
---|
6651 | * @event mousedown |
---|
6652 | * Fires when this Column receives a mousedown event. |
---|
6653 | * @param {Column} this |
---|
6654 | * @param {Grid} The owning GridPanel |
---|
6655 | * @param {Number} rowIndex |
---|
6656 | * @param {Ext.EventObject} e |
---|
6657 | */ |
---|
6658 | 'mousedown' |
---|
6659 | ); |
---|
6660 | Ext.grid.Column.superclass.constructor.call(this); |
---|
6661 | }, |
---|
6662 | |
---|
6663 | /** |
---|
6664 | * @private |
---|
6665 | * Process and refire events routed from the GridView's processEvent method. |
---|
6666 | * Returns the event handler's status to allow cancelling of GridView's bubbling process. |
---|
6667 | */ |
---|
6668 | processEvent : function(name, e, grid, rowIndex, colIndex){ |
---|
6669 | return this.fireEvent(name, this, grid, rowIndex, e); |
---|
6670 | }, |
---|
6671 | |
---|
6672 | /** |
---|
6673 | * @private |
---|
6674 | * Clean up. Remove any Editor. Remove any listeners. |
---|
6675 | */ |
---|
6676 | destroy: function() { |
---|
6677 | if(this.setEditor){ |
---|
6678 | this.setEditor(null); |
---|
6679 | } |
---|
6680 | this.purgeListeners(); |
---|
6681 | }, |
---|
6682 | |
---|
6683 | /** |
---|
6684 | * Optional. A function which returns displayable data when passed the following parameters: |
---|
6685 | * <div class="mdetail-params"><ul> |
---|
6686 | * <li><b>value</b> : Object<p class="sub-desc">The data value for the cell.</p></li> |
---|
6687 | * <li><b>metadata</b> : Object<p class="sub-desc">An object in which you may set the following attributes:<ul> |
---|
6688 | * <li><b>css</b> : String<p class="sub-desc">A CSS class name to add to the cell's TD element.</p></li> |
---|
6689 | * <li><b>attr</b> : String<p class="sub-desc">An HTML attribute definition string to apply to the data container |
---|
6690 | * element <i>within</i> the table cell (e.g. 'style="color:red;"').</p></li></ul></p></li> |
---|
6691 | * <li><b>record</b> : Ext.data.record<p class="sub-desc">The {@link Ext.data.Record} from which the data was |
---|
6692 | * extracted.</p></li> |
---|
6693 | * <li><b>rowIndex</b> : Number<p class="sub-desc">Row index</p></li> |
---|
6694 | * <li><b>colIndex</b> : Number<p class="sub-desc">Column index</p></li> |
---|
6695 | * <li><b>store</b> : Ext.data.Store<p class="sub-desc">The {@link Ext.data.Store} object from which the Record |
---|
6696 | * was extracted.</p></li> |
---|
6697 | * </ul></div> |
---|
6698 | * @property renderer |
---|
6699 | * @type Function |
---|
6700 | */ |
---|
6701 | renderer : function(value){ |
---|
6702 | return value; |
---|
6703 | }, |
---|
6704 | |
---|
6705 | // private |
---|
6706 | getEditor: function(rowIndex){ |
---|
6707 | return this.editable !== false ? this.editor : null; |
---|
6708 | }, |
---|
6709 | |
---|
6710 | /** |
---|
6711 | * Sets a new editor for this column. |
---|
6712 | * @param {Ext.Editor/Ext.form.Field} editor The editor to set |
---|
6713 | */ |
---|
6714 | setEditor : function(editor){ |
---|
6715 | var ed = this.editor; |
---|
6716 | if(ed){ |
---|
6717 | if(ed.gridEditor){ |
---|
6718 | ed.gridEditor.destroy(); |
---|
6719 | delete ed.gridEditor; |
---|
6720 | }else{ |
---|
6721 | ed.destroy(); |
---|
6722 | } |
---|
6723 | } |
---|
6724 | this.editor = null; |
---|
6725 | if(editor){ |
---|
6726 | //not an instance, create it |
---|
6727 | if(!editor.isXType){ |
---|
6728 | editor = Ext.create(editor, 'textfield'); |
---|
6729 | } |
---|
6730 | this.editor = editor; |
---|
6731 | } |
---|
6732 | }, |
---|
6733 | |
---|
6734 | /** |
---|
6735 | * Returns the {@link Ext.Editor editor} defined for this column that was created to wrap the {@link Ext.form.Field Field} |
---|
6736 | * used to edit the cell. |
---|
6737 | * @param {Number} rowIndex The row index |
---|
6738 | * @return {Ext.Editor} |
---|
6739 | */ |
---|
6740 | getCellEditor: function(rowIndex){ |
---|
6741 | var ed = this.getEditor(rowIndex); |
---|
6742 | if(ed){ |
---|
6743 | if(!ed.startEdit){ |
---|
6744 | if(!ed.gridEditor){ |
---|
6745 | ed.gridEditor = new Ext.grid.GridEditor(ed); |
---|
6746 | } |
---|
6747 | ed = ed.gridEditor; |
---|
6748 | } |
---|
6749 | } |
---|
6750 | return ed; |
---|
6751 | } |
---|
6752 | }); |
---|
6753 | |
---|
6754 | /** |
---|
6755 | * @class Ext.grid.BooleanColumn |
---|
6756 | * @extends Ext.grid.Column |
---|
6757 | * <p>A Column definition class which renders boolean data fields. See the {@link Ext.grid.Column#xtype xtype} |
---|
6758 | * config option of {@link Ext.grid.Column} for more details.</p> |
---|
6759 | */ |
---|
6760 | Ext.grid.BooleanColumn = Ext.extend(Ext.grid.Column, { |
---|
6761 | /** |
---|
6762 | * @cfg {String} trueText |
---|
6763 | * The string returned by the renderer when the column value is not falsy (defaults to <tt>'true'</tt>). |
---|
6764 | */ |
---|
6765 | trueText: 'true', |
---|
6766 | /** |
---|
6767 | * @cfg {String} falseText |
---|
6768 | * The string returned by the renderer when the column value is falsy (but not undefined) (defaults to |
---|
6769 | * <tt>'false'</tt>). |
---|
6770 | */ |
---|
6771 | falseText: 'false', |
---|
6772 | /** |
---|
6773 | * @cfg {String} undefinedText |
---|
6774 | * The string returned by the renderer when the column value is undefined (defaults to <tt>'&#160;'</tt>). |
---|
6775 | */ |
---|
6776 | undefinedText: ' ', |
---|
6777 | |
---|
6778 | constructor: function(cfg){ |
---|
6779 | Ext.grid.BooleanColumn.superclass.constructor.call(this, cfg); |
---|
6780 | var t = this.trueText, f = this.falseText, u = this.undefinedText; |
---|
6781 | this.renderer = function(v){ |
---|
6782 | if(v === undefined){ |
---|
6783 | return u; |
---|
6784 | } |
---|
6785 | if(!v || v === 'false'){ |
---|
6786 | return f; |
---|
6787 | } |
---|
6788 | return t; |
---|
6789 | }; |
---|
6790 | } |
---|
6791 | }); |
---|
6792 | |
---|
6793 | /** |
---|
6794 | * @class Ext.grid.NumberColumn |
---|
6795 | * @extends Ext.grid.Column |
---|
6796 | * <p>A Column definition class which renders a numeric data field according to a {@link #format} string. See the |
---|
6797 | * {@link Ext.grid.Column#xtype xtype} config option of {@link Ext.grid.Column} for more details.</p> |
---|
6798 | */ |
---|
6799 | Ext.grid.NumberColumn = Ext.extend(Ext.grid.Column, { |
---|
6800 | /** |
---|
6801 | * @cfg {String} format |
---|
6802 | * A formatting string as used by {@link Ext.util.Format#number} to format a numeric value for this Column |
---|
6803 | * (defaults to <tt>'0,000.00'</tt>). |
---|
6804 | */ |
---|
6805 | format : '0,000.00', |
---|
6806 | constructor: function(cfg){ |
---|
6807 | Ext.grid.NumberColumn.superclass.constructor.call(this, cfg); |
---|
6808 | this.renderer = Ext.util.Format.numberRenderer(this.format); |
---|
6809 | } |
---|
6810 | }); |
---|
6811 | |
---|
6812 | /** |
---|
6813 | * @class Ext.grid.DateColumn |
---|
6814 | * @extends Ext.grid.Column |
---|
6815 | * <p>A Column definition class which renders a passed date according to the default locale, or a configured |
---|
6816 | * {@link #format}. See the {@link Ext.grid.Column#xtype xtype} config option of {@link Ext.grid.Column} |
---|
6817 | * for more details.</p> |
---|
6818 | */ |
---|
6819 | Ext.grid.DateColumn = Ext.extend(Ext.grid.Column, { |
---|
6820 | /** |
---|
6821 | * @cfg {String} format |
---|
6822 | * A formatting string as used by {@link Date#format} to format a Date for this Column |
---|
6823 | * (defaults to <tt>'m/d/Y'</tt>). |
---|
6824 | */ |
---|
6825 | format : 'm/d/Y', |
---|
6826 | constructor: function(cfg){ |
---|
6827 | Ext.grid.DateColumn.superclass.constructor.call(this, cfg); |
---|
6828 | this.renderer = Ext.util.Format.dateRenderer(this.format); |
---|
6829 | } |
---|
6830 | }); |
---|
6831 | |
---|
6832 | /** |
---|
6833 | * @class Ext.grid.TemplateColumn |
---|
6834 | * @extends Ext.grid.Column |
---|
6835 | * <p>A Column definition class which renders a value by processing a {@link Ext.data.Record Record}'s |
---|
6836 | * {@link Ext.data.Record#data data} using a {@link #tpl configured} {@link Ext.XTemplate XTemplate}. |
---|
6837 | * See the {@link Ext.grid.Column#xtype xtype} config option of {@link Ext.grid.Column} for more |
---|
6838 | * details.</p> |
---|
6839 | */ |
---|
6840 | Ext.grid.TemplateColumn = Ext.extend(Ext.grid.Column, { |
---|
6841 | /** |
---|
6842 | * @cfg {String/XTemplate} tpl |
---|
6843 | * An {@link Ext.XTemplate XTemplate}, or an XTemplate <i>definition string</i> to use to process a |
---|
6844 | * {@link Ext.data.Record Record}'s {@link Ext.data.Record#data data} to produce a column's rendered value. |
---|
6845 | */ |
---|
6846 | constructor: function(cfg){ |
---|
6847 | Ext.grid.TemplateColumn.superclass.constructor.call(this, cfg); |
---|
6848 | var tpl = (!Ext.isPrimitive(this.tpl) && this.tpl.compile) ? this.tpl : new Ext.XTemplate(this.tpl); |
---|
6849 | this.renderer = function(value, p, r){ |
---|
6850 | return tpl.apply(r.data); |
---|
6851 | }; |
---|
6852 | this.tpl = tpl; |
---|
6853 | } |
---|
6854 | }); |
---|
6855 | |
---|
6856 | /** |
---|
6857 | * @class Ext.grid.ActionColumn |
---|
6858 | * @extends Ext.grid.Column |
---|
6859 | * <p>A Grid column type which renders an icon, or a series of icons in a grid cell, and offers a scoped click |
---|
6860 | * handler for each icon. Example usage:</p> |
---|
6861 | <pre><code> |
---|
6862 | new Ext.grid.GridPanel({ |
---|
6863 | store: myStore, |
---|
6864 | columns: [ |
---|
6865 | { |
---|
6866 | xtype: 'actioncolumn', |
---|
6867 | width: 50, |
---|
6868 | items: [ |
---|
6869 | { |
---|
6870 | icon : 'sell.gif', // Use a URL in the icon config |
---|
6871 | tooltip: 'Sell stock', |
---|
6872 | handler: function(grid, rowIndex, colIndex) { |
---|
6873 | var rec = store.getAt(rowIndex); |
---|
6874 | alert("Sell " + rec.get('company')); |
---|
6875 | } |
---|
6876 | }, |
---|
6877 | { |
---|
6878 | getClass: function(v, meta, rec) { // Or return a class from a function |
---|
6879 | if (rec.get('change') < 0) { |
---|
6880 | this.items[1].tooltip = 'Do not buy!'; |
---|
6881 | return 'alert-col'; |
---|
6882 | } else { |
---|
6883 | this.items[1].tooltip = 'Buy stock'; |
---|
6884 | return 'buy-col'; |
---|
6885 | } |
---|
6886 | }, |
---|
6887 | handler: function(grid, rowIndex, colIndex) { |
---|
6888 | var rec = store.getAt(rowIndex); |
---|
6889 | alert("Buy " + rec.get('company')); |
---|
6890 | } |
---|
6891 | } |
---|
6892 | ] |
---|
6893 | } |
---|
6894 | //any other columns here |
---|
6895 | ] |
---|
6896 | }); |
---|
6897 | </pre></code> |
---|
6898 | * <p>The action column can be at any index in the columns array, and a grid can have any number of |
---|
6899 | * action columns. </p> |
---|
6900 | */ |
---|
6901 | Ext.grid.ActionColumn = Ext.extend(Ext.grid.Column, { |
---|
6902 | /** |
---|
6903 | * @cfg {String} icon |
---|
6904 | * The URL of an image to display as the clickable element in the column. |
---|
6905 | * Optional - defaults to <code>{@link Ext#BLANK_IMAGE_URL Ext.BLANK_IMAGE_URL}</code>. |
---|
6906 | */ |
---|
6907 | /** |
---|
6908 | * @cfg {String} iconCls |
---|
6909 | * A CSS class to apply to the icon image. To determine the class dynamically, configure the Column with a <code>{@link #getClass}</code> function. |
---|
6910 | */ |
---|
6911 | /** |
---|
6912 | * @cfg {Function} handler A function called when the icon is clicked. |
---|
6913 | * The handler is passed the following parameters:<div class="mdetail-params"><ul> |
---|
6914 | * <li><code>grid</code> : GridPanel<div class="sub-desc">The owning GridPanel.</div></li> |
---|
6915 | * <li><code>rowIndex</code> : Number<div class="sub-desc">The row index clicked on.</div></li> |
---|
6916 | * <li><code>colIndex</code> : Number<div class="sub-desc">The column index clicked on.</div></li> |
---|
6917 | * <li><code>item</code> : Object<div class="sub-desc">The clicked item (or this Column if multiple |
---|
6918 | * {@link #items} were not configured).</div></li> |
---|
6919 | * <li><code>e</code> : Event<div class="sub-desc">The click event.</div></li> |
---|
6920 | * </ul></div> |
---|
6921 | */ |
---|
6922 | /** |
---|
6923 | * @cfg {Object} scope The scope (<tt><b>this</b></tt> reference) in which the <code>{@link #handler}</code> |
---|
6924 | * and <code>{@link #getClass}</code> fuctions are executed. Defaults to this Column. |
---|
6925 | */ |
---|
6926 | /** |
---|
6927 | * @cfg {String} tooltip A tooltip message to be displayed on hover. {@link Ext.QuickTips#init Ext.QuickTips} must have |
---|
6928 | * been initialized. |
---|
6929 | */ |
---|
6930 | /** |
---|
6931 | * @cfg {Boolean} stopSelection Defaults to <code>true</code>. Prevent grid <i>row</i> selection upon mousedown. |
---|
6932 | */ |
---|
6933 | /** |
---|
6934 | * @cfg {Function} getClass A function which returns the CSS class to apply to the icon image. |
---|
6935 | * The function is passed the following parameters:<div class="mdetail-params"><ul> |
---|
6936 | * <li><b>v</b> : Object<p class="sub-desc">The value of the column's configured field (if any).</p></li> |
---|
6937 | * <li><b>metadata</b> : Object<p class="sub-desc">An object in which you may set the following attributes:<ul> |
---|
6938 | * <li><b>css</b> : String<p class="sub-desc">A CSS class name to add to the cell's TD element.</p></li> |
---|
6939 | * <li><b>attr</b> : String<p class="sub-desc">An HTML attribute definition string to apply to the data container element <i>within</i> the table cell |
---|
6940 | * (e.g. 'style="color:red;"').</p></li> |
---|
6941 | * </ul></p></li> |
---|
6942 | * <li><b>r</b> : Ext.data.Record<p class="sub-desc">The Record providing the data.</p></li> |
---|
6943 | * <li><b>rowIndex</b> : Number<p class="sub-desc">The row index..</p></li> |
---|
6944 | * <li><b>colIndex</b> : Number<p class="sub-desc">The column index.</p></li> |
---|
6945 | * <li><b>store</b> : Ext.data.Store<p class="sub-desc">The Store which is providing the data Model.</p></li> |
---|
6946 | * </ul></div> |
---|
6947 | */ |
---|
6948 | /** |
---|
6949 | * @cfg {Array} items An Array which may contain multiple icon definitions, each element of which may contain: |
---|
6950 | * <div class="mdetail-params"><ul> |
---|
6951 | * <li><code>icon</code> : String<div class="sub-desc">The url of an image to display as the clickable element |
---|
6952 | * in the column.</div></li> |
---|
6953 | * <li><code>iconCls</code> : String<div class="sub-desc">A CSS class to apply to the icon image. |
---|
6954 | * To determine the class dynamically, configure the item with a <code>getClass</code> function.</div></li> |
---|
6955 | * <li><code>getClass</code> : Function<div class="sub-desc">A function which returns the CSS class to apply to the icon image. |
---|
6956 | * The function is passed the following parameters:<ul> |
---|
6957 | * <li><b>v</b> : Object<p class="sub-desc">The value of the column's configured field (if any).</p></li> |
---|
6958 | * <li><b>metadata</b> : Object<p class="sub-desc">An object in which you may set the following attributes:<ul> |
---|
6959 | * <li><b>css</b> : String<p class="sub-desc">A CSS class name to add to the cell's TD element.</p></li> |
---|
6960 | * <li><b>attr</b> : String<p class="sub-desc">An HTML attribute definition string to apply to the data container element <i>within</i> the table cell |
---|
6961 | * (e.g. 'style="color:red;"').</p></li> |
---|
6962 | * </ul></p></li> |
---|
6963 | * <li><b>r</b> : Ext.data.Record<p class="sub-desc">The Record providing the data.</p></li> |
---|
6964 | * <li><b>rowIndex</b> : Number<p class="sub-desc">The row index..</p></li> |
---|
6965 | * <li><b>colIndex</b> : Number<p class="sub-desc">The column index.</p></li> |
---|
6966 | * <li><b>store</b> : Ext.data.Store<p class="sub-desc">The Store which is providing the data Model.</p></li> |
---|
6967 | * </ul></div></li> |
---|
6968 | * <li><code>handler</code> : Function<div class="sub-desc">A function called when the icon is clicked.</div></li> |
---|
6969 | * <li><code>scope</code> : Scope<div class="sub-desc">The scope (<code><b>this</b></code> reference) in which the |
---|
6970 | * <code>handler</code> and <code>getClass</code> functions are executed. Fallback defaults are this Column's |
---|
6971 | * configured scope, then this Column.</div></li> |
---|
6972 | * <li><code>tooltip</code> : String<div class="sub-desc">A tooltip message to be displayed on hover. |
---|
6973 | * {@link Ext.QuickTips#init Ext.QuickTips} must have been initialized.</div></li> |
---|
6974 | * </ul></div> |
---|
6975 | */ |
---|
6976 | header: ' ', |
---|
6977 | |
---|
6978 | actionIdRe: /x-action-col-(\d+)/, |
---|
6979 | |
---|
6980 | /** |
---|
6981 | * @cfg {String} altText The alt text to use for the image element. Defaults to <tt>''</tt>. |
---|
6982 | */ |
---|
6983 | altText: '', |
---|
6984 | |
---|
6985 | constructor: function(cfg) { |
---|
6986 | var me = this, |
---|
6987 | items = cfg.items || (me.items = [me]), |
---|
6988 | l = items.length, |
---|
6989 | i, |
---|
6990 | item; |
---|
6991 | |
---|
6992 | Ext.grid.ActionColumn.superclass.constructor.call(me, cfg); |
---|
6993 | |
---|
6994 | // Renderer closure iterates through items creating an <img> element for each and tagging with an identifying |
---|
6995 | // class name x-action-col-{n} |
---|
6996 | me.renderer = function(v, meta) { |
---|
6997 | // Allow a configured renderer to create initial value (And set the other values in the "metadata" argument!) |
---|
6998 | v = Ext.isFunction(cfg.renderer) ? cfg.renderer.apply(this, arguments)||'' : ''; |
---|
6999 | |
---|
7000 | meta.css += ' x-action-col-cell'; |
---|
7001 | for (i = 0; i < l; i++) { |
---|
7002 | item = items[i]; |
---|
7003 | v += '<img alt="' + (item.altText || me.altText) + '" src="' + (item.icon || Ext.BLANK_IMAGE_URL) + |
---|
7004 | '" class="x-action-col-icon x-action-col-' + String(i) + ' ' + (item.iconCls || '') + |
---|
7005 | ' ' + (Ext.isFunction(item.getClass) ? item.getClass.apply(item.scope||this.scope||this, arguments) : '') + '"' + |
---|
7006 | ((item.tooltip) ? ' ext:qtip="' + item.tooltip + '"' : '') + ' />'; |
---|
7007 | } |
---|
7008 | return v; |
---|
7009 | }; |
---|
7010 | }, |
---|
7011 | |
---|
7012 | destroy: function() { |
---|
7013 | delete this.items; |
---|
7014 | delete this.renderer; |
---|
7015 | return Ext.grid.ActionColumn.superclass.destroy.apply(this, arguments); |
---|
7016 | }, |
---|
7017 | |
---|
7018 | /** |
---|
7019 | * @private |
---|
7020 | * Process and refire events routed from the GridView's processEvent method. |
---|
7021 | * Also fires any configured click handlers. By default, cancels the mousedown event to prevent selection. |
---|
7022 | * Returns the event handler's status to allow cancelling of GridView's bubbling process. |
---|
7023 | */ |
---|
7024 | processEvent : function(name, e, grid, rowIndex, colIndex){ |
---|
7025 | var m = e.getTarget().className.match(this.actionIdRe), |
---|
7026 | item, fn; |
---|
7027 | if (m && (item = this.items[parseInt(m[1], 10)])) { |
---|
7028 | if (name == 'click') { |
---|
7029 | (fn = item.handler || this.handler) && fn.call(item.scope||this.scope||this, grid, rowIndex, colIndex, item, e); |
---|
7030 | } else if ((name == 'mousedown') && (item.stopSelection !== false)) { |
---|
7031 | return false; |
---|
7032 | } |
---|
7033 | } |
---|
7034 | return Ext.grid.ActionColumn.superclass.processEvent.apply(this, arguments); |
---|
7035 | } |
---|
7036 | }); |
---|
7037 | |
---|
7038 | /* |
---|
7039 | * @property types |
---|
7040 | * @type Object |
---|
7041 | * @member Ext.grid.Column |
---|
7042 | * @static |
---|
7043 | * <p>An object containing predefined Column classes keyed by a mnemonic code which may be referenced |
---|
7044 | * by the {@link Ext.grid.ColumnModel#xtype xtype} config option of ColumnModel.</p> |
---|
7045 | * <p>This contains the following properties</p><div class="mdesc-details"><ul> |
---|
7046 | * <li>gridcolumn : <b>{@link Ext.grid.Column Column constructor}</b></li> |
---|
7047 | * <li>booleancolumn : <b>{@link Ext.grid.BooleanColumn BooleanColumn constructor}</b></li> |
---|
7048 | * <li>numbercolumn : <b>{@link Ext.grid.NumberColumn NumberColumn constructor}</b></li> |
---|
7049 | * <li>datecolumn : <b>{@link Ext.grid.DateColumn DateColumn constructor}</b></li> |
---|
7050 | * <li>templatecolumn : <b>{@link Ext.grid.TemplateColumn TemplateColumn constructor}</b></li> |
---|
7051 | * </ul></div> |
---|
7052 | */ |
---|
7053 | Ext.grid.Column.types = { |
---|
7054 | gridcolumn : Ext.grid.Column, |
---|
7055 | booleancolumn: Ext.grid.BooleanColumn, |
---|
7056 | numbercolumn: Ext.grid.NumberColumn, |
---|
7057 | datecolumn: Ext.grid.DateColumn, |
---|
7058 | templatecolumn: Ext.grid.TemplateColumn, |
---|
7059 | actioncolumn: Ext.grid.ActionColumn |
---|
7060 | };/** |
---|
7061 | * @class Ext.grid.RowNumberer |
---|
7062 | * This is a utility class that can be passed into a {@link Ext.grid.ColumnModel} as a column config that provides |
---|
7063 | * an automatic row numbering column. |
---|
7064 | * <br>Usage:<br> |
---|
7065 | <pre><code> |
---|
7066 | // This is a typical column config with the first column providing row numbers |
---|
7067 | var colModel = new Ext.grid.ColumnModel([ |
---|
7068 | new Ext.grid.RowNumberer(), |
---|
7069 | {header: "Name", width: 80, sortable: true}, |
---|
7070 | {header: "Code", width: 50, sortable: true}, |
---|
7071 | {header: "Description", width: 200, sortable: true} |
---|
7072 | ]); |
---|
7073 | </code></pre> |
---|
7074 | * @constructor |
---|
7075 | * @param {Object} config The configuration options |
---|
7076 | */ |
---|
7077 | Ext.grid.RowNumberer = Ext.extend(Object, { |
---|
7078 | /** |
---|
7079 | * @cfg {String} header Any valid text or HTML fragment to display in the header cell for the row |
---|
7080 | * number column (defaults to ''). |
---|
7081 | */ |
---|
7082 | header: "", |
---|
7083 | /** |
---|
7084 | * @cfg {Number} width The default width in pixels of the row number column (defaults to 23). |
---|
7085 | */ |
---|
7086 | width: 23, |
---|
7087 | /** |
---|
7088 | * @cfg {Boolean} sortable True if the row number column is sortable (defaults to false). |
---|
7089 | * @hide |
---|
7090 | */ |
---|
7091 | sortable: false, |
---|
7092 | |
---|
7093 | constructor : function(config){ |
---|
7094 | Ext.apply(this, config); |
---|
7095 | if(this.rowspan){ |
---|
7096 | this.renderer = this.renderer.createDelegate(this); |
---|
7097 | } |
---|
7098 | }, |
---|
7099 | |
---|
7100 | // private |
---|
7101 | fixed:true, |
---|
7102 | hideable: false, |
---|
7103 | menuDisabled:true, |
---|
7104 | dataIndex: '', |
---|
7105 | id: 'numberer', |
---|
7106 | rowspan: undefined, |
---|
7107 | |
---|
7108 | // private |
---|
7109 | renderer : function(v, p, record, rowIndex){ |
---|
7110 | if(this.rowspan){ |
---|
7111 | p.cellAttr = 'rowspan="'+this.rowspan+'"'; |
---|
7112 | } |
---|
7113 | return rowIndex+1; |
---|
7114 | } |
---|
7115 | });/** |
---|
7116 | * @class Ext.grid.CheckboxSelectionModel |
---|
7117 | * @extends Ext.grid.RowSelectionModel |
---|
7118 | * A custom selection model that renders a column of checkboxes that can be toggled to select or deselect rows. |
---|
7119 | * @constructor |
---|
7120 | * @param {Object} config The configuration options |
---|
7121 | */ |
---|
7122 | Ext.grid.CheckboxSelectionModel = Ext.extend(Ext.grid.RowSelectionModel, { |
---|
7123 | |
---|
7124 | /** |
---|
7125 | * @cfg {Boolean} checkOnly <tt>true</tt> if rows can only be selected by clicking on the |
---|
7126 | * checkbox column (defaults to <tt>false</tt>). |
---|
7127 | */ |
---|
7128 | /** |
---|
7129 | * @cfg {String} header Any valid text or HTML fragment to display in the header cell for the |
---|
7130 | * checkbox column. Defaults to:<pre><code> |
---|
7131 | * '<div class="x-grid3-hd-checker">&#160;</div>'</tt> |
---|
7132 | * </code></pre> |
---|
7133 | * The default CSS class of <tt>'x-grid3-hd-checker'</tt> displays a checkbox in the header |
---|
7134 | * and provides support for automatic check all/none behavior on header click. This string |
---|
7135 | * can be replaced by any valid HTML fragment, including a simple text string (e.g., |
---|
7136 | * <tt>'Select Rows'</tt>), but the automatic check all/none behavior will only work if the |
---|
7137 | * <tt>'x-grid3-hd-checker'</tt> class is supplied. |
---|
7138 | */ |
---|
7139 | header : '<div class="x-grid3-hd-checker"> </div>', |
---|
7140 | /** |
---|
7141 | * @cfg {Number} width The default width in pixels of the checkbox column (defaults to <tt>20</tt>). |
---|
7142 | */ |
---|
7143 | width : 20, |
---|
7144 | /** |
---|
7145 | * @cfg {Boolean} sortable <tt>true</tt> if the checkbox column is sortable (defaults to |
---|
7146 | * <tt>false</tt>). |
---|
7147 | */ |
---|
7148 | sortable : false, |
---|
7149 | |
---|
7150 | // private |
---|
7151 | menuDisabled : true, |
---|
7152 | fixed : true, |
---|
7153 | hideable: false, |
---|
7154 | dataIndex : '', |
---|
7155 | id : 'checker', |
---|
7156 | isColumn: true, // So that ColumnModel doesn't feed this through the Column constructor |
---|
7157 | |
---|
7158 | constructor : function(){ |
---|
7159 | Ext.grid.CheckboxSelectionModel.superclass.constructor.apply(this, arguments); |
---|
7160 | if(this.checkOnly){ |
---|
7161 | this.handleMouseDown = Ext.emptyFn; |
---|
7162 | } |
---|
7163 | }, |
---|
7164 | |
---|
7165 | // private |
---|
7166 | initEvents : function(){ |
---|
7167 | Ext.grid.CheckboxSelectionModel.superclass.initEvents.call(this); |
---|
7168 | this.grid.on('render', function(){ |
---|
7169 | Ext.fly(this.grid.getView().innerHd).on('mousedown', this.onHdMouseDown, this); |
---|
7170 | }, this); |
---|
7171 | }, |
---|
7172 | |
---|
7173 | /** |
---|
7174 | * @private |
---|
7175 | * Process and refire events routed from the GridView's processEvent method. |
---|
7176 | */ |
---|
7177 | processEvent : function(name, e, grid, rowIndex, colIndex){ |
---|
7178 | if (name == 'mousedown') { |
---|
7179 | this.onMouseDown(e, e.getTarget()); |
---|
7180 | return false; |
---|
7181 | } else { |
---|
7182 | return Ext.grid.Column.prototype.processEvent.apply(this, arguments); |
---|
7183 | } |
---|
7184 | }, |
---|
7185 | |
---|
7186 | // private |
---|
7187 | onMouseDown : function(e, t){ |
---|
7188 | if(e.button === 0 && t.className == 'x-grid3-row-checker'){ // Only fire if left-click |
---|
7189 | e.stopEvent(); |
---|
7190 | var row = e.getTarget('.x-grid3-row'); |
---|
7191 | if(row){ |
---|
7192 | var index = row.rowIndex; |
---|
7193 | if(this.isSelected(index)){ |
---|
7194 | this.deselectRow(index); |
---|
7195 | }else{ |
---|
7196 | this.selectRow(index, true); |
---|
7197 | this.grid.getView().focusRow(index); |
---|
7198 | } |
---|
7199 | } |
---|
7200 | } |
---|
7201 | }, |
---|
7202 | |
---|
7203 | // private |
---|
7204 | onHdMouseDown : function(e, t) { |
---|
7205 | if(t.className == 'x-grid3-hd-checker'){ |
---|
7206 | e.stopEvent(); |
---|
7207 | var hd = Ext.fly(t.parentNode); |
---|
7208 | var isChecked = hd.hasClass('x-grid3-hd-checker-on'); |
---|
7209 | if(isChecked){ |
---|
7210 | hd.removeClass('x-grid3-hd-checker-on'); |
---|
7211 | this.clearSelections(); |
---|
7212 | }else{ |
---|
7213 | hd.addClass('x-grid3-hd-checker-on'); |
---|
7214 | this.selectAll(); |
---|
7215 | } |
---|
7216 | } |
---|
7217 | }, |
---|
7218 | |
---|
7219 | // private |
---|
7220 | renderer : function(v, p, record){ |
---|
7221 | return '<div class="x-grid3-row-checker"> </div>'; |
---|
7222 | }, |
---|
7223 | |
---|
7224 | onEditorSelect: function(row, lastRow){ |
---|
7225 | if(lastRow != row && !this.checkOnly){ |
---|
7226 | this.selectRow(row); // *** highlight newly-selected cell and update selection |
---|
7227 | } |
---|
7228 | } |
---|
7229 | }); |
---|