3 * Copyright(c) 2006-2010 Ext JS, LLC
5 * http://www.extjs.com/license
8 * @class Ext.grid.GridPanel
\r
10 * <p>This class represents the primary interface of a component based grid control to represent data
\r
11 * in a tabular format of rows and columns. The GridPanel is composed of the following:</p>
\r
12 * <div class="mdetail-params"><ul>
\r
13 * <li><b>{@link Ext.data.Store Store}</b> : The Model holding the data records (rows)
\r
14 * <div class="sub-desc"></div></li>
\r
15 * <li><b>{@link Ext.grid.ColumnModel Column model}</b> : Column makeup
\r
16 * <div class="sub-desc"></div></li>
\r
17 * <li><b>{@link Ext.grid.GridView View}</b> : Encapsulates the user interface
\r
18 * <div class="sub-desc"></div></li>
\r
19 * <li><b>{@link Ext.grid.AbstractSelectionModel selection model}</b> : Selection behavior
\r
20 * <div class="sub-desc"></div></li>
\r
22 * <p>Example usage:</p>
\r
24 var grid = new Ext.grid.GridPanel({
\r
25 {@link #store}: new {@link Ext.data.Store}({
\r
26 {@link Ext.data.Store#autoDestroy autoDestroy}: true,
\r
27 {@link Ext.data.Store#reader reader}: reader,
\r
28 {@link Ext.data.Store#data data}: xg.dummyData
\r
30 {@link #colModel}: new {@link Ext.grid.ColumnModel}({
\r
31 {@link Ext.grid.ColumnModel#defaults defaults}: {
\r
35 {@link Ext.grid.ColumnModel#columns columns}: [
\r
36 {id: 'company', header: 'Company', width: 200, sortable: true, dataIndex: 'company'},
\r
37 {header: 'Price', renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
\r
38 {header: 'Change', dataIndex: 'change'},
\r
39 {header: '% Change', dataIndex: 'pctChange'},
\r
40 // instead of specifying renderer: Ext.util.Format.dateRenderer('m/d/Y') use xtype
\r
42 header: 'Last Updated', width: 135, dataIndex: 'lastChange',
\r
43 xtype: 'datecolumn', format: 'M d, Y'
\r
47 {@link #viewConfig}: {
\r
48 {@link Ext.grid.GridView#forceFit forceFit}: true,
\r
50 // Return CSS class to apply to rows depending upon data values
\r
51 {@link Ext.grid.GridView#getRowClass getRowClass}: function(record, index) {
\r
52 var c = record.{@link Ext.data.Record#get get}('change');
\r
54 return 'price-fall';
\r
56 return 'price-rise';
\r
60 {@link #sm}: new Ext.grid.RowSelectionModel({singleSelect:true}),
\r
64 title: 'Framed with Row Selection and Horizontal Scrolling',
\r
65 iconCls: 'icon-grid'
\r
68 * <p><b><u>Notes:</u></b></p>
\r
69 * <div class="mdetail-params"><ul>
\r
70 * <li>Although this class inherits many configuration options from base classes, some of them
\r
71 * (such as autoScroll, autoWidth, layout, items, etc) are not used by this class, and will
\r
72 * have no effect.</li>
\r
73 * <li>A grid <b>requires</b> a width in which to scroll its columns, and a height in which to
\r
74 * scroll its rows. These dimensions can either be set explicitly through the
\r
75 * <tt>{@link Ext.BoxComponent#height height}</tt> and <tt>{@link Ext.BoxComponent#width width}</tt>
\r
76 * configuration options or implicitly set by using the grid as a child item of a
\r
77 * {@link Ext.Container Container} which will have a {@link Ext.Container#layout layout manager}
\r
78 * provide the sizing of its child items (for example the Container of the Grid may specify
\r
79 * <tt>{@link Ext.Container#layout layout}:'fit'</tt>).</li>
\r
80 * <li>To access the data in a Grid, it is necessary to use the data model encapsulated
\r
81 * by the {@link #store Store}. See the {@link #cellclick} event for more details.</li>
\r
84 * @param {Object} config The config object
\r
87 Ext.grid.GridPanel = Ext.extend(Ext.Panel, {
\r
89 * @cfg {String} autoExpandColumn
\r
90 * <p>The <tt>{@link Ext.grid.Column#id id}</tt> of a {@link Ext.grid.Column column} in
\r
91 * this grid that should expand to fill unused space. This value specified here can not
\r
92 * be <tt>0</tt>.</p>
\r
93 * <br><p><b>Note</b>: If the Grid's {@link Ext.grid.GridView view} is configured with
\r
94 * <tt>{@link Ext.grid.GridView#forceFit forceFit}=true</tt> the <tt>autoExpandColumn</tt>
\r
95 * is ignored. See {@link Ext.grid.Column}.<tt>{@link Ext.grid.Column#width width}</tt>
\r
96 * for additional details.</p>
\r
97 * <p>See <tt>{@link #autoExpandMax}</tt> and <tt>{@link #autoExpandMin}</tt> also.</p>
\r
99 autoExpandColumn : false,
\r
101 * @cfg {Number} autoExpandMax The maximum width the <tt>{@link #autoExpandColumn}</tt>
\r
102 * can have (if enabled). Defaults to <tt>1000</tt>.
\r
104 autoExpandMax : 1000,
\r
106 * @cfg {Number} autoExpandMin The minimum width the <tt>{@link #autoExpandColumn}</tt>
\r
107 * can have (if enabled). Defaults to <tt>50</tt>.
\r
109 autoExpandMin : 50,
\r
111 * @cfg {Boolean} columnLines <tt>true</tt> to add css for column separation lines.
\r
112 * Default is <tt>false</tt>.
\r
114 columnLines : false,
\r
116 * @cfg {Object} cm Shorthand for <tt>{@link #colModel}</tt>.
\r
119 * @cfg {Object} colModel The {@link Ext.grid.ColumnModel} to use when rendering the grid (required).
\r
122 * @cfg {Array} columns An array of {@link Ext.grid.Column columns} to auto create a
\r
123 * {@link Ext.grid.ColumnModel}. The ColumnModel may be explicitly created via the
\r
124 * <tt>{@link #colModel}</tt> configuration property.
\r
127 * @cfg {String} ddGroup The DD group this GridPanel belongs to. Defaults to <tt>'GridDD'</tt> if not specified.
\r
130 * @cfg {String} ddText
\r
131 * Configures the text in the drag proxy. Defaults to:
\r
133 * ddText : '{0} selected row{1}'
\r
135 * <tt>{0}</tt> is replaced with the number of selected rows.
\r
137 ddText : '{0} selected row{1}',
\r
139 * @cfg {Boolean} deferRowRender <P>Defaults to <tt>true</tt> to enable deferred row rendering.</p>
\r
140 * <p>This allows the GridPanel to be initially rendered empty, with the expensive update of the row
\r
141 * structure deferred so that layouts with GridPanels appear more quickly.</p>
\r
143 deferRowRender : true,
\r
145 * @cfg {Boolean} disableSelection <p><tt>true</tt> to disable selections in the grid. Defaults to <tt>false</tt>.</p>
\r
146 * <p>Ignored if a {@link #selModel SelectionModel} is specified.</p>
\r
149 * @cfg {Boolean} enableColumnResize <tt>false</tt> to turn off column resizing for the whole grid. Defaults to <tt>true</tt>.
\r
152 * @cfg {Boolean} enableColumnHide
\r
153 * Defaults to <tt>true</tt> to enable {@link Ext.grid.Column#hidden hiding of columns}
\r
154 * with the {@link #enableHdMenu header menu}.
\r
156 enableColumnHide : true,
\r
158 * @cfg {Boolean} enableColumnMove Defaults to <tt>true</tt> to enable drag and drop reorder of columns. <tt>false</tt>
\r
159 * to turn off column reordering via drag drop.
\r
161 enableColumnMove : true,
\r
163 * @cfg {Boolean} enableDragDrop <p>Enables dragging of the selected rows of the GridPanel. Defaults to <tt>false</tt>.</p>
\r
164 * <p>Setting this to <b><tt>true</tt></b> causes this GridPanel's {@link #getView GridView} to
\r
165 * create an instance of {@link Ext.grid.GridDragZone}. <b>Note</b>: this is available only <b>after</b>
\r
166 * the Grid has been rendered as the GridView's <tt>{@link Ext.grid.GridView#dragZone dragZone}</tt>
\r
168 * <p>A cooperating {@link Ext.dd.DropZone DropZone} must be created who's implementations of
\r
169 * {@link Ext.dd.DropZone#onNodeEnter onNodeEnter}, {@link Ext.dd.DropZone#onNodeOver onNodeOver},
\r
170 * {@link Ext.dd.DropZone#onNodeOut onNodeOut} and {@link Ext.dd.DropZone#onNodeDrop onNodeDrop} are able
\r
171 * to process the {@link Ext.grid.GridDragZone#getDragData data} which is provided.</p>
\r
173 enableDragDrop : false,
\r
175 * @cfg {Boolean} enableHdMenu Defaults to <tt>true</tt> to enable the drop down button for menu in the headers.
\r
177 enableHdMenu : true,
\r
179 * @cfg {Boolean} hideHeaders True to hide the grid's header. Defaults to <code>false</code>.
\r
182 * @cfg {Object} loadMask An {@link Ext.LoadMask} config or true to mask the grid while
\r
183 * loading. Defaults to <code>false</code>.
\r
187 * @cfg {Number} maxHeight Sets the maximum height of the grid - ignored if <tt>autoHeight</tt> is not on.
\r
190 * @cfg {Number} minColumnWidth The minimum width a column can be resized to. Defaults to <tt>25</tt>.
\r
192 minColumnWidth : 25,
\r
194 * @cfg {Object} sm Shorthand for <tt>{@link #selModel}</tt>.
\r
197 * @cfg {Object} selModel Any subclass of {@link Ext.grid.AbstractSelectionModel} that will provide
\r
198 * the selection model for the grid (defaults to {@link Ext.grid.RowSelectionModel} if not specified).
\r
201 * @cfg {Ext.data.Store} store The {@link Ext.data.Store} the grid should use as its data source (required).
\r
204 * @cfg {Boolean} stripeRows <tt>true</tt> to stripe the rows. Default is <tt>false</tt>.
\r
205 * <p>This causes the CSS class <tt><b>x-grid3-row-alt</b></tt> to be added to alternate rows of
\r
206 * the grid. A default CSS rule is provided which sets a background colour, but you can override this
\r
207 * with a rule which either overrides the <b>background-color</b> style using the '!important'
\r
208 * modifier, or which uses a CSS selector of higher specificity.</p>
\r
210 stripeRows : false,
\r
212 * @cfg {Boolean} trackMouseOver True to highlight rows when the mouse is over. Default is <tt>true</tt>
\r
213 * for GridPanel, but <tt>false</tt> for EditorGridPanel.
\r
215 trackMouseOver : true,
\r
217 * @cfg {Array} stateEvents
\r
218 * An array of events that, when fired, should trigger this component to save its state.
\r
219 * Defaults to:<pre><code>
\r
220 * stateEvents: ['columnmove', 'columnresize', 'sortchange', 'groupchange']
\r
222 * <p>These can be any types of events supported by this component, including browser or
\r
223 * custom events (e.g., <tt>['click', 'customerchange']</tt>).</p>
\r
224 * <p>See {@link Ext.Component#stateful} for an explanation of saving and restoring
\r
225 * Component state.</p>
\r
227 stateEvents : ['columnmove', 'columnresize', 'sortchange', 'groupchange'],
\r
229 * @cfg {Object} view The {@link Ext.grid.GridView} used by the grid. This can be set
\r
230 * before a call to {@link Ext.Component#render render()}.
\r
235 * @cfg {Array} bubbleEvents
\r
236 * <p>An array of events that, when fired, should be bubbled to any parent container.
\r
237 * See {@link Ext.util.Observable#enableBubble}.
\r
238 * Defaults to <tt>[]</tt>.
\r
243 * @cfg {Object} viewConfig A config object that will be applied to the grid's UI view. Any of
\r
244 * the config options available for {@link Ext.grid.GridView} can be specified here. This option
\r
245 * is ignored if <tt>{@link #view}</tt> is specified.
\r
254 initComponent : function(){
\r
255 Ext.grid.GridPanel.superclass.initComponent.call(this);
\r
257 if(this.columnLines){
\r
258 this.cls = (this.cls || '') + ' x-grid-with-col-lines';
\r
260 // override any provided value since it isn't valid
\r
261 // and is causing too many bug reports ;)
\r
262 this.autoScroll = false;
\r
263 this.autoWidth = false;
\r
265 if(Ext.isArray(this.columns)){
\r
266 this.colModel = new Ext.grid.ColumnModel(this.columns);
\r
267 delete this.columns;
\r
270 // check and correct shorthanded configs
\r
272 this.store = this.ds;
\r
276 this.colModel = this.cm;
\r
280 this.selModel = this.sm;
\r
283 this.store = Ext.StoreMgr.lookup(this.store);
\r
289 * The raw click event for the entire grid.
\r
290 * @param {Ext.EventObject} e
\r
295 * The raw dblclick event for the entire grid.
\r
296 * @param {Ext.EventObject} e
\r
300 * @event contextmenu
\r
301 * The raw contextmenu event for the entire grid.
\r
302 * @param {Ext.EventObject} e
\r
307 * The raw mousedown event for the entire grid.
\r
308 * @param {Ext.EventObject} e
\r
313 * The raw mouseup event for the entire grid.
\r
314 * @param {Ext.EventObject} e
\r
319 * The raw mouseover event for the entire grid.
\r
320 * @param {Ext.EventObject} e
\r
325 * The raw mouseout event for the entire grid.
\r
326 * @param {Ext.EventObject} e
\r
331 * The raw keypress event for the entire grid.
\r
332 * @param {Ext.EventObject} e
\r
337 * The raw keydown event for the entire grid.
\r
338 * @param {Ext.EventObject} e
\r
344 * @event cellmousedown
\r
345 * Fires before a cell is clicked
\r
346 * @param {Grid} this
\r
347 * @param {Number} rowIndex
\r
348 * @param {Number} columnIndex
\r
349 * @param {Ext.EventObject} e
\r
353 * @event rowmousedown
\r
354 * Fires before a row is clicked
\r
355 * @param {Grid} this
\r
356 * @param {Number} rowIndex
\r
357 * @param {Ext.EventObject} e
\r
361 * @event headermousedown
\r
362 * Fires before a header is clicked
\r
363 * @param {Grid} this
\r
364 * @param {Number} columnIndex
\r
365 * @param {Ext.EventObject} e
\r
370 * @event groupmousedown
\r
371 * Fires before a group header is clicked. <b>Only applies for grids with a {@link Ext.grid.GroupingView GroupingView}</b>.
\r
372 * @param {Grid} this
\r
373 * @param {String} groupField
\r
374 * @param {String} groupValue
\r
375 * @param {Ext.EventObject} e
\r
380 * @event rowbodymousedown
\r
381 * Fires before the row body is clicked. <b>Only applies for grids with {@link Ext.grid.GridView#enableRowBody enableRowBody} configured.</b>
\r
382 * @param {Grid} this
\r
383 * @param {Number} rowIndex
\r
384 * @param {Ext.EventObject} e
\r
386 'rowbodymousedown',
\r
389 * @event containermousedown
\r
390 * Fires before the container is clicked. The container consists of any part of the grid body that is not covered by a row.
\r
391 * @param {Grid} this
\r
392 * @param {Ext.EventObject} e
\r
394 'containermousedown',
\r
398 * Fires when a cell is clicked.
\r
399 * The data for the cell is drawn from the {@link Ext.data.Record Record}
\r
400 * for this row. To access the data in the listener function use the
\r
401 * following technique:
\r
403 function(grid, rowIndex, columnIndex, e) {
\r
404 var record = grid.getStore().getAt(rowIndex); // Get the Record
\r
405 var fieldName = grid.getColumnModel().getDataIndex(columnIndex); // Get field name
\r
406 var data = record.get(fieldName);
\r
409 * @param {Grid} this
\r
410 * @param {Number} rowIndex
\r
411 * @param {Number} columnIndex
\r
412 * @param {Ext.EventObject} e
\r
416 * @event celldblclick
\r
417 * Fires when a cell is double clicked
\r
418 * @param {Grid} this
\r
419 * @param {Number} rowIndex
\r
420 * @param {Number} columnIndex
\r
421 * @param {Ext.EventObject} e
\r
426 * Fires when a row is clicked
\r
427 * @param {Grid} this
\r
428 * @param {Number} rowIndex
\r
429 * @param {Ext.EventObject} e
\r
433 * @event rowdblclick
\r
434 * Fires when a row is double clicked
\r
435 * @param {Grid} this
\r
436 * @param {Number} rowIndex
\r
437 * @param {Ext.EventObject} e
\r
441 * @event headerclick
\r
442 * Fires when a header is clicked
\r
443 * @param {Grid} this
\r
444 * @param {Number} columnIndex
\r
445 * @param {Ext.EventObject} e
\r
449 * @event headerdblclick
\r
450 * Fires when a header cell is double clicked
\r
451 * @param {Grid} this
\r
452 * @param {Number} columnIndex
\r
453 * @param {Ext.EventObject} e
\r
457 * @event groupclick
\r
458 * Fires when group header is clicked. <b>Only applies for grids with a {@link Ext.grid.GroupingView GroupingView}</b>.
\r
459 * @param {Grid} this
\r
460 * @param {String} groupField
\r
461 * @param {String} groupValue
\r
462 * @param {Ext.EventObject} e
\r
466 * @event groupdblclick
\r
467 * Fires when group header is double clicked. <b>Only applies for grids with a {@link Ext.grid.GroupingView GroupingView}</b>.
\r
468 * @param {Grid} this
\r
469 * @param {String} groupField
\r
470 * @param {String} groupValue
\r
471 * @param {Ext.EventObject} e
\r
475 * @event containerclick
\r
476 * Fires when the container is clicked. The container consists of any part of the grid body that is not covered by a row.
\r
477 * @param {Grid} this
\r
478 * @param {Ext.EventObject} e
\r
482 * @event containerdblclick
\r
483 * Fires when the container is double clicked. The container consists of any part of the grid body that is not covered by a row.
\r
484 * @param {Grid} this
\r
485 * @param {Ext.EventObject} e
\r
487 'containerdblclick',
\r
490 * @event rowbodyclick
\r
491 * Fires when the row body is clicked. <b>Only applies for grids with {@link Ext.grid.GridView#enableRowBody enableRowBody} configured.</b>
\r
492 * @param {Grid} this
\r
493 * @param {Number} rowIndex
\r
494 * @param {Ext.EventObject} e
\r
498 * @event rowbodydblclick
\r
499 * Fires when the row body is double clicked. <b>Only applies for grids with {@link Ext.grid.GridView#enableRowBody enableRowBody} configured.</b>
\r
500 * @param {Grid} this
\r
501 * @param {Number} rowIndex
\r
502 * @param {Ext.EventObject} e
\r
507 * @event rowcontextmenu
\r
508 * Fires when a row is right clicked
\r
509 * @param {Grid} this
\r
510 * @param {Number} rowIndex
\r
511 * @param {Ext.EventObject} e
\r
515 * @event cellcontextmenu
\r
516 * Fires when a cell is right clicked
\r
517 * @param {Grid} this
\r
518 * @param {Number} rowIndex
\r
519 * @param {Number} cellIndex
\r
520 * @param {Ext.EventObject} e
\r
524 * @event headercontextmenu
\r
525 * Fires when a header is right clicked
\r
526 * @param {Grid} this
\r
527 * @param {Number} columnIndex
\r
528 * @param {Ext.EventObject} e
\r
530 'headercontextmenu',
\r
532 * @event groupcontextmenu
\r
533 * Fires when group header is right clicked. <b>Only applies for grids with a {@link Ext.grid.GroupingView GroupingView}</b>.
\r
534 * @param {Grid} this
\r
535 * @param {String} groupField
\r
536 * @param {String} groupValue
\r
537 * @param {Ext.EventObject} e
\r
539 'groupcontextmenu',
\r
541 * @event containercontextmenu
\r
542 * Fires when the container is right clicked. The container consists of any part of the grid body that is not covered by a row.
\r
543 * @param {Grid} this
\r
544 * @param {Ext.EventObject} e
\r
546 'containercontextmenu',
\r
548 * @event rowbodycontextmenu
\r
549 * Fires when the row body is right clicked. <b>Only applies for grids with {@link Ext.grid.GridView#enableRowBody enableRowBody} configured.</b>
\r
550 * @param {Grid} this
\r
551 * @param {Number} rowIndex
\r
552 * @param {Ext.EventObject} e
\r
554 'rowbodycontextmenu',
\r
556 * @event bodyscroll
\r
557 * Fires when the body element is scrolled
\r
558 * @param {Number} scrollLeft
\r
559 * @param {Number} scrollTop
\r
563 * @event columnresize
\r
564 * Fires when the user resizes a column
\r
565 * @param {Number} columnIndex
\r
566 * @param {Number} newSize
\r
570 * @event columnmove
\r
571 * Fires when the user moves a column
\r
572 * @param {Number} oldIndex
\r
573 * @param {Number} newIndex
\r
577 * @event sortchange
\r
578 * Fires when the grid's store sort changes
\r
579 * @param {Grid} this
\r
580 * @param {Object} sortInfo An object with the keys field and direction
\r
584 * @event groupchange
\r
585 * Fires when the grid's grouping changes (only applies for grids with a {@link Ext.grid.GroupingView GroupingView})
\r
586 * @param {Grid} this
\r
587 * @param {String} groupField A string with the grouping field, null if the store is not grouped.
\r
591 * @event reconfigure
\r
592 * Fires when the grid is reconfigured with a new store and/or column model.
\r
593 * @param {Grid} this
\r
594 * @param {Ext.data.Store} store The new store
\r
595 * @param {Ext.grid.ColumnModel} colModel The new column model
\r
600 * Fires when the grid view is available (use this for selecting a default row).
\r
601 * @param {Grid} this
\r
608 onRender : function(ct, position){
\r
609 Ext.grid.GridPanel.superclass.onRender.apply(this, arguments);
\r
611 var c = this.getGridEl();
\r
613 this.el.addClass('x-grid-panel');
\r
617 mousedown: this.onMouseDown,
\r
618 click: this.onClick,
\r
619 dblclick: this.onDblClick,
\r
620 contextmenu: this.onContextMenu
\r
623 this.relayEvents(c, ['mousedown','mouseup','mouseover','mouseout','keypress', 'keydown']);
\r
625 var view = this.getView();
\r
628 this.getSelectionModel().init(this);
\r
632 initEvents : function(){
\r
633 Ext.grid.GridPanel.superclass.initEvents.call(this);
\r
636 this.loadMask = new Ext.LoadMask(this.bwrap,
\r
637 Ext.apply({store:this.store}, this.loadMask));
\r
641 initStateEvents : function(){
\r
642 Ext.grid.GridPanel.superclass.initStateEvents.call(this);
\r
643 this.mon(this.colModel, 'hiddenchange', this.saveState, this, {delay: 100});
\r
646 applyState : function(state){
\r
647 var cm = this.colModel,
\r
648 cs = state.columns,
\r
649 store = this.store,
\r
655 for(var i = 0, len = cs.length; i < len; i++){
\r
657 c = cm.getColumnById(s.id);
\r
659 c.hidden = s.hidden;
\r
661 oldIndex = cm.getIndexById(s.id);
\r
663 cm.moveColumn(oldIndex, i);
\r
671 store[store.remoteSort ? 'setDefaultSort' : 'sort'](s.field, s.direction);
\r
678 store.clearGrouping();
\r
683 var o = Ext.apply({}, state);
\r
686 Ext.grid.GridPanel.superclass.applyState.call(this, o);
\r
689 getState : function(){
\r
690 var o = {columns: []},
\r
691 store = this.store,
\r
695 for(var i = 0, c; (c = this.colModel.config[i]); i++){
\r
701 o.columns[i].hidden = true;
\r
705 ss = store.getSortState();
\r
709 if(store.getGroupState){
\r
710 gs = store.getGroupState();
\r
720 afterRender : function(){
\r
721 Ext.grid.GridPanel.superclass.afterRender.call(this);
\r
723 this.on('bodyresize', v.layout, v);
\r
725 if(this.deferRowRender){
\r
726 v.afterRender.defer(10, this.view);
\r
730 this.viewReady = true;
\r
734 * <p>Reconfigures the grid to use a different Store and Column Model
\r
735 * and fires the 'reconfigure' event. The View will be bound to the new
\r
736 * objects and refreshed.</p>
\r
737 * <p>Be aware that upon reconfiguring a GridPanel, certain existing settings <i>may</i> become
\r
738 * invalidated. For example the configured {@link #autoExpandColumn} may no longer exist in the
\r
739 * new ColumnModel. Also, an existing {@link Ext.PagingToolbar PagingToolbar} will still be bound
\r
740 * to the old Store, and will need rebinding. Any {@link #plugins} might also need reconfiguring
\r
741 * with the new data.</p>
\r
742 * @param {Ext.data.Store} store The new {@link Ext.data.Store} object
\r
743 * @param {Ext.grid.ColumnModel} colModel The new {@link Ext.grid.ColumnModel} object
\r
745 reconfigure : function(store, colModel){
\r
746 var rendered = this.rendered;
\r
749 this.loadMask.destroy();
\r
750 this.loadMask = new Ext.LoadMask(this.bwrap,
\r
751 Ext.apply({}, {store:store}, this.initialConfig.loadMask));
\r
755 this.view.initData(store, colModel);
\r
757 this.store = store;
\r
758 this.colModel = colModel;
\r
760 this.view.refresh(true);
\r
762 this.fireEvent('reconfigure', this, store, colModel);
\r
766 onDestroy : function(){
\r
768 Ext.destroy(this.view, this.loadMask);
\r
769 }else if(this.store && this.store.autoDestroy){
\r
770 this.store.destroy();
\r
772 Ext.destroy(this.colModel, this.selModel);
\r
773 this.store = this.selModel = this.colModel = this.view = this.loadMask = null;
\r
774 Ext.grid.GridPanel.superclass.onDestroy.call(this);
\r
778 processEvent : function(name, e){
\r
779 this.fireEvent(name, e);
\r
780 var t = e.getTarget(),
\r
782 header = v.findHeaderIndex(t);
\r
784 if(header !== false){
\r
785 this.fireEvent('header' + name, this, header, e);
\r
787 var row = v.findRowIndex(t),
\r
791 this.fireEvent('row' + name, this, row, e);
\r
792 cell = v.findCellIndex(t);
\r
793 body = v.findRowBody(t);
\r
794 if(cell !== false){
\r
795 this.fireEvent('cell' + name, this, row, cell, e);
\r
798 this.fireEvent('rowbody' + name, this, row, e);
\r
801 this.fireEvent('container' + name, this, e);
\r
804 this.view.processEvent(name, e);
\r
808 onClick : function(e){
\r
809 this.processEvent('click', e);
\r
813 onMouseDown : function(e){
\r
814 this.processEvent('mousedown', e);
\r
818 onContextMenu : function(e, t){
\r
819 this.processEvent('contextmenu', e);
\r
823 onDblClick : function(e){
\r
824 this.processEvent('dblclick', e);
\r
828 walkCells : function(row, col, step, fn, scope){
\r
829 var cm = this.colModel,
\r
830 clen = cm.getColumnCount(),
\r
832 rlen = ds.getCount(),
\r
845 if(fn.call(scope || this, row, col, cm) === true){
\r
863 if(fn.call(scope || this, row, col, cm) === true){
\r
875 onResize : function(){
\r
876 Ext.grid.GridPanel.superclass.onResize.apply(this, arguments);
\r
877 if(this.viewReady){
\r
878 this.view.layout();
\r
883 * Returns the grid's underlying element.
\r
884 * @return {Element} The element
\r
886 getGridEl : function(){
\r
890 // private for compatibility, overridden by editor grid
\r
891 stopEditing : Ext.emptyFn,
\r
894 * Returns the grid's selection model configured by the <code>{@link #selModel}</code>
\r
895 * configuration option. If no selection model was configured, this will create
\r
896 * and return a {@link Ext.grid.RowSelectionModel RowSelectionModel}.
\r
897 * @return {SelectionModel}
\r
899 getSelectionModel : function(){
\r
900 if(!this.selModel){
\r
901 this.selModel = new Ext.grid.RowSelectionModel(
\r
902 this.disableSelection ? {selectRow: Ext.emptyFn} : null);
\r
904 return this.selModel;
\r
908 * Returns the grid's data store.
\r
909 * @return {Ext.data.Store} The store
\r
911 getStore : function(){
\r
916 * Returns the grid's ColumnModel.
\r
917 * @return {Ext.grid.ColumnModel} The column model
\r
919 getColumnModel : function(){
\r
920 return this.colModel;
\r
924 * Returns the grid's GridView object.
\r
925 * @return {Ext.grid.GridView} The grid view
\r
927 getView : function(){
\r
929 this.view = new Ext.grid.GridView(this.viewConfig);
\r
934 * Called to get grid's drag proxy text, by default returns this.ddText.
\r
935 * @return {String} The text
\r
937 getDragDropText : function(){
\r
938 var count = this.selModel.getCount();
\r
939 return String.format(this.ddText, count, count == 1 ? '' : 's');
\r
943 * @cfg {String/Number} activeItem
\r
947 * @cfg {Boolean} autoDestroy
\r
951 * @cfg {Object/String/Function} autoLoad
\r
955 * @cfg {Boolean} autoWidth
\r
959 * @cfg {Boolean/Number} bufferResize
\r
963 * @cfg {String} defaultType
\r
967 * @cfg {Object} defaults
\r
971 * @cfg {Boolean} hideBorders
\r
975 * @cfg {Mixed} items
\r
979 * @cfg {String} layout
\r
983 * @cfg {Object} layoutConfig
\r
987 * @cfg {Boolean} monitorResize
\r
1003 * @method doLayout
\r
1015 * @method findById
\r
1019 * @method findByType
\r
1023 * @method getComponent
\r
1027 * @method getLayout
\r
1031 * @method getUpdater
\r
1051 * @event afterlayout
\r
1055 * @event beforeadd
\r
1059 * @event beforeremove
\r
1070 * @cfg {String} allowDomMove @hide
\r
1073 * @cfg {String} autoEl @hide
\r
1076 * @cfg {String} applyTo @hide
\r
1079 * @cfg {String} autoScroll @hide
\r
1082 * @cfg {String} bodyBorder @hide
\r
1085 * @cfg {String} bodyStyle @hide
\r
1088 * @cfg {String} contentEl @hide
\r
1091 * @cfg {String} disabledClass @hide
\r
1094 * @cfg {String} elements @hide
\r
1097 * @cfg {String} html @hide
\r
1100 * @cfg {Boolean} preventBodyReset
\r
1104 * @property disabled
\r
1108 * @method applyToMarkup
\r
1120 * @method setDisabled
\r
1124 Ext.reg('grid', Ext.grid.GridPanel);/**
1125 * @class Ext.grid.GridView
1126 * @extends Ext.util.Observable
1127 * <p>This class encapsulates the user interface of an {@link Ext.grid.GridPanel}.
1128 * Methods of this class may be used to access user interface elements to enable
1129 * special display effects. Do not change the DOM structure of the user interface.</p>
1130 * <p>This class does not provide ways to manipulate the underlying data. The data
1131 * model of a Grid is held in an {@link Ext.data.Store}.</p>
1133 * @param {Object} config
1135 Ext.grid.GridView = Ext.extend(Ext.util.Observable, {
1137 * Override this function to apply custom CSS classes to rows during rendering. You can also supply custom
1138 * parameters to the row template for the current row to customize how it is rendered using the <b>rowParams</b>
1139 * parameter. This function should return the CSS class name (or empty string '' for none) that will be added
1140 * to the row's wrapping div. To apply multiple class names, simply return them space-delimited within the string
1141 * (e.g., 'my-class another-class'). Example usage:
1145 showPreview: true, // custom property
1146 enableRowBody: true, // required to create a second, full-width row to show expanded Record data
1147 getRowClass: function(record, rowIndex, rp, ds){ // rp = rowParams
1148 if(this.showPreview){
1149 rp.body = '<p>'+record.data.excerpt+'</p>';
1150 return 'x-grid3-row-expanded';
1152 return 'x-grid3-row-collapsed';
1156 * @param {Record} record The {@link Ext.data.Record} corresponding to the current row.
1157 * @param {Number} index The row index.
1158 * @param {Object} rowParams A config object that is passed to the row template during rendering that allows
1159 * customization of various aspects of a grid row.
1160 * <p>If {@link #enableRowBody} is configured <b><tt></tt>true</b>, then the following properties may be set
1161 * by this function, and will be used to render a full-width expansion row below each grid row:</p>
1163 * <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>
1164 * <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>
1166 * The following property will be passed in, and may be appended to:
1168 * <li><code>tstyle</code> : String <div class="sub-desc">A CSS style specification that willl be applied to the <table> element which encapsulates
1169 * both the standard grid row, and any expansion row.</div></li>
1171 * @param {Store} store The {@link Ext.data.Store} this grid is bound to
1172 * @method getRowClass
1173 * @return {String} a CSS class name to add to the row.
1176 * @cfg {Boolean} enableRowBody True to add a second TR element per row that can be used to provide a row body
1177 * that spans beneath the data row. Use the {@link #getRowClass} method's rowParams config to customize the row body.
1180 * @cfg {String} emptyText Default text (html tags are accepted) to display in the grid body when no rows
1181 * are available (defaults to ''). This value will be used to update the <tt>{@link #mainBody}</tt>:
1183 this.mainBody.update('<div class="x-grid-empty">' + this.emptyText + '</div>');
1187 * @cfg {Boolean} headersDisabled True to disable the grid column headers (defaults to <tt>false</tt>).
1188 * Use the {@link Ext.grid.ColumnModel ColumnModel} <tt>{@link Ext.grid.ColumnModel#menuDisabled menuDisabled}</tt>
1189 * config to disable the <i>menu</i> for individual columns. While this config is true the
1190 * following will be disabled:<div class="mdetail-params"><ul>
1191 * <li>clicking on header to sort</li>
1192 * <li>the trigger to reveal the menu.</li>
1196 * <p>A customized implementation of a {@link Ext.dd.DragZone DragZone} which provides default implementations
1197 * of the template methods of DragZone to enable dragging of the selected rows of a GridPanel.
1198 * See {@link Ext.grid.GridDragZone} for details.</p>
1199 * <p>This will <b>only</b> be present:<div class="mdetail-params"><ul>
1200 * <li><i>if</i> the owning GridPanel was configured with {@link Ext.grid.GridPanel#enableDragDrop enableDragDrop}: <tt>true</tt>.</li>
1201 * <li><i>after</i> the owning GridPanel has been rendered.</li>
1203 * @property dragZone
1204 * @type {Ext.grid.GridDragZone}
1207 * @cfg {Boolean} deferEmptyText True to defer <tt>{@link #emptyText}</tt> being applied until the store's
1208 * first load (defaults to <tt>true</tt>).
1210 deferEmptyText : true,
1212 * @cfg {Number} scrollOffset The amount of space to reserve for the vertical scrollbar
1213 * (defaults to <tt>undefined</tt>). If an explicit value isn't specified, this will be automatically
1216 scrollOffset : undefined,
1218 * @cfg {Boolean} autoFill
1219 * Defaults to <tt>false</tt>. Specify <tt>true</tt> to have the column widths re-proportioned
1220 * when the grid is <b>initially rendered</b>. The
1221 * {@link Ext.grid.Column#width initially configured width}</tt> of each column will be adjusted
1222 * to fit the grid width and prevent horizontal scrolling. If columns are later resized (manually
1223 * or programmatically), the other columns in the grid will <b>not</b> be resized to fit the grid width.
1224 * See <tt>{@link #forceFit}</tt> also.
1228 * @cfg {Boolean} forceFit
1229 * Defaults to <tt>false</tt>. Specify <tt>true</tt> to have the column widths re-proportioned
1230 * at <b>all times</b>. The {@link Ext.grid.Column#width initially configured width}</tt> of each
1231 * column will be adjusted to fit the grid width and prevent horizontal scrolling. If columns are
1232 * later resized (manually or programmatically), the other columns in the grid <b>will</b> be resized
1233 * to fit the grid width. See <tt>{@link #autoFill}</tt> also.
1237 * @cfg {Array} sortClasses The CSS classes applied to a header when it is sorted. (defaults to <tt>['sort-asc', 'sort-desc']</tt>)
1239 sortClasses : ['sort-asc', 'sort-desc'],
1241 * @cfg {String} sortAscText The text displayed in the 'Sort Ascending' menu item (defaults to <tt>'Sort Ascending'</tt>)
1243 sortAscText : 'Sort Ascending',
1245 * @cfg {String} sortDescText The text displayed in the 'Sort Descending' menu item (defaults to <tt>'Sort Descending'</tt>)
1247 sortDescText : 'Sort Descending',
1249 * @cfg {String} columnsText The text displayed in the 'Columns' menu item (defaults to <tt>'Columns'</tt>)
1251 columnsText : 'Columns',
1254 * @cfg {String} selectedRowClass The CSS class applied to a selected row (defaults to <tt>'x-grid3-row-selected'</tt>). An
1255 * example overriding the default styling:
1257 .x-grid3-row-selected {background-color: yellow;}
1259 * Note that this only controls the row, and will not do anything for the text inside it. To style inner
1260 * facets (like text) use something like:
1262 .x-grid3-row-selected .x-grid3-cell-inner {
1268 selectedRowClass : 'x-grid3-row-selected',
1272 tdClass : 'x-grid3-cell',
1273 hdCls : 'x-grid3-hd',
1277 * @cfg {Number} cellSelectorDepth The number of levels to search for cells in event delegation (defaults to <tt>4</tt>)
1279 cellSelectorDepth : 4,
1281 * @cfg {Number} rowSelectorDepth The number of levels to search for rows in event delegation (defaults to <tt>10</tt>)
1283 rowSelectorDepth : 10,
1286 * @cfg {Number} rowBodySelectorDepth The number of levels to search for row bodies in event delegation (defaults to <tt>10</tt>)
1288 rowBodySelectorDepth : 10,
1291 * @cfg {String} cellSelector The selector used to find cells internally (defaults to <tt>'td.x-grid3-cell'</tt>)
1293 cellSelector : 'td.x-grid3-cell',
1295 * @cfg {String} rowSelector The selector used to find rows internally (defaults to <tt>'div.x-grid3-row'</tt>)
1297 rowSelector : 'div.x-grid3-row',
1300 * @cfg {String} rowBodySelector The selector used to find row bodies internally (defaults to <tt>'div.x-grid3-row'</tt>)
1302 rowBodySelector : 'div.x-grid3-row-body',
1305 firstRowCls: 'x-grid3-row-first',
1306 lastRowCls: 'x-grid3-row-last',
1307 rowClsRe: /(?:^|\s+)x-grid3-row-(first|last|alt)(?:\s+|$)/g,
1309 constructor : function(config){
1310 Ext.apply(this, config);
1311 // These events are only used internally by the grid components
1314 * @event beforerowremoved
1315 * Internal UI Event. Fired before a row is removed.
1316 * @param {Ext.grid.GridView} view
1317 * @param {Number} rowIndex The index of the row to be removed.
1318 * @param {Ext.data.Record} record The Record to be removed
1322 * @event beforerowsinserted
1323 * Internal UI Event. Fired before rows are inserted.
1324 * @param {Ext.grid.GridView} view
1325 * @param {Number} firstRow The index of the first row to be inserted.
1326 * @param {Number} lastRow The index of the last row to be inserted.
1328 'beforerowsinserted',
1330 * @event beforerefresh
1331 * Internal UI Event. Fired before the view is refreshed.
1332 * @param {Ext.grid.GridView} view
1337 * Internal UI Event. Fired after a row is removed.
1338 * @param {Ext.grid.GridView} view
1339 * @param {Number} rowIndex The index of the row that was removed.
1340 * @param {Ext.data.Record} record The Record that was removed
1344 * @event rowsinserted
1345 * Internal UI Event. Fired after rows are inserted.
1346 * @param {Ext.grid.GridView} view
1347 * @param {Number} firstRow The index of the first inserted.
1348 * @param {Number} lastRow The index of the last row inserted.
1353 * Internal UI Event. Fired after a row has been updated.
1354 * @param {Ext.grid.GridView} view
1355 * @param {Number} firstRow The index of the row updated.
1356 * @param {Ext.data.record} record The Record backing the row updated.
1361 * Internal UI Event. Fired after the GridView's body has been refreshed.
1362 * @param {Ext.grid.GridView} view
1366 Ext.grid.GridView.superclass.constructor.call(this);
1369 /* -------------------------------- UI Specific ----------------------------- */
1372 initTemplates : function(){
1373 var ts = this.templates || {};
1375 ts.master = new Ext.Template(
1376 '<div class="x-grid3" hidefocus="true">',
1377 '<div class="x-grid3-viewport">',
1378 '<div class="x-grid3-header"><div class="x-grid3-header-inner"><div class="x-grid3-header-offset" style="{ostyle}">{header}</div></div><div class="x-clear"></div></div>',
1379 '<div class="x-grid3-scroller"><div class="x-grid3-body" style="{bstyle}">{body}</div><a href="#" class="x-grid3-focus" tabIndex="-1"></a></div>',
1381 '<div class="x-grid3-resize-marker"> </div>',
1382 '<div class="x-grid3-resize-proxy"> </div>',
1388 ts.header = new Ext.Template(
1389 '<table border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
1390 '<thead><tr class="x-grid3-hd-row">{cells}</tr></thead>',
1396 ts.hcell = new Ext.Template(
1397 '<td class="x-grid3-hd x-grid3-cell x-grid3-td-{id} {css}" style="{style}"><div {tooltip} {attr} class="x-grid3-hd-inner x-grid3-hd-{id}" unselectable="on" style="{istyle}">', this.grid.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '',
1398 '{value}<img class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
1404 ts.body = new Ext.Template('{rows}');
1408 ts.row = new Ext.Template(
1409 '<div class="x-grid3-row {alt}" style="{tstyle}"><table class="x-grid3-row-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
1410 '<tbody><tr>{cells}</tr>',
1411 (this.enableRowBody ? '<tr class="x-grid3-row-body-tr" style="{bodyStyle}"><td colspan="{cols}" class="x-grid3-body-cell" tabIndex="0" hidefocus="on"><div class="x-grid3-row-body">{body}</div></td></tr>' : ''),
1412 '</tbody></table></div>'
1417 ts.cell = new Ext.Template(
1418 '<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} {css}" style="{style}" tabIndex="0" {cellAttr}>',
1419 '<div class="x-grid3-cell-inner x-grid3-col-{id}" unselectable="on" {attr}>{value}</div>',
1426 if(t && Ext.isFunction(t.compile) && !t.compiled){
1427 t.disableFormats = true;
1432 this.templates = ts;
1433 this.colRe = new RegExp('x-grid3-td-([^\\s]+)', '');
1438 if(!this._flyweight){
1439 this._flyweight = new Ext.Element.Flyweight(document.body);
1441 this._flyweight.dom = el;
1442 return this._flyweight;
1446 getEditorParent : function(){
1447 return this.scroller.dom;
1451 initElements : function(){
1452 var E = Ext.Element;
1454 var el = this.grid.getGridEl().dom.firstChild;
1455 var cs = el.childNodes;
1457 this.el = new E(el);
1459 this.mainWrap = new E(cs[0]);
1460 this.mainHd = new E(this.mainWrap.dom.firstChild);
1462 if(this.grid.hideHeaders){
1463 this.mainHd.setDisplayed(false);
1466 this.innerHd = this.mainHd.dom.firstChild;
1467 this.scroller = new E(this.mainWrap.dom.childNodes[1]);
1469 this.scroller.setStyle('overflow-x', 'hidden');
1472 * <i>Read-only</i>. The GridView's body Element which encapsulates all rows in the Grid.
1473 * This {@link Ext.Element Element} is only available after the GridPanel has been rendered.
1475 * @property mainBody
1477 this.mainBody = new E(this.scroller.dom.firstChild);
1479 this.focusEl = new E(this.scroller.dom.childNodes[1]);
1480 this.focusEl.swallowEvent('click', true);
1482 this.resizeMarker = new E(cs[1]);
1483 this.resizeProxy = new E(cs[2]);
1487 getRows : function(){
1488 return this.hasRows() ? this.mainBody.dom.childNodes : [];
1491 // finder methods, used with delegation
1494 findCell : function(el){
1498 return this.fly(el).findParent(this.cellSelector, this.cellSelectorDepth);
1502 * <p>Return the index of the grid column which contains the passed HTMLElement.</p>
1503 * See also {@link #findRowIndex}
1504 * @param {HTMLElement} el The target element
1505 * @return {Number} The column index, or <b>false</b> if the target element is not within a row of this GridView.
1507 findCellIndex : function(el, requiredCls){
1508 var cell = this.findCell(el);
1509 if(cell && (!requiredCls || this.fly(cell).hasClass(requiredCls))){
1510 return this.getCellIndex(cell);
1516 getCellIndex : function(el){
1518 var m = el.className.match(this.colRe);
1520 return this.cm.getIndexById(m[1]);
1527 findHeaderCell : function(el){
1528 var cell = this.findCell(el);
1529 return cell && this.fly(cell).hasClass(this.hdCls) ? cell : null;
1533 findHeaderIndex : function(el){
1534 return this.findCellIndex(el, this.hdCls);
1538 * Return the HtmlElement representing the grid row which contains the passed element.
1539 * @param {HTMLElement} el The target HTMLElement
1540 * @return {HTMLElement} The row element, or null if the target element is not within a row of this GridView.
1542 findRow : function(el){
1546 return this.fly(el).findParent(this.rowSelector, this.rowSelectorDepth);
1550 * <p>Return the index of the grid row which contains the passed HTMLElement.</p>
1551 * See also {@link #findCellIndex}
1552 * @param {HTMLElement} el The target HTMLElement
1553 * @return {Number} The row index, or <b>false</b> if the target element is not within a row of this GridView.
1555 findRowIndex : function(el){
1556 var r = this.findRow(el);
1557 return r ? r.rowIndex : false;
1561 * Return the HtmlElement representing the grid row body which contains the passed element.
1562 * @param {HTMLElement} el The target HTMLElement
1563 * @return {HTMLElement} The row body element, or null if the target element is not within a row body of this GridView.
1565 findRowBody : function(el){
1569 return this.fly(el).findParent(this.rowBodySelector, this.rowBodySelectorDepth);
1572 // getter methods for fetching elements dynamically in the grid
1575 * Return the <tt><div></tt> HtmlElement which represents a Grid row for the specified index.
1576 * @param {Number} index The row index
1577 * @return {HtmlElement} The div element.
1579 getRow : function(row){
1580 return this.getRows()[row];
1584 * Returns the grid's <tt><td></tt> HtmlElement at the specified coordinates.
1585 * @param {Number} row The row index in which to find the cell.
1586 * @param {Number} col The column index of the cell.
1587 * @return {HtmlElement} The td at the specified coordinates.
1589 getCell : function(row, col){
1590 return this.getRow(row).getElementsByTagName('td')[col];
1594 * Return the <tt><td></tt> HtmlElement which represents the Grid's header cell for the specified column index.
1595 * @param {Number} index The column index
1596 * @return {HtmlElement} The td element.
1598 getHeaderCell : function(index){
1599 return this.mainHd.dom.getElementsByTagName('td')[index];
1602 // manipulating elements
1604 // private - use getRowClass to apply custom row classes
1605 addRowClass : function(row, cls){
1606 var r = this.getRow(row);
1608 this.fly(r).addClass(cls);
1613 removeRowClass : function(row, cls){
1614 var r = this.getRow(row);
1616 this.fly(r).removeClass(cls);
1621 removeRow : function(row){
1622 Ext.removeNode(this.getRow(row));
1623 this.syncFocusEl(row);
1627 removeRows : function(firstRow, lastRow){
1628 var bd = this.mainBody.dom;
1629 for(var rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){
1630 Ext.removeNode(bd.childNodes[firstRow]);
1632 this.syncFocusEl(firstRow);
1638 getScrollState : function(){
1639 var sb = this.scroller.dom;
1640 return {left: sb.scrollLeft, top: sb.scrollTop};
1644 restoreScroll : function(state){
1645 var sb = this.scroller.dom;
1646 sb.scrollLeft = state.left;
1647 sb.scrollTop = state.top;
1651 * Scrolls the grid to the top
1653 scrollToTop : function(){
1654 this.scroller.dom.scrollTop = 0;
1655 this.scroller.dom.scrollLeft = 0;
1659 syncScroll : function(){
1660 this.syncHeaderScroll();
1661 var mb = this.scroller.dom;
1662 this.grid.fireEvent('bodyscroll', mb.scrollLeft, mb.scrollTop);
1666 syncHeaderScroll : function(){
1667 var mb = this.scroller.dom;
1668 this.innerHd.scrollLeft = mb.scrollLeft;
1669 this.innerHd.scrollLeft = mb.scrollLeft; // second time for IE (1/2 time first fails, other browsers ignore)
1673 updateSortIcon : function(col, dir){
1674 var sc = this.sortClasses;
1675 var hds = this.mainHd.select('td').removeClass(sc);
1676 hds.item(col).addClass(sc[dir == 'DESC' ? 1 : 0]);
1680 updateAllColumnWidths : function(){
1681 var tw = this.getTotalWidth(),
1682 clen = this.cm.getColumnCount(),
1686 for(i = 0; i < clen; i++){
1687 ws[i] = this.getColumnWidth(i);
1689 this.innerHd.firstChild.style.width = this.getOffsetWidth();
1690 this.innerHd.firstChild.firstChild.style.width = tw;
1691 this.mainBody.dom.style.width = tw;
1692 for(i = 0; i < clen; i++){
1693 var hd = this.getHeaderCell(i);
1694 hd.style.width = ws[i];
1697 var ns = this.getRows(), row, trow;
1698 for(i = 0, len = ns.length; i < len; i++){
1700 row.style.width = tw;
1702 row.firstChild.style.width = tw;
1703 trow = row.firstChild.rows[0];
1704 for (var j = 0; j < clen; j++) {
1705 trow.childNodes[j].style.width = ws[j];
1710 this.onAllColumnWidthsUpdated(ws, tw);
1714 updateColumnWidth : function(col, width){
1715 var w = this.getColumnWidth(col);
1716 var tw = this.getTotalWidth();
1717 this.innerHd.firstChild.style.width = this.getOffsetWidth();
1718 this.innerHd.firstChild.firstChild.style.width = tw;
1719 this.mainBody.dom.style.width = tw;
1720 var hd = this.getHeaderCell(col);
1723 var ns = this.getRows(), row;
1724 for(var i = 0, len = ns.length; i < len; i++){
1726 row.style.width = tw;
1728 row.firstChild.style.width = tw;
1729 row.firstChild.rows[0].childNodes[col].style.width = w;
1733 this.onColumnWidthUpdated(col, w, tw);
1737 updateColumnHidden : function(col, hidden){
1738 var tw = this.getTotalWidth();
1739 this.innerHd.firstChild.style.width = this.getOffsetWidth();
1740 this.innerHd.firstChild.firstChild.style.width = tw;
1741 this.mainBody.dom.style.width = tw;
1742 var display = hidden ? 'none' : '';
1744 var hd = this.getHeaderCell(col);
1745 hd.style.display = display;
1747 var ns = this.getRows(), row;
1748 for(var i = 0, len = ns.length; i < len; i++){
1750 row.style.width = tw;
1752 row.firstChild.style.width = tw;
1753 row.firstChild.rows[0].childNodes[col].style.display = display;
1757 this.onColumnHiddenUpdated(col, hidden, tw);
1758 delete this.lastViewWidth; // force recalc
1763 doRender : function(cs, rs, ds, startRow, colCount, stripe){
1764 var ts = this.templates, ct = ts.cell, rt = ts.row, last = colCount-1;
1765 var tstyle = 'width:'+this.getTotalWidth()+';';
1767 var buf = [], cb, c, p = {}, rp = {tstyle: tstyle}, r;
1768 for(var j = 0, len = rs.length; j < len; j++){
1770 var rowIndex = (j+startRow);
1771 for(var i = 0; i < colCount; i++){
1774 p.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
1775 p.attr = p.cellAttr = '';
1776 p.value = c.renderer.call(c.scope, r.data[c.name], p, r, rowIndex, i, ds);
1778 if(Ext.isEmpty(p.value)){
1781 if(this.markDirty && r.dirty && Ext.isDefined(r.modified[c.name])){
1782 p.css += ' x-grid3-dirty-cell';
1784 cb[cb.length] = ct.apply(p);
1787 if(stripe && ((rowIndex+1) % 2 === 0)){
1788 alt[0] = 'x-grid3-row-alt';
1791 alt[1] = ' x-grid3-dirty-row';
1794 if(this.getRowClass){
1795 alt[2] = this.getRowClass(r, rowIndex, rp, ds);
1797 rp.alt = alt.join(' ');
1798 rp.cells = cb.join('');
1799 buf[buf.length] = rt.apply(rp);
1801 return buf.join('');
1805 processRows : function(startRow, skipStripe){
1806 if(!this.ds || this.ds.getCount() < 1){
1809 var rows = this.getRows(),
1813 skipStripe = skipStripe || !this.grid.stripeRows;
1814 startRow = startRow || 0;
1815 for(i = 0; i<len; i++) {
1820 r.className = r.className.replace(this.rowClsRe, ' ');
1821 if ((i + 1) % 2 === 0){
1822 r.className += ' x-grid3-row-alt';
1827 // add first/last-row classes
1829 Ext.fly(rows[0]).addClass(this.firstRowCls);
1831 Ext.fly(rows[rows.length - 1]).addClass(this.lastRowCls);
1834 afterRender : function(){
1835 if(!this.ds || !this.cm){
1838 this.mainBody.dom.innerHTML = this.renderRows() || ' ';
1839 this.processRows(0, true);
1841 if(this.deferEmptyText !== true){
1842 this.applyEmptyText();
1844 this.grid.fireEvent('viewready', this.grid);
1848 renderUI : function(){
1850 var header = this.renderHeaders();
1851 var body = this.templates.body.apply({rows:' '});
1854 var html = this.templates.master.apply({
1857 ostyle: 'width:'+this.getOffsetWidth()+';',
1858 bstyle: 'width:'+this.getTotalWidth()+';'
1863 g.getGridEl().dom.innerHTML = html;
1865 this.initElements();
1867 // get mousedowns early
1868 Ext.fly(this.innerHd).on('click', this.handleHdDown, this);
1871 mouseover: this.handleHdOver,
1872 mouseout: this.handleHdOut,
1873 mousemove: this.handleHdMove
1876 this.scroller.on('scroll', this.syncScroll, this);
1877 if(g.enableColumnResize !== false){
1878 this.splitZone = new Ext.grid.GridView.SplitDragZone(g, this.mainHd.dom);
1881 if(g.enableColumnMove){
1882 this.columnDrag = new Ext.grid.GridView.ColumnDragZone(g, this.innerHd);
1883 this.columnDrop = new Ext.grid.HeaderDropZone(g, this.mainHd.dom);
1886 if(g.enableHdMenu !== false){
1887 this.hmenu = new Ext.menu.Menu({id: g.id + '-hctx'});
1889 {itemId:'asc', text: this.sortAscText, cls: 'xg-hmenu-sort-asc'},
1890 {itemId:'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'}
1892 if(g.enableColumnHide !== false){
1893 this.colMenu = new Ext.menu.Menu({id:g.id + '-hcols-menu'});
1896 beforeshow: this.beforeColMenuShow,
1897 itemclick: this.handleHdMenuClick
1899 this.hmenu.add('-', {
1902 text: this.columnsText,
1904 iconCls: 'x-cols-icon'
1907 this.hmenu.on('itemclick', this.handleHdMenuClick, this);
1910 if(g.trackMouseOver){
1913 mouseover: this.onRowOver,
1914 mouseout: this.onRowOut
1918 if(g.enableDragDrop || g.enableDrag){
1919 this.dragZone = new Ext.grid.GridDragZone(g, {
1920 ddGroup : g.ddGroup || 'GridDD'
1924 this.updateHeaderSortState();
1929 processEvent: Ext.emptyFn,
1932 layout : function(){
1934 return; // not rendered
1937 var c = g.getGridEl();
1938 var csize = c.getSize(true);
1939 var vw = csize.width;
1941 if(!g.hideHeaders && (vw < 20 || csize.height < 20)){ // display: none?
1946 this.scroller.dom.style.overflow = 'visible';
1948 this.scroller.dom.style.position = 'static';
1951 this.el.setSize(csize.width, csize.height);
1953 var hdHeight = this.mainHd.getHeight();
1954 var vh = csize.height - (hdHeight);
1956 this.scroller.setSize(vw, vh);
1958 this.innerHd.style.width = (vw)+'px';
1962 if(this.lastViewWidth != vw){
1963 this.fitColumns(false, false);
1964 this.lastViewWidth = vw;
1968 this.syncHeaderScroll();
1970 this.onLayout(vw, vh);
1973 // template functions for subclasses and plugins
1974 // these functions include precalculated values
1975 onLayout : function(vw, vh){
1979 onColumnWidthUpdated : function(col, w, tw){
1983 onAllColumnWidthsUpdated : function(ws, tw){
1987 onColumnHiddenUpdated : function(col, hidden, tw){
1991 updateColumnText : function(col, text){
1995 afterMove : function(colIndex){
1999 /* ----------------------------------- Core Specific -------------------------------------------*/
2001 init : function(grid){
2004 this.initTemplates();
2005 this.initData(grid.store, grid.colModel);
2010 getColumnId : function(index){
2011 return this.cm.getColumnId(index);
2015 getOffsetWidth : function() {
2016 return (this.cm.getTotalWidth() + this.getScrollOffset()) + 'px';
2019 getScrollOffset: function(){
2020 return Ext.num(this.scrollOffset, Ext.getScrollBarWidth());
2024 renderHeaders : function(){
2026 ts = this.templates,
2030 len = cm.getColumnCount(),
2033 for(var i = 0; i < len; i++){
2034 p.id = cm.getColumnId(i);
2035 p.value = cm.getColumnHeader(i) || '';
2036 p.style = this.getColumnStyle(i, true);
2037 p.tooltip = this.getColumnTooltip(i);
2038 p.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
2039 if(cm.config[i].align == 'right'){
2040 p.istyle = 'padding-right:16px';
2044 cb[cb.length] = ct.apply(p);
2046 return ts.header.apply({cells: cb.join(''), tstyle:'width:'+this.getTotalWidth()+';'});
2050 getColumnTooltip : function(i){
2051 var tt = this.cm.getColumnTooltip(i);
2053 if(Ext.QuickTips.isEnabled()){
2054 return 'ext:qtip="'+tt+'"';
2056 return 'title="'+tt+'"';
2063 beforeUpdate : function(){
2064 this.grid.stopEditing(true);
2068 updateHeaders : function(){
2069 this.innerHd.firstChild.innerHTML = this.renderHeaders();
2070 this.innerHd.firstChild.style.width = this.getOffsetWidth();
2071 this.innerHd.firstChild.firstChild.style.width = this.getTotalWidth();
2075 * Focuses the specified row.
2076 * @param {Number} row The row index
2078 focusRow : function(row){
2079 this.focusCell(row, 0, false);
2083 * Focuses the specified cell.
2084 * @param {Number} row The row index
2085 * @param {Number} col The column index
2087 focusCell : function(row, col, hscroll){
2088 this.syncFocusEl(this.ensureVisible(row, col, hscroll));
2090 this.focusEl.focus();
2092 this.focusEl.focus.defer(1, this.focusEl);
2096 resolveCell : function(row, col, hscroll){
2097 if(!Ext.isNumber(row)){
2103 if(row < 0 || row >= this.ds.getCount()){
2106 col = (col !== undefined ? col : 0);
2108 var rowEl = this.getRow(row),
2110 colCount = cm.getColumnCount(),
2112 if(!(hscroll === false && col === 0)){
2113 while(col < colCount && cm.isHidden(col)){
2116 cellEl = this.getCell(row, col);
2119 return {row: rowEl, cell: cellEl};
2122 getResolvedXY : function(resolved){
2126 var s = this.scroller.dom, c = resolved.cell, r = resolved.row;
2127 return c ? Ext.fly(c).getXY() : [this.el.getX(), Ext.fly(r).getY()];
2130 syncFocusEl : function(row, col, hscroll){
2132 if(!Ext.isArray(xy)){
2133 row = Math.min(row, Math.max(0, this.getRows().length-1));
2134 xy = this.getResolvedXY(this.resolveCell(row, col, hscroll));
2136 this.focusEl.setXY(xy||this.scroller.getXY());
2139 ensureVisible : function(row, col, hscroll){
2140 var resolved = this.resolveCell(row, col, hscroll);
2141 if(!resolved || !resolved.row){
2145 var rowEl = resolved.row,
2146 cellEl = resolved.cell,
2147 c = this.scroller.dom,
2152 while(p && p != stop){
2153 ctop += p.offsetTop;
2157 ctop -= this.mainHd.dom.offsetHeight;
2158 stop = parseInt(c.scrollTop, 10);
2160 var cbot = ctop + rowEl.offsetHeight,
2161 ch = c.clientHeight,
2167 }else if(cbot > sbot){
2168 c.scrollTop = cbot-ch;
2171 if(hscroll !== false){
2172 var cleft = parseInt(cellEl.offsetLeft, 10);
2173 var cright = cleft + cellEl.offsetWidth;
2175 var sleft = parseInt(c.scrollLeft, 10);
2176 var sright = sleft + c.clientWidth;
2178 c.scrollLeft = cleft;
2179 }else if(cright > sright){
2180 c.scrollLeft = cright-c.clientWidth;
2183 return this.getResolvedXY(resolved);
2187 insertRows : function(dm, firstRow, lastRow, isUpdate){
2188 var last = dm.getCount() - 1;
2189 if(!isUpdate && firstRow === 0 && lastRow >= last){
2190 this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
2192 this.fireEvent('rowsinserted', this, firstRow, lastRow);
2195 this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
2197 var html = this.renderRows(firstRow, lastRow),
2198 before = this.getRow(firstRow);
2201 Ext.fly(this.getRow(0)).removeClass(this.firstRowCls);
2203 Ext.DomHelper.insertHtml('beforeBegin', before, html);
2205 var r = this.getRow(last - 1);
2207 Ext.fly(r).removeClass(this.lastRowCls);
2209 Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html);
2212 this.fireEvent('rowsinserted', this, firstRow, lastRow);
2213 this.processRows(firstRow);
2214 }else if(firstRow === 0 || firstRow >= last){
2215 //ensure first/last row is kept after an update.
2216 Ext.fly(this.getRow(firstRow)).addClass(firstRow === 0 ? this.firstRowCls : this.lastRowCls);
2219 this.syncFocusEl(firstRow);
2223 deleteRows : function(dm, firstRow, lastRow){
2224 if(dm.getRowCount()<1){
2227 this.fireEvent('beforerowsdeleted', this, firstRow, lastRow);
2229 this.removeRows(firstRow, lastRow);
2231 this.processRows(firstRow);
2232 this.fireEvent('rowsdeleted', this, firstRow, lastRow);
2237 getColumnStyle : function(col, isHeader){
2238 var style = !isHeader ? (this.cm.config[col].css || '') : '';
2239 style += 'width:'+this.getColumnWidth(col)+';';
2240 if(this.cm.isHidden(col)){
2241 style += 'display:none;';
2243 var align = this.cm.config[col].align;
2245 style += 'text-align:'+align+';';
2251 getColumnWidth : function(col){
2252 var w = this.cm.getColumnWidth(col);
2253 if(Ext.isNumber(w)){
2254 return (Ext.isBorderBox || (Ext.isWebKit && !Ext.isSafari2) ? w : (w - this.borderWidth > 0 ? w - this.borderWidth : 0)) + 'px';
2260 getTotalWidth : function(){
2261 return this.cm.getTotalWidth()+'px';
2265 fitColumns : function(preventRefresh, onlyExpand, omitColumn){
2266 var cm = this.cm, i;
2267 var tw = cm.getTotalWidth(false);
2268 var aw = this.grid.getGridEl().getWidth(true)-this.getScrollOffset();
2270 if(aw < 20){ // not initialized, so don't screw up the default widths
2273 var extra = aw - tw;
2279 var vc = cm.getColumnCount(true);
2280 var ac = vc-(Ext.isNumber(omitColumn) ? 1 : 0);
2283 omitColumn = undefined;
2285 var colCount = cm.getColumnCount();
2290 for (i = 0; i < colCount; i++){
2291 if(!cm.isHidden(i) && !cm.isFixed(i) && i !== omitColumn){
2292 w = cm.getColumnWidth(i);
2299 var frac = (aw - cm.getTotalWidth())/width;
2300 while (cols.length){
2303 cm.setColumnWidth(i, Math.max(this.grid.minColumnWidth, Math.floor(w + w*frac)), true);
2306 if((tw = cm.getTotalWidth(false)) > aw){
2307 var adjustCol = ac != vc ? omitColumn : extraCol;
2308 cm.setColumnWidth(adjustCol, Math.max(1,
2309 cm.getColumnWidth(adjustCol)- (tw-aw)), true);
2312 if(preventRefresh !== true){
2313 this.updateAllColumnWidths();
2321 autoExpand : function(preventUpdate){
2322 var g = this.grid, cm = this.cm;
2323 if(!this.userResized && g.autoExpandColumn){
2324 var tw = cm.getTotalWidth(false);
2325 var aw = this.grid.getGridEl().getWidth(true)-this.getScrollOffset();
2327 var ci = cm.getIndexById(g.autoExpandColumn);
2328 var currentWidth = cm.getColumnWidth(ci);
2329 var cw = Math.min(Math.max(((aw-tw)+currentWidth), g.autoExpandMin), g.autoExpandMax);
2330 if(cw != currentWidth){
2331 cm.setColumnWidth(ci, cw, true);
2332 if(preventUpdate !== true){
2333 this.updateColumnWidth(ci, cw);
2341 getColumnData : function(){
2342 // build a map for all the columns
2343 var cs = [], cm = this.cm, colCount = cm.getColumnCount();
2344 for(var i = 0; i < colCount; i++){
2345 var name = cm.getDataIndex(i);
2347 name : (!Ext.isDefined(name) ? this.ds.fields.get(i).name : name),
2348 renderer : cm.getRenderer(i),
2349 scope: cm.getRendererScope(i),
2350 id : cm.getColumnId(i),
2351 style : this.getColumnStyle(i)
2358 renderRows : function(startRow, endRow){
2359 // pull in all the crap needed to render rows
2360 var g = this.grid, cm = g.colModel, ds = g.store, stripe = g.stripeRows;
2361 var colCount = cm.getColumnCount();
2363 if(ds.getCount() < 1){
2367 var cs = this.getColumnData();
2369 startRow = startRow || 0;
2370 endRow = !Ext.isDefined(endRow) ? ds.getCount()-1 : endRow;
2372 // records to render
2373 var rs = ds.getRange(startRow, endRow);
2375 return this.doRender(cs, rs, ds, startRow, colCount, stripe);
2379 renderBody : function(){
2380 var markup = this.renderRows() || ' ';
2381 return this.templates.body.apply({rows: markup});
2385 refreshRow : function(record){
2386 var ds = this.ds, index;
2387 if(Ext.isNumber(record)){
2389 record = ds.getAt(index);
2394 index = ds.indexOf(record);
2399 this.insertRows(ds, index, index, true);
2400 this.getRow(index).rowIndex = index;
2401 this.onRemove(ds, record, index+1, true);
2402 this.fireEvent('rowupdated', this, index, record);
2406 * Refreshs the grid UI
2407 * @param {Boolean} headersToo (optional) True to also refresh the headers
2409 refresh : function(headersToo){
2410 this.fireEvent('beforerefresh', this);
2411 this.grid.stopEditing(true);
2413 var result = this.renderBody();
2414 this.mainBody.update(result).setWidth(this.getTotalWidth());
2415 if(headersToo === true){
2416 this.updateHeaders();
2417 this.updateHeaderSortState();
2419 this.processRows(0, true);
2421 this.applyEmptyText();
2422 this.fireEvent('refresh', this);
2426 applyEmptyText : function(){
2427 if(this.emptyText && !this.hasRows()){
2428 this.mainBody.update('<div class="x-grid-empty">' + this.emptyText + '</div>');
2433 updateHeaderSortState : function(){
2434 var state = this.ds.getSortState();
2438 if(!this.sortState || (this.sortState.field != state.field || this.sortState.direction != state.direction)){
2439 this.grid.fireEvent('sortchange', this.grid, state);
2441 this.sortState = state;
2442 var sortColumn = this.cm.findColumnIndex(state.field);
2443 if(sortColumn != -1){
2444 var sortDir = state.direction;
2445 this.updateSortIcon(sortColumn, sortDir);
2450 clearHeaderSortState : function(){
2451 if(!this.sortState){
2454 this.grid.fireEvent('sortchange', this.grid, null);
2455 this.mainHd.select('td').removeClass(this.sortClasses);
2456 delete this.sortState;
2460 destroy : function(){
2462 Ext.menu.MenuMgr.unregister(this.colMenu);
2463 this.colMenu.destroy();
2464 delete this.colMenu;
2467 Ext.menu.MenuMgr.unregister(this.hmenu);
2468 this.hmenu.destroy();
2472 this.initData(null, null);
2473 this.purgeListeners();
2474 Ext.fly(this.innerHd).un("click", this.handleHdDown, this);
2476 if(this.grid.enableColumnMove){
2479 this.columnDrag.proxy.ghost,
2480 this.columnDrag.proxy.el,
2482 this.columnDrop.proxyTop,
2483 this.columnDrop.proxyBottom,
2484 this.columnDrag.dragData.ddel,
2485 this.columnDrag.dragData.header
2487 if (this.columnDrag.proxy.anim) {
2488 Ext.destroy(this.columnDrag.proxy.anim);
2490 delete this.columnDrag.proxy.ghost;
2491 delete this.columnDrag.dragData.ddel;
2492 delete this.columnDrag.dragData.header;
2493 this.columnDrag.destroy();
2494 delete Ext.dd.DDM.locationCache[this.columnDrag.id];
2495 delete this.columnDrag._domRef;
2497 delete this.columnDrop.proxyTop;
2498 delete this.columnDrop.proxyBottom;
2499 this.columnDrop.destroy();
2500 delete Ext.dd.DDM.locationCache["gridHeader" + this.grid.getGridEl().id];
2501 delete this.columnDrop._domRef;
2502 delete Ext.dd.DDM.ids[this.columnDrop.ddGroup];
2505 if (this.splitZone){ // enableColumnResize
2506 this.splitZone.destroy();
2507 delete this.splitZone._domRef;
2508 delete Ext.dd.DDM.ids["gridSplitters" + this.grid.getGridEl().id];
2511 Ext.fly(this.innerHd).removeAllListeners();
2512 Ext.removeNode(this.innerHd);
2513 delete this.innerHd;
2530 delete this.grid.container;
2533 this.dragZone.destroy();
2536 Ext.dd.DDM.currentTarget = null;
2537 delete Ext.dd.DDM.locationCache[this.grid.getGridEl().id];
2539 Ext.EventManager.removeResizeListener(this.onWindowResize, this);
2543 onDenyColumnHide : function(){
2548 render : function(){
2550 var ct = this.grid.ownerCt;
2551 if (ct && ct.getLayout()){
2552 ct.on('afterlayout', function(){
2553 this.fitColumns(true, true);
2554 this.updateHeaders();
2555 }, this, {single: true});
2557 this.fitColumns(true, true);
2559 }else if(this.forceFit){
2560 this.fitColumns(true, false);
2561 }else if(this.grid.autoExpandColumn){
2562 this.autoExpand(true);
2568 /* --------------------------------- Model Events and Handlers --------------------------------*/
2570 initData : function(ds, cm){
2572 this.ds.un('load', this.onLoad, this);
2573 this.ds.un('datachanged', this.onDataChange, this);
2574 this.ds.un('add', this.onAdd, this);
2575 this.ds.un('remove', this.onRemove, this);
2576 this.ds.un('update', this.onUpdate, this);
2577 this.ds.un('clear', this.onClear, this);
2578 if(this.ds !== ds && this.ds.autoDestroy){
2586 datachanged: this.onDataChange,
2588 remove: this.onRemove,
2589 update: this.onUpdate,
2596 this.cm.un('configchange', this.onColConfigChange, this);
2597 this.cm.un('widthchange', this.onColWidthChange, this);
2598 this.cm.un('headerchange', this.onHeaderChange, this);
2599 this.cm.un('hiddenchange', this.onHiddenChange, this);
2600 this.cm.un('columnmoved', this.onColumnMove, this);
2603 delete this.lastViewWidth;
2606 configchange: this.onColConfigChange,
2607 widthchange: this.onColWidthChange,
2608 headerchange: this.onHeaderChange,
2609 hiddenchange: this.onHiddenChange,
2610 columnmoved: this.onColumnMove
2617 onDataChange : function(){
2619 this.updateHeaderSortState();
2620 this.syncFocusEl(0);
2624 onClear : function(){
2626 this.syncFocusEl(0);
2630 onUpdate : function(ds, record){
2631 this.refreshRow(record);
2635 onAdd : function(ds, records, index){
2637 this.insertRows(ds, index, index + (records.length-1));
2641 onRemove : function(ds, record, index, isUpdate){
2642 if(isUpdate !== true){
2643 this.fireEvent('beforerowremoved', this, index, record);
2645 this.removeRow(index);
2646 if(isUpdate !== true){
2647 this.processRows(index);
2648 this.applyEmptyText();
2649 this.fireEvent('rowremoved', this, index, record);
2654 onLoad : function(){
2655 this.scrollToTop.defer(Ext.isGecko ? 1 : 0, this);
2659 onColWidthChange : function(cm, col, width){
2660 this.updateColumnWidth(col, width);
2664 onHeaderChange : function(cm, col, text){
2665 this.updateHeaders();
2669 onHiddenChange : function(cm, col, hidden){
2670 this.updateColumnHidden(col, hidden);
2674 onColumnMove : function(cm, oldIndex, newIndex){
2675 this.indexMap = null;
2676 var s = this.getScrollState();
2678 this.restoreScroll(s);
2679 this.afterMove(newIndex);
2680 this.grid.fireEvent('columnmove', oldIndex, newIndex);
2684 onColConfigChange : function(){
2685 delete this.lastViewWidth;
2686 this.indexMap = null;
2690 /* -------------------- UI Events and Handlers ------------------------------ */
2692 initUI : function(grid){
2693 grid.on('headerclick', this.onHeaderClick, this);
2697 initEvents : function(){
2701 onHeaderClick : function(g, index){
2702 if(this.headersDisabled || !this.cm.isSortable(index)){
2705 g.stopEditing(true);
2706 g.store.sort(this.cm.getDataIndex(index));
2710 onRowOver : function(e, t){
2712 if((row = this.findRowIndex(t)) !== false){
2713 this.addRowClass(row, 'x-grid3-row-over');
2718 onRowOut : function(e, t){
2720 if((row = this.findRowIndex(t)) !== false && !e.within(this.getRow(row), true)){
2721 this.removeRowClass(row, 'x-grid3-row-over');
2726 handleWheel : function(e){
2727 e.stopPropagation();
2731 onRowSelect : function(row){
2732 this.addRowClass(row, this.selectedRowClass);
2736 onRowDeselect : function(row){
2737 this.removeRowClass(row, this.selectedRowClass);
2741 onCellSelect : function(row, col){
2742 var cell = this.getCell(row, col);
2744 this.fly(cell).addClass('x-grid3-cell-selected');
2749 onCellDeselect : function(row, col){
2750 var cell = this.getCell(row, col);
2752 this.fly(cell).removeClass('x-grid3-cell-selected');
2757 onColumnSplitterMoved : function(i, w){
2758 this.userResized = true;
2759 var cm = this.grid.colModel;
2760 cm.setColumnWidth(i, w, true);
2763 this.fitColumns(true, false, i);
2764 this.updateAllColumnWidths();
2766 this.updateColumnWidth(i, w);
2767 this.syncHeaderScroll();
2770 this.grid.fireEvent('columnresize', i, w);
2774 handleHdMenuClick : function(item){
2775 var index = this.hdCtxIndex,
2778 id = item.getItemId();
2781 ds.sort(cm.getDataIndex(index), 'ASC');
2784 ds.sort(cm.getDataIndex(index), 'DESC');
2787 index = cm.getIndexById(id.substr(4));
2789 if(item.checked && cm.getColumnsBy(this.isHideableColumn, this).length <= 1){
2790 this.onDenyColumnHide();
2793 cm.setHidden(index, item.checked);
2800 isHideableColumn : function(c){
2801 return !c.hidden && !c.fixed;
2805 beforeColMenuShow : function(){
2806 var cm = this.cm, colCount = cm.getColumnCount();
2807 this.colMenu.removeAll();
2808 for(var i = 0; i < colCount; i++){
2809 if(cm.config[i].fixed !== true && cm.config[i].hideable !== false){
2810 this.colMenu.add(new Ext.menu.CheckItem({
2811 itemId: 'col-'+cm.getColumnId(i),
2812 text: cm.getColumnHeader(i),
2813 checked: !cm.isHidden(i),
2815 disabled: cm.config[i].hideable === false
2822 handleHdDown : function(e, t){
2823 if(Ext.fly(t).hasClass('x-grid3-hd-btn')){
2825 var hd = this.findHeaderCell(t);
2826 Ext.fly(hd).addClass('x-grid3-hd-menu-open');
2827 var index = this.getCellIndex(hd);
2828 this.hdCtxIndex = index;
2829 var ms = this.hmenu.items, cm = this.cm;
2830 ms.get('asc').setDisabled(!cm.isSortable(index));
2831 ms.get('desc').setDisabled(!cm.isSortable(index));
2832 this.hmenu.on('hide', function(){
2833 Ext.fly(hd).removeClass('x-grid3-hd-menu-open');
2834 }, this, {single:true});
2835 this.hmenu.show(t, 'tl-bl?');
2840 handleHdOver : function(e, t){
2841 var hd = this.findHeaderCell(t);
2842 if(hd && !this.headersDisabled){
2843 this.activeHdRef = t;
2844 this.activeHdIndex = this.getCellIndex(hd);
2845 var fly = this.fly(hd);
2846 this.activeHdRegion = fly.getRegion();
2847 if(!this.cm.isMenuDisabled(this.activeHdIndex)){
2848 fly.addClass('x-grid3-hd-over');
2849 this.activeHdBtn = fly.child('.x-grid3-hd-btn');
2850 if(this.activeHdBtn){
2851 this.activeHdBtn.dom.style.height = (hd.firstChild.offsetHeight-1)+'px';
2858 handleHdMove : function(e, t){
2859 var hd = this.findHeaderCell(this.activeHdRef);
2860 if(hd && !this.headersDisabled){
2861 var hw = this.splitHandleWidth || 5,
2862 r = this.activeHdRegion,
2866 if(this.grid.enableColumnResize !== false){
2867 if(x - r.left <= hw && this.cm.isResizable(this.activeHdIndex-1)){
2868 cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'e-resize' : 'col-resize'; // col-resize not always supported
2869 }else if(r.right - x <= (!this.activeHdBtn ? hw : 2) && this.cm.isResizable(this.activeHdIndex)){
2870 cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'w-resize' : 'col-resize';
2878 handleHdOut : function(e, t){
2879 var hd = this.findHeaderCell(t);
2880 if(hd && (!Ext.isIE || !e.within(hd, true))){
2881 this.activeHdRef = null;
2882 this.fly(hd).removeClass('x-grid3-hd-over');
2883 hd.style.cursor = '';
2888 hasRows : function(){
2889 var fc = this.mainBody.dom.firstChild;
2890 return fc && fc.nodeType == 1 && fc.className != 'x-grid-empty';
2894 bind : function(d, c){
2895 this.initData(d, c);
2901 // This is a support class used internally by the Grid components
2902 Ext.grid.GridView.SplitDragZone = function(grid, hd){
2904 this.view = grid.getView();
2905 this.marker = this.view.resizeMarker;
2906 this.proxy = this.view.resizeProxy;
2907 Ext.grid.GridView.SplitDragZone.superclass.constructor.call(this, hd,
2908 'gridSplitters' + this.grid.getGridEl().id, {
2909 dragElId : Ext.id(this.proxy.dom), resizeFrame:false
2911 this.scroll = false;
2912 this.hw = this.view.splitHandleWidth || 5;
2914 Ext.extend(Ext.grid.GridView.SplitDragZone, Ext.dd.DDProxy, {
2916 b4StartDrag : function(x, y){
2917 this.view.headersDisabled = true;
2918 var h = this.view.mainWrap.getHeight();
2919 this.marker.setHeight(h);
2921 this.marker.alignTo(this.view.getHeaderCell(this.cellIndex), 'tl-tl', [-2, 0]);
2922 this.proxy.setHeight(h);
2923 var w = this.cm.getColumnWidth(this.cellIndex);
2924 var minw = Math.max(w-this.grid.minColumnWidth, 0);
2925 this.resetConstraints();
2926 this.setXConstraint(minw, 1000);
2927 this.setYConstraint(0, 0);
2928 this.minX = x - minw;
2929 this.maxX = x + 1000;
2931 Ext.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
2934 allowHeaderDrag : function(e){
2939 handleMouseDown : function(e){
2940 var t = this.view.findHeaderCell(e.getTarget());
2941 if(t && this.allowHeaderDrag(e)){
2942 var xy = this.view.fly(t).getXY(), x = xy[0], y = xy[1];
2943 var exy = e.getXY(), ex = exy[0];
2944 var w = t.offsetWidth, adjust = false;
2945 if((ex - x) <= this.hw){
2947 }else if((x+w) - ex <= this.hw){
2950 if(adjust !== false){
2951 this.cm = this.grid.colModel;
2952 var ci = this.view.getCellIndex(t);
2954 if (ci + adjust < 0) {
2957 while(this.cm.isHidden(ci+adjust)){
2964 this.cellIndex = ci+adjust;
2966 if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
2967 Ext.grid.GridView.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
2969 }else if(this.view.columnDrag){
2970 this.view.columnDrag.callHandleMouseDown(e);
2975 endDrag : function(e){
2978 var endX = Math.max(this.minX, e.getPageX());
2979 var diff = endX - this.startPos;
2980 v.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
2981 setTimeout(function(){
2982 v.headersDisabled = false;
2986 autoOffset : function(){
2991 // This is a support class used internally by the Grid components
\r
2992 Ext.grid.HeaderDragZone = Ext.extend(Ext.dd.DragZone, {
\r
2993 maxDragWidth: 120,
\r
2995 constructor : function(grid, hd, hd2){
\r
2997 this.view = grid.getView();
\r
2998 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
\r
2999 Ext.grid.HeaderDragZone.superclass.constructor.call(this, hd);
\r
3001 this.setHandleElId(Ext.id(hd));
\r
3002 this.setOuterHandleElId(Ext.id(hd2));
\r
3004 this.scroll = false;
\r
3007 getDragData : function(e){
\r
3008 var t = Ext.lib.Event.getTarget(e);
\r
3009 var h = this.view.findHeaderCell(t);
\r
3011 return {ddel: h.firstChild, header:h};
\r
3016 onInitDrag : function(e){
\r
3017 this.view.headersDisabled = true;
\r
3018 var clone = this.dragData.ddel.cloneNode(true);
\r
3019 clone.id = Ext.id();
\r
3020 clone.style.width = Math.min(this.dragData.header.offsetWidth,this.maxDragWidth) + "px";
\r
3021 this.proxy.update(clone);
\r
3025 afterValidDrop : function(){
\r
3026 var v = this.view;
\r
3027 setTimeout(function(){
\r
3028 v.headersDisabled = false;
\r
3032 afterInvalidDrop : function(){
\r
3033 var v = this.view;
\r
3034 setTimeout(function(){
\r
3035 v.headersDisabled = false;
\r
3041 // This is a support class used internally by the Grid components
\r
3042 Ext.grid.HeaderDropZone = Ext.extend(Ext.dd.DropZone, {
\r
3043 proxyOffsets : [-4, -9],
\r
3044 fly: Ext.Element.fly,
\r
3046 constructor : function(grid, hd, hd2){
\r
3048 this.view = grid.getView();
\r
3049 // split the proxies so they don't interfere with mouse events
\r
3050 this.proxyTop = Ext.DomHelper.append(document.body, {
\r
3051 cls:"col-move-top", html:" "
\r
3053 this.proxyBottom = Ext.DomHelper.append(document.body, {
\r
3054 cls:"col-move-bottom", html:" "
\r
3056 this.proxyTop.hide = this.proxyBottom.hide = function(){
\r
3057 this.setLeftTop(-100,-100);
\r
3058 this.setStyle("visibility", "hidden");
\r
3060 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
\r
3061 // temporarily disabled
\r
3062 //Ext.dd.ScrollManager.register(this.view.scroller.dom);
\r
3063 Ext.grid.HeaderDropZone.superclass.constructor.call(this, grid.getGridEl().dom);
\r
3066 getTargetFromEvent : function(e){
\r
3067 var t = Ext.lib.Event.getTarget(e);
\r
3068 var cindex = this.view.findCellIndex(t);
\r
3069 if(cindex !== false){
\r
3070 return this.view.getHeaderCell(cindex);
\r
3074 nextVisible : function(h){
\r
3075 var v = this.view, cm = this.grid.colModel;
\r
3076 h = h.nextSibling;
\r
3078 if(!cm.isHidden(v.getCellIndex(h))){
\r
3081 h = h.nextSibling;
\r
3086 prevVisible : function(h){
\r
3087 var v = this.view, cm = this.grid.colModel;
\r
3088 h = h.prevSibling;
\r
3090 if(!cm.isHidden(v.getCellIndex(h))){
\r
3093 h = h.prevSibling;
\r
3098 positionIndicator : function(h, n, e){
\r
3099 var x = Ext.lib.Event.getPageX(e);
\r
3100 var r = Ext.lib.Dom.getRegion(n.firstChild);
\r
3101 var px, pt, py = r.top + this.proxyOffsets[1];
\r
3102 if((r.right - x) <= (r.right-r.left)/2){
\r
3103 px = r.right+this.view.borderWidth;
\r
3110 if(this.grid.colModel.isFixed(this.view.getCellIndex(n))){
\r
3114 px += this.proxyOffsets[0];
\r
3115 this.proxyTop.setLeftTop(px, py);
\r
3116 this.proxyTop.show();
\r
3117 if(!this.bottomOffset){
\r
3118 this.bottomOffset = this.view.mainHd.getHeight();
\r
3120 this.proxyBottom.setLeftTop(px, py+this.proxyTop.dom.offsetHeight+this.bottomOffset);
\r
3121 this.proxyBottom.show();
\r
3125 onNodeEnter : function(n, dd, e, data){
\r
3126 if(data.header != n){
\r
3127 this.positionIndicator(data.header, n, e);
\r
3131 onNodeOver : function(n, dd, e, data){
\r
3132 var result = false;
\r
3133 if(data.header != n){
\r
3134 result = this.positionIndicator(data.header, n, e);
\r
3137 this.proxyTop.hide();
\r
3138 this.proxyBottom.hide();
\r
3140 return result ? this.dropAllowed : this.dropNotAllowed;
\r
3143 onNodeOut : function(n, dd, e, data){
\r
3144 this.proxyTop.hide();
\r
3145 this.proxyBottom.hide();
\r
3148 onNodeDrop : function(n, dd, e, data){
\r
3149 var h = data.header;
\r
3151 var cm = this.grid.colModel;
\r
3152 var x = Ext.lib.Event.getPageX(e);
\r
3153 var r = Ext.lib.Dom.getRegion(n.firstChild);
\r
3154 var pt = (r.right - x) <= ((r.right-r.left)/2) ? "after" : "before";
\r
3155 var oldIndex = this.view.getCellIndex(h);
\r
3156 var newIndex = this.view.getCellIndex(n);
\r
3157 if(pt == "after"){
\r
3160 if(oldIndex < newIndex){
\r
3163 cm.moveColumn(oldIndex, newIndex);
\r
3170 Ext.grid.GridView.ColumnDragZone = Ext.extend(Ext.grid.HeaderDragZone, {
\r
3172 constructor : function(grid, hd){
\r
3173 Ext.grid.GridView.ColumnDragZone.superclass.constructor.call(this, grid, hd, null);
\r
3174 this.proxy.el.addClass('x-grid3-col-dd');
\r
3177 handleMouseDown : function(e){
\r
3180 callHandleMouseDown : function(e){
\r
3181 Ext.grid.GridView.ColumnDragZone.superclass.handleMouseDown.call(this, e);
\r
3184 // This is a support class used internally by the Grid components
3185 Ext.grid.SplitDragZone = Ext.extend(Ext.dd.DDProxy, {
3186 fly: Ext.Element.fly,
3188 constructor : function(grid, hd, hd2){
3190 this.view = grid.getView();
3191 this.proxy = this.view.resizeProxy;
3192 Ext.grid.SplitDragZone.superclass.constructor.call(this, hd,
3193 "gridSplitters" + this.grid.getGridEl().id, {
3194 dragElId : Ext.id(this.proxy.dom), resizeFrame:false
3196 this.setHandleElId(Ext.id(hd));
3197 this.setOuterHandleElId(Ext.id(hd2));
3198 this.scroll = false;
3201 b4StartDrag : function(x, y){
3202 this.view.headersDisabled = true;
3203 this.proxy.setHeight(this.view.mainWrap.getHeight());
3204 var w = this.cm.getColumnWidth(this.cellIndex);
3205 var minw = Math.max(w-this.grid.minColumnWidth, 0);
3206 this.resetConstraints();
3207 this.setXConstraint(minw, 1000);
3208 this.setYConstraint(0, 0);
3209 this.minX = x - minw;
3210 this.maxX = x + 1000;
3212 Ext.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
3216 handleMouseDown : function(e){
3217 var ev = Ext.EventObject.setEvent(e);
3218 var t = this.fly(ev.getTarget());
3219 if(t.hasClass("x-grid-split")){
3220 this.cellIndex = this.view.getCellIndex(t.dom);
3222 this.cm = this.grid.colModel;
3223 if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
3224 Ext.grid.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
3229 endDrag : function(e){
3230 this.view.headersDisabled = false;
3231 var endX = Math.max(this.minX, Ext.lib.Event.getPageX(e));
3232 var diff = endX - this.startPos;
3233 this.view.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
3236 autoOffset : function(){
3240 * @class Ext.grid.GridDragZone
3241 * @extends Ext.dd.DragZone
3242 * <p>A customized implementation of a {@link Ext.dd.DragZone DragZone} which provides default implementations of two of the
3243 * template methods of DragZone to enable dragging of the selected rows of a GridPanel.</p>
3244 * <p>A cooperating {@link Ext.dd.DropZone DropZone} must be created who's template method implementations of
3245 * {@link Ext.dd.DropZone#onNodeEnter onNodeEnter}, {@link Ext.dd.DropZone#onNodeOver onNodeOver},
3246 * {@link Ext.dd.DropZone#onNodeOut onNodeOut} and {@link Ext.dd.DropZone#onNodeDrop onNodeDrop}</p> are able
3247 * to process the {@link #getDragData data} which is provided.
3249 Ext.grid.GridDragZone = function(grid, config){
3250 this.view = grid.getView();
3251 Ext.grid.GridDragZone.superclass.constructor.call(this, this.view.mainBody.dom, config);
3252 this.scroll = false;
3254 this.ddel = document.createElement('div');
3255 this.ddel.className = 'x-grid-dd-wrap';
3258 Ext.extend(Ext.grid.GridDragZone, Ext.dd.DragZone, {
3262 * <p>The provided implementation of the getDragData method which collects the data to be dragged from the GridPanel on mousedown.</p>
3263 * <p>This data is available for processing in the {@link Ext.dd.DropZone#onNodeEnter onNodeEnter}, {@link Ext.dd.DropZone#onNodeOver onNodeOver},
3264 * {@link Ext.dd.DropZone#onNodeOut onNodeOut} and {@link Ext.dd.DropZone#onNodeDrop onNodeDrop} methods of a cooperating {@link Ext.dd.DropZone DropZone}.</p>
3265 * <p>The data object contains the following properties:<ul>
3266 * <li><b>grid</b> : Ext.Grid.GridPanel<div class="sub-desc">The GridPanel from which the data is being dragged.</div></li>
3267 * <li><b>ddel</b> : htmlElement<div class="sub-desc">An htmlElement which provides the "picture" of the data being dragged.</div></li>
3268 * <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>
3269 * <li><b>selections</b> : Array<div class="sub-desc">An Array of the selected Records which are being dragged from the GridPanel.</div></li>
3272 getDragData : function(e){
3273 var t = Ext.lib.Event.getTarget(e);
3274 var rowIndex = this.view.findRowIndex(t);
3275 if(rowIndex !== false){
3276 var sm = this.grid.selModel;
3277 if(!sm.isSelected(rowIndex) || e.hasModifier()){
3278 sm.handleMouseDown(this.grid, rowIndex, e);
3280 return {grid: this.grid, ddel: this.ddel, rowIndex: rowIndex, selections:sm.getSelections()};
3286 * <p>The provided implementation of the onInitDrag method. Sets the <tt>innerHTML</tt> of the drag proxy which provides the "picture"
3287 * of the data being dragged.</p>
3288 * <p>The <tt>innerHTML</tt> data is found by calling the owning GridPanel's {@link Ext.grid.GridPanel#getDragDropText getDragDropText}.</p>
3290 onInitDrag : function(e){
3291 var data = this.dragData;
3292 this.ddel.innerHTML = this.grid.getDragDropText();
3293 this.proxy.update(this.ddel);
3298 * An empty immplementation. Implement this to provide behaviour after a repair of an invalid drop. An implementation might highlight
3299 * the selected rows to show that they have not been dragged.
3301 afterRepair : function(){
3302 this.dragging = false;
3306 * <p>An empty implementation. Implement this to provide coordinates for the drag proxy to slide back to after an invalid drop.</p>
3307 * <p>Called before a repair of an invalid drop to get the XY to animate to.</p>
3308 * @param {EventObject} e The mouse up event
3309 * @return {Array} The xy location (e.g. [100, 200])
3311 getRepairXY : function(e, data){
3315 onEndDrag : function(data, e){
3319 onValidDrop : function(dd, e, id){
3324 beforeInvalidDrop : function(e, id){
3329 * @class Ext.grid.ColumnModel
3330 * @extends Ext.util.Observable
3331 * <p>After the data has been read into the client side cache (<b>{@link Ext.data.Store Store}</b>),
3332 * the ColumnModel is used to configure how and what parts of that data will be displayed in the
3333 * vertical slices (columns) of the grid. The Ext.grid.ColumnModel Class is the default implementation
3334 * of a ColumnModel used by implentations of {@link Ext.grid.GridPanel GridPanel}.</p>
3335 * <p>Data is mapped into the store's records and then indexed into the ColumnModel using the
3336 * <tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt>:</p>
3338 {data source} == mapping ==> {data store} == <b><tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt></b> ==> {ColumnModel}
3340 * <p>Each {@link Ext.grid.Column Column} in the grid's ColumnModel is configured with a
3341 * <tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt> to specify how the data within
3342 * each record in the store is indexed into the ColumnModel.</p>
3343 * <p>There are two ways to initialize the ColumnModel class:</p>
3344 * <p><u>Initialization Method 1: an Array</u></p>
3346 var colModel = new Ext.grid.ColumnModel([
3347 { header: "Ticker", width: 60, sortable: true},
3348 { header: "Company Name", width: 150, sortable: true, id: 'company'},
3349 { header: "Market Cap.", width: 100, sortable: true},
3350 { header: "$ Sales", width: 100, sortable: true, renderer: money},
3351 { header: "Employees", width: 100, sortable: true, resizable: false}
3354 * <p>The ColumnModel may be initialized with an Array of {@link Ext.grid.Column} column configuration
3355 * objects to define the initial layout / display of the columns in the Grid. The order of each
3356 * {@link Ext.grid.Column} column configuration object within the specified Array defines the initial
3357 * order of the column display. A Column's display may be initially hidden using the
3358 * <tt>{@link Ext.grid.Column#hidden hidden}</tt></b> config property (and then shown using the column
3359 * header menu). Fields that are not included in the ColumnModel will not be displayable at all.</p>
3360 * <p>How each column in the grid correlates (maps) to the {@link Ext.data.Record} field in the
3361 * {@link Ext.data.Store Store} the column draws its data from is configured through the
3362 * <b><tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt></b>. If the
3363 * <b><tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt></b> is not explicitly defined (as shown in the
3364 * example above) it will use the column configuration's index in the Array as the index.</p>
3365 * <p>See <b><tt>{@link Ext.grid.Column}</tt></b> for additional configuration options for each column.</p>
3366 * <p><u>Initialization Method 2: an Object</u></p>
3367 * <p>In order to use configuration options from <tt>Ext.grid.ColumnModel</tt>, an Object may be used to
3368 * initialize the ColumnModel. The column configuration Array will be specified in the <tt><b>{@link #columns}</b></tt>
3369 * config property. The <tt><b>{@link #defaults}</b></tt> config property can be used to apply defaults
3370 * for all columns, e.g.:</p><pre><code>
3371 var colModel = new Ext.grid.ColumnModel({
3373 { header: "Ticker", width: 60, menuDisabled: false},
3374 { header: "Company Name", width: 150, id: 'company'},
3375 { header: "Market Cap."},
3376 { header: "$ Sales", renderer: money},
3377 { header: "Employees", resizable: false}
3385 {@link #hiddenchange}: function(cm, colIndex, hidden) {
3386 saveConfig(colIndex, hidden);
3391 * <p>In both examples above, the ability to apply a CSS class to all cells in a column (including the
3392 * header) is demonstrated through the use of the <b><tt>{@link Ext.grid.Column#id id}</tt></b> config
3393 * option. This column could be styled by including the following css:</p><pre><code>
3394 //add this css *after* the core css is loaded
3395 .x-grid3-td-company {
3396 color: red; // entire column will have red font
3398 // modify the header row only, adding an icon to the column header
3399 .x-grid3-hd-company {
3400 background: transparent
3401 url(../../resources/images/icons/silk/building.png)
3402 no-repeat 3px 3px ! important;
3406 * Note that the "Company Name" column could be specified as the
3407 * <b><tt>{@link Ext.grid.GridPanel}.{@link Ext.grid.GridPanel#autoExpandColumn autoExpandColumn}</tt></b>.
3409 * @param {Mixed} config Specify either an Array of {@link Ext.grid.Column} configuration objects or specify
3410 * a configuration Object (see introductory section discussion utilizing Initialization Method 2 above).
3412 Ext.grid.ColumnModel = Ext.extend(Ext.util.Observable, {
3414 * @cfg {Number} defaultWidth (optional) The width of columns which have no <tt>{@link #width}</tt>
3415 * specified (defaults to <tt>100</tt>). This property shall preferably be configured through the
3416 * <tt><b>{@link #defaults}</b></tt> config property.
3420 * @cfg {Boolean} defaultSortable (optional) Default sortable of columns which have no
3421 * sortable specified (defaults to <tt>false</tt>). This property shall preferably be configured
3422 * through the <tt><b>{@link #defaults}</b></tt> config property.
3424 defaultSortable: false,
3426 * @cfg {Array} columns An Array of object literals. The config options defined by
3427 * <b>{@link Ext.grid.Column}</b> are the options which may appear in the object literal for each
3428 * individual column definition.
3431 * @cfg {Object} defaults Object literal which will be used to apply {@link Ext.grid.Column}
3432 * configuration options to all <tt><b>{@link #columns}</b></tt>. Configuration options specified with
3433 * individual {@link Ext.grid.Column column} configs will supersede these <tt><b>{@link #defaults}</b></tt>.
3436 constructor : function(config){
3438 * An Array of {@link Ext.grid.Column Column definition} objects representing the configuration
3439 * of this ColumnModel. See {@link Ext.grid.Column} for the configuration properties that may
3445 Ext.apply(this, config);
3446 this.setConfig(config.columns, true);
3448 this.setConfig(config, true);
3452 * @event widthchange
3453 * Fires when the width of a column is programmaticially changed using
3454 * <code>{@link #setColumnWidth}</code>.
3455 * Note internal resizing suppresses the event from firing. See also
3456 * {@link Ext.grid.GridPanel}.<code>{@link #columnresize}</code>.
3457 * @param {ColumnModel} this
3458 * @param {Number} columnIndex The column index
3459 * @param {Number} newWidth The new width
3463 * @event headerchange
3464 * Fires when the text of a header changes.
3465 * @param {ColumnModel} this
3466 * @param {Number} columnIndex The column index
3467 * @param {String} newText The new header text
3471 * @event hiddenchange
3472 * Fires when a column is hidden or "unhidden".
3473 * @param {ColumnModel} this
3474 * @param {Number} columnIndex The column index
3475 * @param {Boolean} hidden true if hidden, false otherwise
3479 * @event columnmoved
3480 * Fires when a column is moved.
3481 * @param {ColumnModel} this
3482 * @param {Number} oldIndex
3483 * @param {Number} newIndex
3487 * @event configchange
3488 * Fires when the configuration is changed
3489 * @param {ColumnModel} this
3493 Ext.grid.ColumnModel.superclass.constructor.call(this);
3497 * Returns the id of the column at the specified index.
3498 * @param {Number} index The column index
3499 * @return {String} the id
3501 getColumnId : function(index){
3502 return this.config[index].id;
3505 getColumnAt : function(index){
3506 return this.config[index];
3510 * <p>Reconfigures this column model according to the passed Array of column definition objects.
3511 * For a description of the individual properties of a column definition object, see the
3512 * <a href="#Ext.grid.ColumnModel-configs">Config Options</a>.</p>
3513 * <p>Causes the {@link #configchange} event to be fired. A {@link Ext.grid.GridPanel GridPanel}
3514 * using this ColumnModel will listen for this event and refresh its UI automatically.</p>
3515 * @param {Array} config Array of Column definition objects.
3516 * @param {Boolean} initial Specify <tt>true</tt> to bypass cleanup which deletes the <tt>totalWidth</tt>
3517 * and destroys existing editors.
3519 setConfig : function(config, initial){
3521 if(!initial){ // cleanup
3522 delete this.totalWidth;
3523 for(i = 0, len = this.config.length; i < len; i++){
3524 this.config[i].destroy();
3528 // backward compatibility
3529 this.defaults = Ext.apply({
3530 width: this.defaultWidth,
3531 sortable: this.defaultSortable
3534 this.config = config;
3537 for(i = 0, len = config.length; i < len; i++){
3538 c = Ext.applyIf(config[i], this.defaults);
3539 // if no id, create one using column's ordinal position
3540 if(Ext.isEmpty(c.id)){
3544 var Cls = Ext.grid.Column.types[c.xtype || 'gridcolumn'];
3548 this.lookup[c.id] = c;
3551 this.fireEvent('configchange', this);
3556 * Returns the column for a specified id.
3557 * @param {String} id The column id
3558 * @return {Object} the column
3560 getColumnById : function(id){
3561 return this.lookup[id];
3565 * Returns the index for a specified column id.
3566 * @param {String} id The column id
3567 * @return {Number} the index, or -1 if not found
3569 getIndexById : function(id){
3570 for(var i = 0, len = this.config.length; i < len; i++){
3571 if(this.config[i].id == id){
3579 * Moves a column from one position to another.
3580 * @param {Number} oldIndex The index of the column to move.
3581 * @param {Number} newIndex The position at which to reinsert the coolumn.
3583 moveColumn : function(oldIndex, newIndex){
3584 var c = this.config[oldIndex];
3585 this.config.splice(oldIndex, 1);
3586 this.config.splice(newIndex, 0, c);
3587 this.dataMap = null;
3588 this.fireEvent("columnmoved", this, oldIndex, newIndex);
3592 * Returns the number of columns.
3593 * @param {Boolean} visibleOnly Optional. Pass as true to only include visible columns.
3596 getColumnCount : function(visibleOnly){
3597 if(visibleOnly === true){
3599 for(var i = 0, len = this.config.length; i < len; i++){
3600 if(!this.isHidden(i)){
3606 return this.config.length;
3610 * Returns the column configs that return true by the passed function that is called
3611 * with (columnConfig, index)
3613 // returns an array of column config objects for all hidden columns
3614 var columns = grid.getColumnModel().getColumnsBy(function(c){
3618 * @param {Function} fn A function which, when passed a {@link Ext.grid.Column Column} object, must
3619 * return <code>true</code> if the column is to be included in the returned Array.
3620 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function
3621 * is executed. Defaults to this ColumnModel.
3622 * @return {Array} result
3624 getColumnsBy : function(fn, scope){
3626 for(var i = 0, len = this.config.length; i < len; i++){
3627 var c = this.config[i];
3628 if(fn.call(scope||this, c, i) === true){
3636 * Returns true if the specified column is sortable.
3637 * @param {Number} col The column index
3640 isSortable : function(col){
3641 return !!this.config[col].sortable;
3645 * Returns true if the specified column menu is disabled.
3646 * @param {Number} col The column index
3649 isMenuDisabled : function(col){
3650 return !!this.config[col].menuDisabled;
3654 * Returns the rendering (formatting) function defined for the column.
3655 * @param {Number} col The column index.
3656 * @return {Function} The function used to render the cell. See {@link #setRenderer}.
3658 getRenderer : function(col){
3659 if(!this.config[col].renderer){
3660 return Ext.grid.ColumnModel.defaultRenderer;
3662 return this.config[col].renderer;
3665 getRendererScope : function(col){
3666 return this.config[col].scope;
3670 * Sets the rendering (formatting) function for a column. See {@link Ext.util.Format} for some
3671 * default formatting functions.
3672 * @param {Number} col The column index
3673 * @param {Function} fn The function to use to process the cell's raw data
3674 * to return HTML markup for the grid view. The render function is called with
3675 * the following parameters:<ul>
3676 * <li><b>value</b> : Object<p class="sub-desc">The data value for the cell.</p></li>
3677 * <li><b>metadata</b> : Object<p class="sub-desc">An object in which you may set the following attributes:<ul>
3678 * <li><b>css</b> : String<p class="sub-desc">A CSS class name to add to the cell's TD element.</p></li>
3679 * <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
3680 * (e.g. 'style="color:red;"').</p></li></ul></p></li>
3681 * <li><b>record</b> : Ext.data.record<p class="sub-desc">The {@link Ext.data.Record} from which the data was extracted.</p></li>
3682 * <li><b>rowIndex</b> : Number<p class="sub-desc">Row index</p></li>
3683 * <li><b>colIndex</b> : Number<p class="sub-desc">Column index</p></li>
3684 * <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>
3686 setRenderer : function(col, fn){
3687 this.config[col].renderer = fn;
3691 * Returns the width for the specified column.
3692 * @param {Number} col The column index
3695 getColumnWidth : function(col){
3696 return this.config[col].width;
3700 * Sets the width for a column.
3701 * @param {Number} col The column index
3702 * @param {Number} width The new width
3703 * @param {Boolean} suppressEvent True to suppress firing the <code>{@link #widthchange}</code>
3704 * event. Defaults to false.
3706 setColumnWidth : function(col, width, suppressEvent){
3707 this.config[col].width = width;
3708 this.totalWidth = null;
3710 this.fireEvent("widthchange", this, col, width);
3715 * Returns the total width of all columns.
3716 * @param {Boolean} includeHidden True to include hidden column widths
3719 getTotalWidth : function(includeHidden){
3720 if(!this.totalWidth){
3721 this.totalWidth = 0;
3722 for(var i = 0, len = this.config.length; i < len; i++){
3723 if(includeHidden || !this.isHidden(i)){
3724 this.totalWidth += this.getColumnWidth(i);
3728 return this.totalWidth;
3732 * Returns the header for the specified column.
3733 * @param {Number} col The column index
3736 getColumnHeader : function(col){
3737 return this.config[col].header;
3741 * Sets the header for a column.
3742 * @param {Number} col The column index
3743 * @param {String} header The new header
3745 setColumnHeader : function(col, header){
3746 this.config[col].header = header;
3747 this.fireEvent("headerchange", this, col, header);
3751 * Returns the tooltip for the specified column.
3752 * @param {Number} col The column index
3755 getColumnTooltip : function(col){
3756 return this.config[col].tooltip;
3759 * Sets the tooltip for a column.
3760 * @param {Number} col The column index
3761 * @param {String} tooltip The new tooltip
3763 setColumnTooltip : function(col, tooltip){
3764 this.config[col].tooltip = tooltip;
3768 * Returns the dataIndex for the specified column.
3770 // Get field name for the column
3771 var fieldName = grid.getColumnModel().getDataIndex(columnIndex);
3773 * @param {Number} col The column index
3774 * @return {String} The column's dataIndex
3776 getDataIndex : function(col){
3777 return this.config[col].dataIndex;
3781 * Sets the dataIndex for a column.
3782 * @param {Number} col The column index
3783 * @param {String} dataIndex The new dataIndex
3785 setDataIndex : function(col, dataIndex){
3786 this.config[col].dataIndex = dataIndex;
3790 * Finds the index of the first matching column for the given dataIndex.
3791 * @param {String} col The dataIndex to find
3792 * @return {Number} The column index, or -1 if no match was found
3794 findColumnIndex : function(dataIndex){
3795 var c = this.config;
3796 for(var i = 0, len = c.length; i < len; i++){
3797 if(c[i].dataIndex == dataIndex){
3805 * Returns true if the cell is editable.
3807 var store = new Ext.data.Store({...});
3808 var colModel = new Ext.grid.ColumnModel({
3810 isCellEditable: function(col, row) {
3811 var record = store.getAt(row);
3812 if (record.get('readonly')) { // replace with your condition
3815 return Ext.grid.ColumnModel.prototype.isCellEditable.call(this, col, row);
3818 var grid = new Ext.grid.GridPanel({
3824 * @param {Number} colIndex The column index
3825 * @param {Number} rowIndex The row index
3828 isCellEditable : function(colIndex, rowIndex){
3829 var c = this.config[colIndex],
3833 return !!(ed || (!Ext.isDefined(ed) && c.editor));
3837 * Returns the editor defined for the cell/column.
3838 * @param {Number} colIndex The column index
3839 * @param {Number} rowIndex The row index
3840 * @return {Ext.Editor} The {@link Ext.Editor Editor} that was created to wrap
3841 * the {@link Ext.form.Field Field} used to edit the cell.
3843 getCellEditor : function(colIndex, rowIndex){
3844 return this.config[colIndex].getCellEditor(rowIndex);
3848 * Sets if a column is editable.
3849 * @param {Number} col The column index
3850 * @param {Boolean} editable True if the column is editable
3852 setEditable : function(col, editable){
3853 this.config[col].editable = editable;
3857 * Returns <tt>true</tt> if the column is <code>{@link Ext.grid.Column#hidden hidden}</code>,
3858 * <tt>false</tt> otherwise.
3859 * @param {Number} colIndex The column index
3862 isHidden : function(colIndex){
3863 return !!this.config[colIndex].hidden; // ensure returns boolean
3867 * Returns <tt>true</tt> if the column is <code>{@link Ext.grid.Column#fixed fixed}</code>,
3868 * <tt>false</tt> otherwise.
3869 * @param {Number} colIndex The column index
3872 isFixed : function(colIndex){
3873 return !!this.config[colIndex].fixed;
3877 * Returns true if the column can be resized
3880 isResizable : function(colIndex){
3881 return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
3884 * Sets if a column is hidden.
3886 myGrid.getColumnModel().setHidden(0, true); // hide column 0 (0 = the first column).
3888 * @param {Number} colIndex The column index
3889 * @param {Boolean} hidden True if the column is hidden
3891 setHidden : function(colIndex, hidden){
3892 var c = this.config[colIndex];
3893 if(c.hidden !== hidden){
3895 this.totalWidth = null;
3896 this.fireEvent("hiddenchange", this, colIndex, hidden);
3901 * Sets the editor for a column and destroys the prior editor.
3902 * @param {Number} col The column index
3903 * @param {Object} editor The editor object
3905 setEditor : function(col, editor){
3906 this.config[col].setEditor(editor);
3910 * Destroys this column model by purging any event listeners, and removing any editors.
3912 destroy : function(){
3913 for(var i = 0, len = this.config.length; i < len; i++){
3914 this.config[i].destroy();
3916 this.purgeListeners();
3921 Ext.grid.ColumnModel.defaultRenderer = function(value){
3922 if(typeof value == "string" && value.length < 1){
3927 * @class Ext.grid.AbstractSelectionModel
\r
3928 * @extends Ext.util.Observable
\r
3929 * Abstract base class for grid SelectionModels. It provides the interface that should be
\r
3930 * implemented by descendant classes. This class should not be directly instantiated.
\r
3933 Ext.grid.AbstractSelectionModel = Ext.extend(Ext.util.Observable, {
\r
3935 * The GridPanel for which this SelectionModel is handling selection. Read-only.
\r
3940 constructor : function(){
\r
3941 this.locked = false;
\r
3942 Ext.grid.AbstractSelectionModel.superclass.constructor.call(this);
\r
3945 /** @ignore Called by the grid automatically. Do not call directly. */
\r
3946 init : function(grid){
\r
3948 this.initEvents();
\r
3952 * Locks the selections.
\r
3954 lock : function(){
\r
3955 this.locked = true;
\r
3959 * Unlocks the selections.
\r
3961 unlock : function(){
\r
3962 this.locked = false;
\r
3966 * Returns true if the selections are locked.
\r
3967 * @return {Boolean}
\r
3969 isLocked : function(){
\r
3970 return this.locked;
\r
3973 destroy: function(){
\r
3974 this.purgeListeners();
\r
3977 * @class Ext.grid.RowSelectionModel
3978 * @extends Ext.grid.AbstractSelectionModel
3979 * The default SelectionModel used by {@link Ext.grid.GridPanel}.
3980 * It supports multiple selections and keyboard selection/navigation. The objects stored
3981 * as selections and returned by {@link #getSelected}, and {@link #getSelections} are
3982 * the {@link Ext.data.Record Record}s which provide the data for the selected rows.
3984 * @param {Object} config
3986 Ext.grid.RowSelectionModel = Ext.extend(Ext.grid.AbstractSelectionModel, {
3988 * @cfg {Boolean} singleSelect
3989 * <tt>true</tt> to allow selection of only one row at a time (defaults to <tt>false</tt>
3990 * allowing multiple selections)
3992 singleSelect : false,
3994 constructor : function(config){
3995 Ext.apply(this, config);
3996 this.selections = new Ext.util.MixedCollection(false, function(o){
4001 this.lastActive = false;
4005 * @event selectionchange
4006 * Fires when the selection changes
4007 * @param {SelectionModel} this
4011 * @event beforerowselect
4012 * Fires before a row is selected, return false to cancel the selection.
4013 * @param {SelectionModel} this
4014 * @param {Number} rowIndex The index to be selected
4015 * @param {Boolean} keepExisting False if other selections will be cleared
4016 * @param {Record} record The record to be selected
4021 * Fires when a row is selected.
4022 * @param {SelectionModel} this
4023 * @param {Number} rowIndex The selected index
4024 * @param {Ext.data.Record} r The selected record
4028 * @event rowdeselect
4029 * Fires when a row is deselected. To prevent deselection
4030 * {@link Ext.grid.AbstractSelectionModel#lock lock the selections}.
4031 * @param {SelectionModel} this
4032 * @param {Number} rowIndex
4033 * @param {Record} record
4037 Ext.grid.RowSelectionModel.superclass.constructor.call(this);
4041 * @cfg {Boolean} moveEditorOnEnter
4042 * <tt>false</tt> to turn off moving the editor to the next row down when the enter key is pressed
4043 * or the next row up when shift + enter keys are pressed.
4046 initEvents : function(){
4048 if(!this.grid.enableDragDrop && !this.grid.enableDrag){
4049 this.grid.on('rowmousedown', this.handleMouseDown, this);
4052 this.rowNav = new Ext.KeyNav(this.grid.getGridEl(), {
4054 if(!e.shiftKey || this.singleSelect){
4055 this.selectPrevious(false);
4056 }else if(this.last !== false && this.lastActive !== false){
4057 var last = this.last;
4058 this.selectRange(this.last, this.lastActive-1);
4059 this.grid.getView().focusRow(this.lastActive);
4064 this.selectFirstRow();
4067 'down' : function(e){
4068 if(!e.shiftKey || this.singleSelect){
4069 this.selectNext(false);
4070 }else if(this.last !== false && this.lastActive !== false){
4071 var last = this.last;
4072 this.selectRange(this.last, this.lastActive+1);
4073 this.grid.getView().focusRow(this.lastActive);
4078 this.selectFirstRow();
4084 this.grid.getView().on({
4086 refresh: this.onRefresh,
4087 rowupdated: this.onRowUpdated,
4088 rowremoved: this.onRemove
4093 onRefresh : function(){
4094 var ds = this.grid.store, index;
4095 var s = this.getSelections();
4096 this.clearSelections(true);
4097 for(var i = 0, len = s.length; i < len; i++){
4099 if((index = ds.indexOfId(r.id)) != -1){
4100 this.selectRow(index, true);
4103 if(s.length != this.selections.getCount()){
4104 this.fireEvent('selectionchange', this);
4109 onRemove : function(v, index, r){
4110 if(this.selections.remove(r) !== false){
4111 this.fireEvent('selectionchange', this);
4116 onRowUpdated : function(v, index, r){
4117 if(this.isSelected(r)){
4118 v.onRowSelect(index);
4124 * @param {Array} records The records to select
4125 * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
4127 selectRecords : function(records, keepExisting){
4129 this.clearSelections();
4131 var ds = this.grid.store;
4132 for(var i = 0, len = records.length; i < len; i++){
4133 this.selectRow(ds.indexOf(records[i]), true);
4138 * Gets the number of selected rows.
4141 getCount : function(){
4142 return this.selections.length;
4146 * Selects the first row in the grid.
4148 selectFirstRow : function(){
4153 * Select the last row.
4154 * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
4156 selectLastRow : function(keepExisting){
4157 this.selectRow(this.grid.store.getCount() - 1, keepExisting);
4161 * Selects the row immediately following the last selected row.
4162 * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
4163 * @return {Boolean} <tt>true</tt> if there is a next row, else <tt>false</tt>
4165 selectNext : function(keepExisting){
4167 this.selectRow(this.last+1, keepExisting);
4168 this.grid.getView().focusRow(this.last);
4175 * Selects the row that precedes the last selected row.
4176 * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
4177 * @return {Boolean} <tt>true</tt> if there is a previous row, else <tt>false</tt>
4179 selectPrevious : function(keepExisting){
4180 if(this.hasPrevious()){
4181 this.selectRow(this.last-1, keepExisting);
4182 this.grid.getView().focusRow(this.last);
4189 * Returns true if there is a next record to select
4192 hasNext : function(){
4193 return this.last !== false && (this.last+1) < this.grid.store.getCount();
4197 * Returns true if there is a previous record to select
4200 hasPrevious : function(){
4206 * Returns the selected records
4207 * @return {Array} Array of selected records
4209 getSelections : function(){
4210 return [].concat(this.selections.items);
4214 * Returns the first selected record.
4217 getSelected : function(){
4218 return this.selections.itemAt(0);
4222 * Calls the passed function with each selection. If the function returns
4223 * <tt>false</tt>, iteration is stopped and this function returns
4224 * <tt>false</tt>. Otherwise it returns <tt>true</tt>.
4225 * @param {Function} fn The function to call upon each iteration. It is passed the selected {@link Ext.data.Record Record}.
4226 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this RowSelectionModel.
4227 * @return {Boolean} true if all selections were iterated
4229 each : function(fn, scope){
4230 var s = this.getSelections();
4231 for(var i = 0, len = s.length; i < len; i++){
4232 if(fn.call(scope || this, s[i], i) === false){
4240 * Clears all selections if the selection model
4241 * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}.
4242 * @param {Boolean} fast (optional) <tt>true</tt> to bypass the
4243 * conditional checks and events described in {@link #deselectRow}.
4245 clearSelections : function(fast){
4246 if(this.isLocked()){
4250 var ds = this.grid.store;
4251 var s = this.selections;
4253 this.deselectRow(ds.indexOfId(r.id));
4257 this.selections.clear();
4264 * Selects all rows if the selection model
4265 * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}.
4267 selectAll : function(){
4268 if(this.isLocked()){
4271 this.selections.clear();
4272 for(var i = 0, len = this.grid.store.getCount(); i < len; i++){
4273 this.selectRow(i, true);
4278 * Returns <tt>true</tt> if there is a selection.
4281 hasSelection : function(){
4282 return this.selections.length > 0;
4286 * Returns <tt>true</tt> if the specified row is selected.
4287 * @param {Number/Record} index The record or index of the record to check
4290 isSelected : function(index){
4291 var r = Ext.isNumber(index) ? this.grid.store.getAt(index) : index;
4292 return (r && this.selections.key(r.id) ? true : false);
4296 * Returns <tt>true</tt> if the specified record id is selected.
4297 * @param {String} id The id of record to check
4300 isIdSelected : function(id){
4301 return (this.selections.key(id) ? true : false);
4305 handleMouseDown : function(g, rowIndex, e){
4306 if(e.button !== 0 || this.isLocked()){
4309 var view = this.grid.getView();
4310 if(e.shiftKey && !this.singleSelect && this.last !== false){
4311 var last = this.last;
4312 this.selectRange(last, rowIndex, e.ctrlKey);
4313 this.last = last; // reset the last
4314 view.focusRow(rowIndex);
4316 var isSelected = this.isSelected(rowIndex);
4317 if(e.ctrlKey && isSelected){
4318 this.deselectRow(rowIndex);
4319 }else if(!isSelected || this.getCount() > 1){
4320 this.selectRow(rowIndex, e.ctrlKey || e.shiftKey);
4321 view.focusRow(rowIndex);
4327 * Selects multiple rows.
4328 * @param {Array} rows Array of the indexes of the row to select
4329 * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep
4330 * existing selections (defaults to <tt>false</tt>)
4332 selectRows : function(rows, keepExisting){
4334 this.clearSelections();
4336 for(var i = 0, len = rows.length; i < len; i++){
4337 this.selectRow(rows[i], true);
4342 * Selects a range of rows if the selection model
4343 * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}.
4344 * All rows in between startRow and endRow are also selected.
4345 * @param {Number} startRow The index of the first row in the range
4346 * @param {Number} endRow The index of the last row in the range
4347 * @param {Boolean} keepExisting (optional) True to retain existing selections
4349 selectRange : function(startRow, endRow, keepExisting){
4351 if(this.isLocked()){
4355 this.clearSelections();
4357 if(startRow <= endRow){
4358 for(i = startRow; i <= endRow; i++){
4359 this.selectRow(i, true);
4362 for(i = startRow; i >= endRow; i--){
4363 this.selectRow(i, true);
4369 * Deselects a range of rows if the selection model
4370 * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}.
4371 * All rows in between startRow and endRow are also deselected.
4372 * @param {Number} startRow The index of the first row in the range
4373 * @param {Number} endRow The index of the last row in the range
4375 deselectRange : function(startRow, endRow, preventViewNotify){
4376 if(this.isLocked()){
4379 for(var i = startRow; i <= endRow; i++){
4380 this.deselectRow(i, preventViewNotify);
4385 * Selects a row. Before selecting a row, checks if the selection model
4386 * {@link Ext.grid.AbstractSelectionModel#isLocked is locked} and fires the
4387 * {@link #beforerowselect} event. If these checks are satisfied the row
4388 * will be selected and followed up by firing the {@link #rowselect} and
4389 * {@link #selectionchange} events.
4390 * @param {Number} row The index of the row to select
4391 * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
4392 * @param {Boolean} preventViewNotify (optional) Specify <tt>true</tt> to
4393 * prevent notifying the view (disables updating the selected appearance)
4395 selectRow : function(index, keepExisting, preventViewNotify){
4396 if(this.isLocked() || (index < 0 || index >= this.grid.store.getCount()) || (keepExisting && this.isSelected(index))){
4399 var r = this.grid.store.getAt(index);
4400 if(r && this.fireEvent('beforerowselect', this, index, keepExisting, r) !== false){
4401 if(!keepExisting || this.singleSelect){
4402 this.clearSelections();
4404 this.selections.add(r);
4405 this.last = this.lastActive = index;
4406 if(!preventViewNotify){
4407 this.grid.getView().onRowSelect(index);
4409 this.fireEvent('rowselect', this, index, r);
4410 this.fireEvent('selectionchange', this);
4415 * Deselects a row. Before deselecting a row, checks if the selection model
4416 * {@link Ext.grid.AbstractSelectionModel#isLocked is locked}.
4417 * If this check is satisfied the row will be deselected and followed up by
4418 * firing the {@link #rowdeselect} and {@link #selectionchange} events.
4419 * @param {Number} row The index of the row to deselect
4420 * @param {Boolean} preventViewNotify (optional) Specify <tt>true</tt> to
4421 * prevent notifying the view (disables updating the selected appearance)
4423 deselectRow : function(index, preventViewNotify){
4424 if(this.isLocked()){
4427 if(this.last == index){
4430 if(this.lastActive == index){
4431 this.lastActive = false;
4433 var r = this.grid.store.getAt(index);
4435 this.selections.remove(r);
4436 if(!preventViewNotify){
4437 this.grid.getView().onRowDeselect(index);
4439 this.fireEvent('rowdeselect', this, index, r);
4440 this.fireEvent('selectionchange', this);
4445 restoreLast : function(){
4447 this.last = this._last;
4452 acceptsNav : function(row, col, cm){
4453 return !cm.isHidden(col) && cm.isCellEditable(col, row);
4457 onEditorKey : function(field, e){
4462 ed = g.activeEditor,
4464 var shift = e.shiftKey;
4469 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
4471 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
4473 }else if(k == e.ENTER){
4474 if(this.moveEditorOnEnter !== false){
4476 newCell = g.walkCells(last.row - 1, last.col, -1, this.acceptsNav, this);
4478 newCell = g.walkCells(last.row + 1, last.col, 1, this.acceptsNav, this);
4487 this.selectRow(r); // *** highlight newly-selected cell and update selection
4490 if(g.isEditor && g.editing){ // *** handle tabbing while editorgrid is in edit mode
4491 ae = g.activeEditor;
4492 if(ae && ae.field.triggerBlur){
4493 // *** if activeEditor is a TriggerField, explicitly call its triggerBlur() method
4494 ae.field.triggerBlur();
4497 g.startEditing(r, c);
4501 destroy : function(){
4503 this.rowNav.disable();
4506 Ext.grid.RowSelectionModel.superclass.destroy.call(this);
4509 * @class Ext.grid.Column
\r
4510 * <p>This class encapsulates column configuration data to be used in the initialization of a
\r
4511 * {@link Ext.grid.ColumnModel ColumnModel}.</p>
\r
4512 * <p>While subclasses are provided to render data in different ways, this class renders a passed
\r
4513 * data field unchanged and is usually used for textual columns.</p>
\r
4515 Ext.grid.Column = Ext.extend(Object, {
\r
4517 * @cfg {Boolean} editable Optional. Defaults to <tt>true</tt>, enabling the configured
\r
4518 * <tt>{@link #editor}</tt>. Set to <tt>false</tt> to initially disable editing on this column.
\r
4519 * The initial configuration may be dynamically altered using
\r
4520 * {@link Ext.grid.ColumnModel}.{@link Ext.grid.ColumnModel#setEditable setEditable()}.
\r
4523 * @cfg {String} id Optional. A name which identifies this column (defaults to the column's initial
\r
4524 * ordinal position.) The <tt>id</tt> is used to create a CSS <b>class</b> name which is applied to all
\r
4525 * table cells (including headers) in that column (in this context the <tt>id</tt> does not need to be
\r
4526 * unique). The class name takes the form of <pre>x-grid3-td-<b>id</b></pre>
\r
4527 * Header cells will also receive this class name, but will also have the class <pre>x-grid3-hd</pre>
\r
4528 * So, to target header cells, use CSS selectors such as:<pre>.x-grid3-hd-row .x-grid3-td-<b>id</b></pre>
\r
4529 * The {@link Ext.grid.GridPanel#autoExpandColumn} grid config option references the column via this
\r
4530 * unique identifier.
\r
4533 * @cfg {String} header Optional. The header text to be used as innerHTML
\r
4534 * (html tags are accepted) to display in the Grid view. <b>Note</b>: to
\r
4535 * have a clickable header with no text displayed use <tt>' '</tt>.
\r
4538 * @cfg {Boolean} groupable Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option
\r
4539 * may be used to disable the header menu item to group by the column selected. Defaults to <tt>true</tt>,
\r
4540 * which enables the header menu group option. Set to <tt>false</tt> to disable (but still show) the
\r
4541 * group option in the header menu for the column. See also <code>{@link #groupName}</code>.
\r
4544 * @cfg {String} groupName Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option
\r
4545 * may be used to specify the text with which to prefix the group field value in the group header line.
\r
4546 * See also {@link #groupRenderer} and
\r
4547 * {@link Ext.grid.GroupingView}.{@link Ext.grid.GroupingView#showGroupName showGroupName}.
\r
4550 * @cfg {Function} groupRenderer <p>Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option
\r
4551 * may be used to specify the function used to format the grouping field value for display in the group
\r
4552 * {@link #groupName header}. If a <tt><b>groupRenderer</b></tt> is not specified, the configured
\r
4553 * <tt><b>{@link #renderer}</b></tt> will be called; if a <tt><b>{@link #renderer}</b></tt> is also not specified
\r
4554 * the new value of the group field will be used.</p>
\r
4555 * <p>The called function (either the <tt><b>groupRenderer</b></tt> or <tt><b>{@link #renderer}</b></tt>) will be
\r
4556 * passed the following parameters:
\r
4557 * <div class="mdetail-params"><ul>
\r
4558 * <li><b>v</b> : Object<p class="sub-desc">The new value of the group field.</p></li>
\r
4559 * <li><b>unused</b> : undefined<p class="sub-desc">Unused parameter.</p></li>
\r
4560 * <li><b>r</b> : Ext.data.Record<p class="sub-desc">The Record providing the data
\r
4561 * for the row which caused group change.</p></li>
\r
4562 * <li><b>rowIndex</b> : Number<p class="sub-desc">The row index of the Record which caused group change.</p></li>
\r
4563 * <li><b>colIndex</b> : Number<p class="sub-desc">The column index of the group field.</p></li>
\r
4564 * <li><b>ds</b> : Ext.data.Store<p class="sub-desc">The Store which is providing the data Model.</p></li>
\r
4566 * <p>The function should return a string value.</p>
\r
4569 * @cfg {String} emptyGroupText Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option
\r
4570 * may be used to specify the text to display when there is an empty group value. Defaults to the
\r
4571 * {@link Ext.grid.GroupingView}.{@link Ext.grid.GroupingView#emptyGroupText emptyGroupText}.
\r
4574 * @cfg {String} dataIndex <p><b>Required</b>. The name of the field in the
\r
4575 * grid's {@link Ext.data.Store}'s {@link Ext.data.Record} definition from
\r
4576 * which to draw the column's value.</p>
\r
4579 * @cfg {Number} width
\r
4580 * Optional. The initial width in pixels of the column.
\r
4581 * The width of each column can also be affected if any of the following are configured:
\r
4582 * <div class="mdetail-params"><ul>
\r
4583 * <li>{@link Ext.grid.GridPanel}.<tt>{@link Ext.grid.GridPanel#autoExpandColumn autoExpandColumn}</tt></li>
\r
4584 * <li>{@link Ext.grid.GridView}.<tt>{@link Ext.grid.GridView#forceFit forceFit}</tt>
\r
4585 * <div class="sub-desc">
\r
4586 * <p>By specifying <tt>forceFit:true</tt>, {@link #fixed non-fixed width} columns will be
\r
4587 * re-proportioned (based on the relative initial widths) to fill the width of the grid so
\r
4588 * that no horizontal scrollbar is shown.</p>
\r
4590 * <li>{@link Ext.grid.GridView}.<tt>{@link Ext.grid.GridView#autoFill autoFill}</tt></li>
\r
4591 * <li>{@link Ext.grid.GridPanel}.<tt>{@link Ext.grid.GridPanel#minColumnWidth minColumnWidth}</tt></li>
\r
4592 * <br><p><b>Note</b>: when the width of each column is determined, a space on the right side
\r
4593 * is reserved for the vertical scrollbar. The
\r
4594 * {@link Ext.grid.GridView}.<tt>{@link Ext.grid.GridView#scrollOffset scrollOffset}</tt>
\r
4595 * can be modified to reduce or eliminate the reserved offset.</p>
\r
4598 * @cfg {Boolean} sortable Optional. <tt>true</tt> if sorting is to be allowed on this column.
\r
4599 * Defaults to the value of the <code>{@link Ext.grid.ColumnModel#defaultSortable}</code> property.
\r
4600 * Whether local/remote sorting is used is specified in <code>{@link Ext.data.Store#remoteSort}</code>.
\r
4603 * @cfg {Boolean} fixed Optional. <tt>true</tt> if the column width cannot be changed. Defaults to <tt>false</tt>.
\r
4606 * @cfg {Boolean} resizable Optional. <tt>false</tt> to disable column resizing. Defaults to <tt>true</tt>.
\r
4609 * @cfg {Boolean} menuDisabled Optional. <tt>true</tt> to disable the column menu. Defaults to <tt>false</tt>.
\r
4612 * @cfg {Boolean} hidden
\r
4613 * Optional. <tt>true</tt> to initially hide this column. Defaults to <tt>false</tt>.
\r
4614 * A hidden column {@link Ext.grid.GridPanel#enableColumnHide may be shown via the header row menu}.
\r
4615 * If a column is never to be shown, simply do not include this column in the Column Model at all.
\r
4618 * @cfg {String} tooltip Optional. A text string to use as the column header's tooltip. If Quicktips
\r
4619 * are enabled, this value will be used as the text of the quick tip, otherwise it will be set as the
\r
4620 * header's HTML title attribute. Defaults to ''.
\r
4623 * @cfg {Mixed} renderer
\r
4624 * <p>For an alternative to specifying a renderer see <code>{@link #xtype}</code></p>
\r
4625 * <p>Optional. A renderer is an 'interceptor' method which can be used transform data (value,
\r
4626 * appearance, etc.) before it is rendered). This may be specified in either of three ways:
\r
4627 * <div class="mdetail-params"><ul>
\r
4628 * <li>A renderer function used to return HTML markup for a cell given the cell's data value.</li>
\r
4629 * <li>A string which references a property name of the {@link Ext.util.Format} class which
\r
4630 * provides a renderer function.</li>
\r
4631 * <li>An object specifying both the renderer function, and its execution scope (<tt><b>this</b></tt>
\r
4632 * reference) e.g.:<pre style="margin-left:1.2em"><code>
\r
4634 fn: this.gridRenderer,
\r
4637 </code></pre></li></ul></div>
\r
4638 * If not specified, the default renderer uses the raw data value.</p>
\r
4639 * <p>For information about the renderer function (passed parameters, etc.), see
\r
4640 * {@link Ext.grid.ColumnModel#setRenderer}. An example of specifying renderer function inline:</p><pre><code>
\r
4641 var companyColumn = {
\r
4642 header: 'Company Name',
\r
4643 dataIndex: 'company',
\r
4644 renderer: function(value, metaData, record, rowIndex, colIndex, store) {
\r
4645 // provide the logic depending on business rules
\r
4646 // name of your own choosing to manipulate the cell depending upon
\r
4647 // the data in the underlying Record object.
\r
4648 if (value == 'whatever') {
\r
4649 //metaData.css : String : A CSS class name to add to the TD element of the cell.
\r
4650 //metaData.attr : String : An html attribute definition string to apply to
\r
4651 // the data container element within the table
\r
4652 // cell (e.g. 'style="color:red;"').
\r
4653 metaData.css = 'name-of-css-class-you-will-define';
\r
4659 * See also {@link #scope}.
\r
4662 * @cfg {String} xtype Optional. A String which references a predefined {@link Ext.grid.Column} subclass
\r
4663 * type which is preconfigured with an appropriate <code>{@link #renderer}</code> to be easily
\r
4664 * configured into a ColumnModel. The predefined {@link Ext.grid.Column} subclass types are:
\r
4665 * <div class="mdetail-params"><ul>
\r
4666 * <li><b><tt>gridcolumn</tt></b> : {@link Ext.grid.Column} (<b>Default</b>)<p class="sub-desc"></p></li>
\r
4667 * <li><b><tt>booleancolumn</tt></b> : {@link Ext.grid.BooleanColumn}<p class="sub-desc"></p></li>
\r
4668 * <li><b><tt>numbercolumn</tt></b> : {@link Ext.grid.NumberColumn}<p class="sub-desc"></p></li>
\r
4669 * <li><b><tt>datecolumn</tt></b> : {@link Ext.grid.DateColumn}<p class="sub-desc"></p></li>
\r
4670 * <li><b><tt>templatecolumn</tt></b> : {@link Ext.grid.TemplateColumn}<p class="sub-desc"></p></li>
\r
4672 * <p>Configuration properties for the specified <code>xtype</code> may be specified with
\r
4673 * the Column configuration properties, for example:</p>
\r
4675 var grid = new Ext.grid.GridPanel({
\r
4678 header: 'Last Updated',
\r
4679 dataIndex: 'lastChange',
\r
4682 //renderer: Ext.util.Format.dateRenderer('m/d/Y'),
\r
4683 xtype: 'datecolumn', // use xtype instead of renderer
\r
4684 format: 'M/d/Y' // configuration property for {@link Ext.grid.DateColumn}
\r
4692 * @cfg {Object} scope Optional. The scope (<tt><b>this</b></tt> reference) in which to execute the
\r
4693 * renderer. Defaults to the Column configuration object.
\r
4696 * @cfg {String} align Optional. Set the CSS text-align property of the column. Defaults to undefined.
\r
4699 * @cfg {String} css Optional. An inline style definition string which is applied to all table cells in the column
\r
4700 * (excluding headers). Defaults to undefined.
\r
4703 * @cfg {Boolean} hideable Optional. Specify as <tt>false</tt> to prevent the user from hiding this column
\r
4704 * (defaults to true). To disallow column hiding globally for all columns in the grid, use
\r
4705 * {@link Ext.grid.GridPanel#enableColumnHide} instead.
\r
4708 * @cfg {Ext.form.Field} editor Optional. The {@link Ext.form.Field} to use when editing values in this column
\r
4709 * if editing is supported by the grid. See <tt>{@link #editable}</tt> also.
\r
4714 * @cfg {Boolean} isColumn
\r
4715 * Used by ColumnModel setConfig method to avoid reprocessing a Column
\r
4716 * if <code>isColumn</code> is not set ColumnModel will recreate a new Ext.grid.Column
\r
4717 * Defaults to true.
\r
4721 constructor : function(config){
\r
4722 Ext.apply(this, config);
\r
4724 if(Ext.isString(this.renderer)){
\r
4725 this.renderer = Ext.util.Format[this.renderer];
\r
4726 }else if(Ext.isObject(this.renderer)){
\r
4727 this.scope = this.renderer.scope;
\r
4728 this.renderer = this.renderer.fn;
\r
4731 this.scope = this;
\r
4734 var ed = this.editor;
\r
4735 delete this.editor;
\r
4736 this.setEditor(ed);
\r
4740 * Optional. A function which returns displayable data when passed the following parameters:
\r
4741 * <div class="mdetail-params"><ul>
\r
4742 * <li><b>value</b> : Object<p class="sub-desc">The data value for the cell.</p></li>
\r
4743 * <li><b>metadata</b> : Object<p class="sub-desc">An object in which you may set the following attributes:<ul>
\r
4744 * <li><b>css</b> : String<p class="sub-desc">A CSS class name to add to the cell's TD element.</p></li>
\r
4745 * <li><b>attr</b> : String<p class="sub-desc">An HTML attribute definition string to apply to the data container
\r
4746 * element <i>within</i> the table cell (e.g. 'style="color:red;"').</p></li></ul></p></li>
\r
4747 * <li><b>record</b> : Ext.data.record<p class="sub-desc">The {@link Ext.data.Record} from which the data was
\r
4748 * extracted.</p></li>
\r
4749 * <li><b>rowIndex</b> : Number<p class="sub-desc">Row index</p></li>
\r
4750 * <li><b>colIndex</b> : Number<p class="sub-desc">Column index</p></li>
\r
4751 * <li><b>store</b> : Ext.data.Store<p class="sub-desc">The {@link Ext.data.Store} object from which the Record
\r
4752 * was extracted.</p></li>
\r
4754 * @property renderer
\r
4757 renderer : function(value){
\r
4758 if(Ext.isString(value) && value.length < 1){
\r
4765 getEditor: function(rowIndex){
\r
4766 return this.editable !== false ? this.editor : null;
\r
4770 * Sets a new editor for this column.
\r
4771 * @param {Ext.Editor/Ext.form.Field} editor The editor to set
\r
4773 setEditor : function(editor){
\r
4775 this.editor.destroy();
\r
4777 this.editor = null;
\r
4779 //not an instance, create it
\r
4780 if(!editor.isXType){
\r
4781 editor = Ext.create(editor, 'textfield');
\r
4783 //check if it's wrapped in an editor
\r
4784 if(!editor.startEdit){
\r
4785 editor = new Ext.grid.GridEditor(editor);
\r
4787 this.editor = editor;
\r
4791 destroy : function(){
\r
4792 this.setEditor(null);
\r
4796 * Returns the {@link Ext.Editor editor} defined for this column that was created to wrap the {@link Ext.form.Field Field}
\r
4797 * used to edit the cell.
\r
4798 * @param {Number} rowIndex The row index
\r
4799 * @return {Ext.Editor}
\r
4801 getCellEditor: function(rowIndex){
\r
4802 return this.getEditor(rowIndex);
\r
4807 * @class Ext.grid.BooleanColumn
\r
4808 * @extends Ext.grid.Column
\r
4809 * <p>A Column definition class which renders boolean data fields. See the {@link Ext.grid.Column#xtype xtype}
\r
4810 * config option of {@link Ext.grid.Column} for more details.</p>
\r
4812 Ext.grid.BooleanColumn = Ext.extend(Ext.grid.Column, {
\r
4814 * @cfg {String} trueText
\r
4815 * The string returned by the renderer when the column value is not falsey (defaults to <tt>'true'</tt>).
\r
4819 * @cfg {String} falseText
\r
4820 * The string returned by the renderer when the column value is falsey (but not undefined) (defaults to
\r
4821 * <tt>'false'</tt>).
\r
4823 falseText: 'false',
\r
4825 * @cfg {String} undefinedText
\r
4826 * The string returned by the renderer when the column value is undefined (defaults to <tt>' '</tt>).
\r
4828 undefinedText: ' ',
\r
4830 constructor: function(cfg){
\r
4831 Ext.grid.BooleanColumn.superclass.constructor.call(this, cfg);
\r
4832 var t = this.trueText, f = this.falseText, u = this.undefinedText;
\r
4833 this.renderer = function(v){
\r
4834 if(v === undefined){
\r
4837 if(!v || v === 'false'){
\r
4846 * @class Ext.grid.NumberColumn
\r
4847 * @extends Ext.grid.Column
\r
4848 * <p>A Column definition class which renders a numeric data field according to a {@link #format} string. See the
\r
4849 * {@link Ext.grid.Column#xtype xtype} config option of {@link Ext.grid.Column} for more details.</p>
\r
4851 Ext.grid.NumberColumn = Ext.extend(Ext.grid.Column, {
\r
4853 * @cfg {String} format
\r
4854 * A formatting string as used by {@link Ext.util.Format#number} to format a numeric value for this Column
\r
4855 * (defaults to <tt>'0,000.00'</tt>).
\r
4857 format : '0,000.00',
\r
4858 constructor: function(cfg){
\r
4859 Ext.grid.NumberColumn.superclass.constructor.call(this, cfg);
\r
4860 this.renderer = Ext.util.Format.numberRenderer(this.format);
\r
4865 * @class Ext.grid.DateColumn
\r
4866 * @extends Ext.grid.Column
\r
4867 * <p>A Column definition class which renders a passed date according to the default locale, or a configured
\r
4868 * {@link #format}. See the {@link Ext.grid.Column#xtype xtype} config option of {@link Ext.grid.Column}
\r
4869 * for more details.</p>
\r
4871 Ext.grid.DateColumn = Ext.extend(Ext.grid.Column, {
\r
4873 * @cfg {String} format
\r
4874 * A formatting string as used by {@link Date#format} to format a Date for this Column
\r
4875 * (defaults to <tt>'m/d/Y'</tt>).
\r
4878 constructor: function(cfg){
\r
4879 Ext.grid.DateColumn.superclass.constructor.call(this, cfg);
\r
4880 this.renderer = Ext.util.Format.dateRenderer(this.format);
\r
4885 * @class Ext.grid.TemplateColumn
\r
4886 * @extends Ext.grid.Column
\r
4887 * <p>A Column definition class which renders a value by processing a {@link Ext.data.Record Record}'s
\r
4888 * {@link Ext.data.Record#data data} using a {@link #tpl configured} {@link Ext.XTemplate XTemplate}.
\r
4889 * See the {@link Ext.grid.Column#xtype xtype} config option of {@link Ext.grid.Column} for more
\r
4892 Ext.grid.TemplateColumn = Ext.extend(Ext.grid.Column, {
\r
4894 * @cfg {String/XTemplate} tpl
\r
4895 * An {@link Ext.XTemplate XTemplate}, or an XTemplate <i>definition string</i> to use to process a
\r
4896 * {@link Ext.data.Record Record}'s {@link Ext.data.Record#data data} to produce a column's rendered value.
\r
4898 constructor: function(cfg){
\r
4899 Ext.grid.TemplateColumn.superclass.constructor.call(this, cfg);
\r
4900 var tpl = (!Ext.isPrimitive(this.tpl) && this.tpl.compile) ? this.tpl : new Ext.XTemplate(this.tpl);
\r
4901 this.renderer = function(value, p, r){
\r
4902 return tpl.apply(r.data);
\r
4911 * @member Ext.grid.Column
\r
4913 * <p>An object containing predefined Column classes keyed by a mnemonic code which may be referenced
\r
4914 * by the {@link Ext.grid.ColumnModel#xtype xtype} config option of ColumnModel.</p>
\r
4915 * <p>This contains the following properties</p><div class="mdesc-details"><ul>
\r
4916 * <li>gridcolumn : <b>{@link Ext.grid.Column Column constructor}</b></li>
\r
4917 * <li>booleancolumn : <b>{@link Ext.grid.BooleanColumn BooleanColumn constructor}</b></li>
\r
4918 * <li>numbercolumn : <b>{@link Ext.grid.NumberColumn NumberColumn constructor}</b></li>
\r
4919 * <li>datecolumn : <b>{@link Ext.grid.DateColumn DateColumn constructor}</b></li>
\r
4920 * <li>templatecolumn : <b>{@link Ext.grid.TemplateColumn TemplateColumn constructor}</b></li>
\r
4923 Ext.grid.Column.types = {
\r
4924 gridcolumn : Ext.grid.Column,
\r
4925 booleancolumn: Ext.grid.BooleanColumn,
\r
4926 numbercolumn: Ext.grid.NumberColumn,
\r
4927 datecolumn: Ext.grid.DateColumn,
\r
4928 templatecolumn: Ext.grid.TemplateColumn
\r
4930 * @class Ext.grid.RowNumberer
4931 * This is a utility class that can be passed into a {@link Ext.grid.ColumnModel} as a column config that provides
4932 * an automatic row numbering column.
4935 // This is a typical column config with the first column providing row numbers
4936 var colModel = new Ext.grid.ColumnModel([
4937 new Ext.grid.RowNumberer(),
4938 {header: "Name", width: 80, sortable: true},
4939 {header: "Code", width: 50, sortable: true},
4940 {header: "Description", width: 200, sortable: true}
4944 * @param {Object} config The configuration options
4946 Ext.grid.RowNumberer = Ext.extend(Object, {
4948 * @cfg {String} header Any valid text or HTML fragment to display in the header cell for the row
4949 * number column (defaults to '').
4953 * @cfg {Number} width The default width in pixels of the row number column (defaults to 23).
4957 * @cfg {Boolean} sortable True if the row number column is sortable (defaults to false).
4962 constructor : function(config){
4963 Ext.apply(this, config);
4965 this.renderer = this.renderer.createDelegate(this);
4977 renderer : function(v, p, record, rowIndex){
4979 p.cellAttr = 'rowspan="'+this.rowspan+'"';
4984 * @class Ext.grid.CheckboxSelectionModel
\r
4985 * @extends Ext.grid.RowSelectionModel
\r
4986 * A custom selection model that renders a column of checkboxes that can be toggled to select or deselect rows.
\r
4988 * @param {Object} config The configuration options
\r
4990 Ext.grid.CheckboxSelectionModel = Ext.extend(Ext.grid.RowSelectionModel, {
\r
4993 * @cfg {Boolean} checkOnly <tt>true</tt> if rows can only be selected by clicking on the
\r
4994 * checkbox column (defaults to <tt>false</tt>).
\r
4997 * @cfg {String} header Any valid text or HTML fragment to display in the header cell for the
\r
4998 * checkbox column. Defaults to:<pre><code>
\r
4999 * '<div class="x-grid3-hd-checker">&#160;</div>'</tt>
\r
5001 * The default CSS class of <tt>'x-grid3-hd-checker'</tt> displays a checkbox in the header
\r
5002 * and provides support for automatic check all/none behavior on header click. This string
\r
5003 * can be replaced by any valid HTML fragment, including a simple text string (e.g.,
\r
5004 * <tt>'Select Rows'</tt>), but the automatic check all/none behavior will only work if the
\r
5005 * <tt>'x-grid3-hd-checker'</tt> class is supplied.
\r
5007 header : '<div class="x-grid3-hd-checker"> </div>',
\r
5009 * @cfg {Number} width The default width in pixels of the checkbox column (defaults to <tt>20</tt>).
\r
5013 * @cfg {Boolean} sortable <tt>true</tt> if the checkbox column is sortable (defaults to
\r
5014 * <tt>false</tt>).
\r
5019 menuDisabled : true,
\r
5024 constructor : function(){
\r
5025 Ext.grid.CheckboxSelectionModel.superclass.constructor.apply(this, arguments);
\r
5027 if(this.checkOnly){
\r
5028 this.handleMouseDown = Ext.emptyFn;
\r
5033 initEvents : function(){
\r
5034 Ext.grid.CheckboxSelectionModel.superclass.initEvents.call(this);
\r
5035 this.grid.on('render', function(){
\r
5036 var view = this.grid.getView();
\r
5037 view.mainBody.on('mousedown', this.onMouseDown, this);
\r
5038 Ext.fly(view.innerHd).on('mousedown', this.onHdMouseDown, this);
\r
5044 onMouseDown : function(e, t){
\r
5045 if(e.button === 0 && t.className == 'x-grid3-row-checker'){ // Only fire if left-click
\r
5047 var row = e.getTarget('.x-grid3-row');
\r
5049 var index = row.rowIndex;
\r
5050 if(this.isSelected(index)){
\r
5051 this.deselectRow(index);
\r
5053 this.selectRow(index, true);
\r
5060 onHdMouseDown : function(e, t){
\r
5061 if(t.className == 'x-grid3-hd-checker'){
\r
5063 var hd = Ext.fly(t.parentNode);
\r
5064 var isChecked = hd.hasClass('x-grid3-hd-checker-on');
\r
5066 hd.removeClass('x-grid3-hd-checker-on');
\r
5067 this.clearSelections();
\r
5069 hd.addClass('x-grid3-hd-checker-on');
\r
5076 renderer : function(v, p, record){
\r
5077 return '<div class="x-grid3-row-checker"> </div>';
\r