3 * Copyright(c) 2006-2009 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
31 {id: 'company', header: 'Company', width: 200, sortable: true, dataIndex: 'company'},
\r
32 {header: 'Price', width: 120, sortable: true, renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
\r
33 {header: 'Change', width: 120, sortable: true, dataIndex: 'change'},
\r
34 {header: '% Change', width: 120, sortable: true, dataIndex: 'pctChange'},
\r
35 // instead of specifying renderer: Ext.util.Format.dateRenderer('m/d/Y') use xtype
\r
36 {header: 'Last Updated', width: 135, sortable: true, dataIndex: 'lastChange', xtype: 'datecolumn', format: 'M d, Y'}
\r
38 {@link #viewConfig}: {
\r
39 {@link Ext.grid.GridView#forceFit forceFit}: true,
\r
41 // Return CSS class to apply to rows depending upon data values
\r
42 {@link Ext.grid.GridView#getRowClass getRowClass}: function(record, index) {
\r
43 var c = record.{@link Ext.data.Record#get get}('change');
\r
45 return 'price-fall';
\r
47 return 'price-rise';
\r
51 {@link #sm}: new Ext.grid.RowSelectionModel({singleSelect:true}),
\r
55 title: 'Framed with Row Selection and Horizontal Scrolling',
\r
56 iconCls: 'icon-grid'
\r
59 * <p><b><u>Notes:</u></b></p>
\r
60 * <div class="mdetail-params"><ul>
\r
61 * <li>Although this class inherits many configuration options from base classes, some of them
\r
62 * (such as autoScroll, autoWidth, layout, items, etc) are not used by this class, and will
\r
63 * have no effect.</li>
\r
64 * <li>A grid <b>requires</b> a width in which to scroll its columns, and a height in which to
\r
65 * scroll its rows. These dimensions can either be set explicitly through the
\r
66 * <tt>{@link Ext.BoxComponent#height height}</tt> and <tt>{@link Ext.BoxComponent#width width}</tt>
\r
67 * configuration options or implicitly set by using the grid as a child item of a
\r
68 * {@link Ext.Container Container} which will have a {@link Ext.Container#layout layout manager}
\r
69 * provide the sizing of its child items (for example the Container of the Grid may specify
\r
70 * <tt>{@link Ext.Container#layout layout}:'fit'</tt>).</li>
\r
71 * <li>To access the data in a Grid, it is necessary to use the data model encapsulated
\r
72 * by the {@link #store Store}. See the {@link #cellclick} event for more details.</li>
\r
75 * @param {Object} config The config object
\r
78 Ext.grid.GridPanel = Ext.extend(Ext.Panel, {
\r
80 * @cfg {String} autoExpandColumn
\r
81 * <p>The <tt>{@link Ext.grid.Column#id id}</tt> of a {@link Ext.grid.Column column} in
\r
82 * this grid that should expand to fill unused space. This value specified here can not
\r
83 * be <tt>0</tt>.</p>
\r
84 * <br><p><b>Note</b>: If the Grid's {@link Ext.grid.GridView view} is configured with
\r
85 * <tt>{@link Ext.grid.GridView#forceFit forceFit}=true</tt> the <tt>autoExpandColumn</tt>
\r
86 * is ignored. See {@link Ext.grid.Column}.<tt>{@link Ext.grid.Column#width width}</tt>
\r
87 * for additional details.</p>
\r
88 * <p>See <tt>{@link #autoExpandMax}</tt> and <tt>{@link #autoExpandMin}</tt> also.</p>
\r
90 autoExpandColumn : false,
\r
92 * @cfg {Number} autoExpandMax The maximum width the <tt>{@link #autoExpandColumn}</tt>
\r
93 * can have (if enabled). Defaults to <tt>1000</tt>.
\r
95 autoExpandMax : 1000,
\r
97 * @cfg {Number} autoExpandMin The minimum width the <tt>{@link #autoExpandColumn}</tt>
\r
98 * can have (if enabled). Defaults to <tt>50</tt>.
\r
100 autoExpandMin : 50,
\r
102 * @cfg {Boolean} columnLines <tt>true</tt> to add css for column separation lines.
\r
103 * Default is <tt>false</tt>.
\r
105 columnLines : false,
\r
107 * @cfg {Object} cm Shorthand for <tt>{@link #colModel}</tt>.
\r
110 * @cfg {Object} colModel The {@link Ext.grid.ColumnModel} to use when rendering the grid (required).
\r
113 * @cfg {Array} columns An array of {@link Ext.grid.Column columns} to auto create a
\r
114 * {@link Ext.grid.ColumnModel}. The ColumnModel may be explicitly created via the
\r
115 * <tt>{@link #colModel}</tt> configuration property.
\r
118 * @cfg {String} ddGroup The DD group this GridPanel belongs to. Defaults to <tt>'GridDD'</tt> if not specified.
\r
121 * @cfg {String} ddText
\r
122 * Configures the text in the drag proxy. Defaults to:
\r
124 * ddText : '{0} selected row{1}'
\r
126 * <tt>{0}</tt> is replaced with the number of selected rows.
\r
128 ddText : '{0} selected row{1}',
\r
130 * @cfg {Boolean} deferRowRender <P>Defaults to <tt>true</tt> to enable deferred row rendering.</p>
\r
131 * <p>This allows the GridPanel to be initially rendered empty, with the expensive update of the row
\r
132 * structure deferred so that layouts with GridPanels appear more quickly.</p>
\r
134 deferRowRender : true,
\r
136 * @cfg {Boolean} disableSelection <p><tt>true</tt> to disable selections in the grid. Defaults to <tt>false</tt>.</p>
\r
137 * <p>Ignored if a {@link #selModel SelectionModel} is specified.</p>
\r
140 * @cfg {Boolean} enableColumnResize <tt>false</tt> to turn off column resizing for the whole grid. Defaults to <tt>true</tt>.
\r
143 * @cfg {Boolean} enableColumnHide Defaults to <tt>true</tt> to enable hiding of columns with the header context menu.
\r
145 enableColumnHide : true,
\r
147 * @cfg {Boolean} enableColumnMove Defaults to <tt>true</tt> to enable drag and drop reorder of columns. <tt>false</tt>
\r
148 * to turn off column reordering via drag drop.
\r
150 enableColumnMove : true,
\r
152 * @cfg {Boolean} enableDragDrop <p>Enables dragging of the selected rows of the GridPanel. Defaults to <tt>false</tt>.</p>
\r
153 * <p>Setting this to <b><tt>true</tt></b> causes this GridPanel's {@link #getView GridView} to
\r
154 * create an instance of {@link Ext.grid.GridDragZone}. <b>Note</b>: this is available only <b>after</b>
\r
155 * the Grid has been rendered as the GridView's <tt>{@link Ext.grid.GridView#dragZone dragZone}</tt>
\r
157 * <p>A cooperating {@link Ext.dd.DropZone DropZone} must be created who's implementations of
\r
158 * {@link Ext.dd.DropZone#onNodeEnter onNodeEnter}, {@link Ext.dd.DropZone#onNodeOver onNodeOver},
\r
159 * {@link Ext.dd.DropZone#onNodeOut onNodeOut} and {@link Ext.dd.DropZone#onNodeDrop onNodeDrop} are able
\r
160 * to process the {@link Ext.grid.GridDragZone#getDragData data} which is provided.</p>
\r
162 enableDragDrop : false,
\r
164 * @cfg {Boolean} enableHdMenu Defaults to <tt>true</tt> to enable the drop down button for menu in the headers.
\r
166 enableHdMenu : true,
\r
168 * @cfg {Boolean} hideHeaders True to hide the grid's header. Defaults to <code>false</code>.
\r
171 * @cfg {Object} loadMask An {@link Ext.LoadMask} config or true to mask the grid while
\r
172 * loading. Defaults to <code>false</code>.
\r
176 * @cfg {Number} maxHeight Sets the maximum height of the grid - ignored if <tt>autoHeight</tt> is not on.
\r
179 * @cfg {Number} minColumnWidth The minimum width a column can be resized to. Defaults to <tt>25</tt>.
\r
181 minColumnWidth : 25,
\r
183 * @cfg {Object} sm Shorthand for <tt>{@link #selModel}</tt>.
\r
186 * @cfg {Object} selModel Any subclass of {@link Ext.grid.AbstractSelectionModel} that will provide
\r
187 * the selection model for the grid (defaults to {@link Ext.grid.RowSelectionModel} if not specified).
\r
190 * @cfg {Ext.data.Store} store The {@link Ext.data.Store} the grid should use as its data source (required).
\r
193 * @cfg {Boolean} stripeRows <tt>true</tt> to stripe the rows. Default is <tt>false</tt>.
\r
194 * <p>This causes the CSS class <tt><b>x-grid3-row-alt</b></tt> to be added to alternate rows of
\r
195 * the grid. A default CSS rule is provided which sets a background colour, but you can override this
\r
196 * with a rule which either overrides the <b>background-color</b> style using the '!important'
\r
197 * modifier, or which uses a CSS selector of higher specificity.</p>
\r
199 stripeRows : false,
\r
201 * @cfg {Boolean} trackMouseOver True to highlight rows when the mouse is over. Default is <tt>true</tt>
\r
202 * for GridPanel, but <tt>false</tt> for EditorGridPanel.
\r
204 trackMouseOver : true,
\r
206 * @cfg {Array} stateEvents
\r
207 * An array of events that, when fired, should trigger this component to save its state.
\r
208 * Defaults to:<pre><code>
\r
209 * stateEvents: ['columnmove', 'columnresize', 'sortchange']
\r
211 * <p>These can be any types of events supported by this component, including browser or
\r
212 * custom events (e.g., <tt>['click', 'customerchange']</tt>).</p>
\r
213 * <p>See {@link Ext.Component#stateful} for an explanation of saving and restoring
\r
214 * Component state.</p>
\r
216 stateEvents : ['columnmove', 'columnresize', 'sortchange'],
\r
218 * @cfg {Object} view The {@link Ext.grid.GridView} used by the grid. This can be set
\r
219 * before a call to {@link Ext.Component#render render()}.
\r
223 * @cfg {Object} viewConfig A config object that will be applied to the grid's UI view. Any of
\r
224 * the config options available for {@link Ext.grid.GridView} can be specified here. This option
\r
225 * is ignored if <tt>{@link #view}</tt> is specified.
\r
234 initComponent : function(){
\r
235 Ext.grid.GridPanel.superclass.initComponent.call(this);
\r
237 if(this.columnLines){
\r
238 this.cls = (this.cls || '') + ' x-grid-with-col-lines';
\r
240 // override any provided value since it isn't valid
\r
241 // and is causing too many bug reports ;)
\r
242 this.autoScroll = false;
\r
243 this.autoWidth = false;
\r
245 if(Ext.isArray(this.columns)){
\r
246 this.colModel = new Ext.grid.ColumnModel(this.columns);
\r
247 delete this.columns;
\r
250 // check and correct shorthanded configs
\r
252 this.store = this.ds;
\r
256 this.colModel = this.cm;
\r
260 this.selModel = this.sm;
\r
263 this.store = Ext.StoreMgr.lookup(this.store);
\r
269 * The raw click event for the entire grid.
\r
270 * @param {Ext.EventObject} e
\r
275 * The raw dblclick event for the entire grid.
\r
276 * @param {Ext.EventObject} e
\r
280 * @event contextmenu
\r
281 * The raw contextmenu event for the entire grid.
\r
282 * @param {Ext.EventObject} e
\r
287 * The raw mousedown event for the entire grid.
\r
288 * @param {Ext.EventObject} e
\r
293 * The raw mouseup event for the entire grid.
\r
294 * @param {Ext.EventObject} e
\r
299 * The raw mouseover event for the entire grid.
\r
300 * @param {Ext.EventObject} e
\r
305 * The raw mouseout event for the entire grid.
\r
306 * @param {Ext.EventObject} e
\r
311 * The raw keypress event for the entire grid.
\r
312 * @param {Ext.EventObject} e
\r
317 * The raw keydown event for the entire grid.
\r
318 * @param {Ext.EventObject} e
\r
324 * @event cellmousedown
\r
325 * Fires before a cell is clicked
\r
326 * @param {Grid} this
\r
327 * @param {Number} rowIndex
\r
328 * @param {Number} columnIndex
\r
329 * @param {Ext.EventObject} e
\r
333 * @event rowmousedown
\r
334 * Fires before a row is clicked
\r
335 * @param {Grid} this
\r
336 * @param {Number} rowIndex
\r
337 * @param {Ext.EventObject} e
\r
341 * @event headermousedown
\r
342 * Fires before a header is clicked
\r
343 * @param {Grid} this
\r
344 * @param {Number} columnIndex
\r
345 * @param {Ext.EventObject} e
\r
351 * Fires when a cell is clicked.
\r
352 * The data for the cell is drawn from the {@link Ext.data.Record Record}
\r
353 * for this row. To access the data in the listener function use the
\r
354 * following technique:
\r
356 function(grid, rowIndex, columnIndex, e) {
\r
357 var record = grid.getStore().getAt(rowIndex); // Get the Record
\r
358 var fieldName = grid.getColumnModel().getDataIndex(columnIndex); // Get field name
\r
359 var data = record.get(fieldName);
\r
362 * @param {Grid} this
\r
363 * @param {Number} rowIndex
\r
364 * @param {Number} columnIndex
\r
365 * @param {Ext.EventObject} e
\r
369 * @event celldblclick
\r
370 * Fires when a cell is double clicked
\r
371 * @param {Grid} this
\r
372 * @param {Number} rowIndex
\r
373 * @param {Number} columnIndex
\r
374 * @param {Ext.EventObject} e
\r
379 * Fires when a row is clicked
\r
380 * @param {Grid} this
\r
381 * @param {Number} rowIndex
\r
382 * @param {Ext.EventObject} e
\r
386 * @event rowdblclick
\r
387 * Fires when a row is double clicked
\r
388 * @param {Grid} this
\r
389 * @param {Number} rowIndex
\r
390 * @param {Ext.EventObject} e
\r
394 * @event headerclick
\r
395 * Fires when a header is clicked
\r
396 * @param {Grid} this
\r
397 * @param {Number} columnIndex
\r
398 * @param {Ext.EventObject} e
\r
402 * @event headerdblclick
\r
403 * Fires when a header cell is double clicked
\r
404 * @param {Grid} this
\r
405 * @param {Number} columnIndex
\r
406 * @param {Ext.EventObject} e
\r
410 * @event rowcontextmenu
\r
411 * Fires when a row is right clicked
\r
412 * @param {Grid} this
\r
413 * @param {Number} rowIndex
\r
414 * @param {Ext.EventObject} e
\r
418 * @event cellcontextmenu
\r
419 * Fires when a cell is right clicked
\r
420 * @param {Grid} this
\r
421 * @param {Number} rowIndex
\r
422 * @param {Number} cellIndex
\r
423 * @param {Ext.EventObject} e
\r
427 * @event headercontextmenu
\r
428 * Fires when a header is right clicked
\r
429 * @param {Grid} this
\r
430 * @param {Number} columnIndex
\r
431 * @param {Ext.EventObject} e
\r
433 'headercontextmenu',
\r
435 * @event bodyscroll
\r
436 * Fires when the body element is scrolled
\r
437 * @param {Number} scrollLeft
\r
438 * @param {Number} scrollTop
\r
442 * @event columnresize
\r
443 * Fires when the user resizes a column
\r
444 * @param {Number} columnIndex
\r
445 * @param {Number} newSize
\r
449 * @event columnmove
\r
450 * Fires when the user moves a column
\r
451 * @param {Number} oldIndex
\r
452 * @param {Number} newIndex
\r
456 * @event sortchange
\r
457 * Fires when the grid's store sort changes
\r
458 * @param {Grid} this
\r
459 * @param {Object} sortInfo An object with the keys field and direction
\r
463 * @event reconfigure
\r
464 * Fires when the grid is reconfigured with a new store and/or column model.
\r
465 * @param {Grid} this
\r
466 * @param {Ext.data.Store} store The new store
\r
467 * @param {Ext.grid.ColumnModel} colModel The new column model
\r
474 onRender : function(ct, position){
\r
475 Ext.grid.GridPanel.superclass.onRender.apply(this, arguments);
\r
479 this.el.addClass('x-grid-panel');
\r
481 var view = this.getView();
\r
485 mousedown: this.onMouseDown,
\r
486 click: this.onClick,
\r
487 dblclick: this.onDblClick,
\r
488 contextmenu: this.onContextMenu,
\r
489 keydown: this.onKeyDown,
\r
493 this.relayEvents(c, ['mousedown','mouseup','mouseover','mouseout','keypress']);
\r
495 this.getSelectionModel().init(this);
\r
496 this.view.render();
\r
500 initEvents : function(){
\r
501 Ext.grid.GridPanel.superclass.initEvents.call(this);
\r
504 this.loadMask = new Ext.LoadMask(this.bwrap,
\r
505 Ext.apply({store:this.store}, this.loadMask));
\r
509 initStateEvents : function(){
\r
510 Ext.grid.GridPanel.superclass.initStateEvents.call(this);
\r
511 this.mon(this.colModel, 'hiddenchange', this.saveState, this, {delay: 100});
\r
514 applyState : function(state){
\r
515 var cm = this.colModel;
\r
516 var cs = state.columns;
\r
518 for(var i = 0, len = cs.length; i < len; i++){
\r
520 var c = cm.getColumnById(s.id);
\r
522 c.hidden = s.hidden;
\r
524 var oldIndex = cm.getIndexById(s.id);
\r
526 cm.moveColumn(oldIndex, i);
\r
531 if(state.sort && this.store){
\r
532 this.store[this.store.remoteSort ? 'setDefaultSort' : 'sort'](state.sort.field, state.sort.direction);
\r
534 delete state.columns;
\r
536 Ext.grid.GridPanel.superclass.applyState.call(this, state);
\r
539 getState : function(){
\r
540 var o = {columns: []};
\r
541 for(var i = 0, c; (c = this.colModel.config[i]); i++){
\r
547 o.columns[i].hidden = true;
\r
551 var ss = this.store.getSortState();
\r
560 afterRender : function(){
\r
561 Ext.grid.GridPanel.superclass.afterRender.call(this);
\r
562 this.view.layout();
\r
563 if(this.deferRowRender){
\r
564 this.view.afterRender.defer(10, this.view);
\r
566 this.view.afterRender();
\r
568 this.viewReady = true;
\r
572 * <p>Reconfigures the grid to use a different Store and Column Model
\r
573 * and fires the 'reconfigure' event. The View will be bound to the new
\r
574 * objects and refreshed.</p>
\r
575 * <p>Be aware that upon reconfiguring a GridPanel, certain existing settings <i>may</i> become
\r
576 * invalidated. For example the configured {@link #autoExpandColumn} may no longer exist in the
\r
577 * new ColumnModel. Also, an existing {@link Ext.PagingToolbar PagingToolbar} will still be bound
\r
578 * to the old Store, and will need rebinding. Any {@link #plugins} might also need reconfiguring
\r
579 * with the new data.</p>
\r
580 * @param {Ext.data.Store} store The new {@link Ext.data.Store} object
\r
581 * @param {Ext.grid.ColumnModel} colModel The new {@link Ext.grid.ColumnModel} object
\r
583 reconfigure : function(store, colModel){
\r
585 this.loadMask.destroy();
\r
586 this.loadMask = new Ext.LoadMask(this.bwrap,
\r
587 Ext.apply({}, {store:store}, this.initialConfig.loadMask));
\r
589 this.view.initData(store, colModel);
\r
590 this.store = store;
\r
591 this.colModel = colModel;
\r
593 this.view.refresh(true);
\r
595 this.fireEvent('reconfigure', this, store, colModel);
\r
599 onKeyDown : function(e){
\r
600 this.fireEvent('keydown', e);
\r
604 onDestroy : function(){
\r
607 c.removeAllListeners();
\r
609 Ext.destroy(this.view, this.loadMask);
\r
610 }else if(this.store && this.store.autoDestroy){
\r
611 this.store.destroy();
\r
613 Ext.destroy(this.colModel, this.selModel);
\r
614 this.store = this.selModel = this.colModel = this.view = this.loadMask = null;
\r
615 Ext.grid.GridPanel.superclass.onDestroy.call(this);
\r
619 processEvent : function(name, e){
\r
620 this.fireEvent(name, e);
\r
621 var t = e.getTarget();
\r
623 var header = v.findHeaderIndex(t);
\r
624 if(header !== false){
\r
625 this.fireEvent('header' + name, this, header, e);
\r
627 var row = v.findRowIndex(t);
\r
628 var cell = v.findCellIndex(t);
\r
630 this.fireEvent('row' + name, this, row, e);
\r
631 if(cell !== false){
\r
632 this.fireEvent('cell' + name, this, row, cell, e);
\r
639 onClick : function(e){
\r
640 this.processEvent('click', e);
\r
644 onMouseDown : function(e){
\r
645 this.processEvent('mousedown', e);
\r
649 onContextMenu : function(e, t){
\r
650 this.processEvent('contextmenu', e);
\r
654 onDblClick : function(e){
\r
655 this.processEvent('dblclick', e);
\r
659 walkCells : function(row, col, step, fn, scope){
\r
660 var cm = this.colModel, clen = cm.getColumnCount();
\r
661 var ds = this.store, rlen = ds.getCount(), first = true;
\r
673 if(fn.call(scope || this, row, col, cm) === true){
\r
691 if(fn.call(scope || this, row, col, cm) === true){
\r
703 onResize : function(){
\r
704 Ext.grid.GridPanel.superclass.onResize.apply(this, arguments);
\r
705 if(this.viewReady){
\r
706 this.view.layout();
\r
711 * Returns the grid's underlying element.
\r
712 * @return {Element} The element
\r
714 getGridEl : function(){
\r
718 // private for compatibility, overridden by editor grid
\r
719 stopEditing : Ext.emptyFn,
\r
722 * Returns the grid's selection model configured by the <code>{@link #selModel}</code>
\r
723 * configuration option. If no selection model was configured, this will create
\r
724 * and return a {@link Ext.grid.RowSelectionModel RowSelectionModel}.
\r
725 * @return {SelectionModel}
\r
727 getSelectionModel : function(){
\r
728 if(!this.selModel){
\r
729 this.selModel = new Ext.grid.RowSelectionModel(
\r
730 this.disableSelection ? {selectRow: Ext.emptyFn} : null);
\r
732 return this.selModel;
\r
736 * Returns the grid's data store.
\r
737 * @return {Ext.data.Store} The store
\r
739 getStore : function(){
\r
744 * Returns the grid's ColumnModel.
\r
745 * @return {Ext.grid.ColumnModel} The column model
\r
747 getColumnModel : function(){
\r
748 return this.colModel;
\r
752 * Returns the grid's GridView object.
\r
753 * @return {Ext.grid.GridView} The grid view
\r
755 getView : function(){
\r
757 this.view = new Ext.grid.GridView(this.viewConfig);
\r
762 * Called to get grid's drag proxy text, by default returns this.ddText.
\r
763 * @return {String} The text
\r
765 getDragDropText : function(){
\r
766 var count = this.selModel.getCount();
\r
767 return String.format(this.ddText, count, count == 1 ? '' : 's');
\r
771 * @cfg {String/Number} activeItem
\r
775 * @cfg {Boolean} autoDestroy
\r
779 * @cfg {Object/String/Function} autoLoad
\r
783 * @cfg {Boolean} autoWidth
\r
787 * @cfg {Boolean/Number} bufferResize
\r
791 * @cfg {String} defaultType
\r
795 * @cfg {Object} defaults
\r
799 * @cfg {Boolean} hideBorders
\r
803 * @cfg {Mixed} items
\r
807 * @cfg {String} layout
\r
811 * @cfg {Object} layoutConfig
\r
815 * @cfg {Boolean} monitorResize
\r
831 * @method doLayout
\r
843 * @method findById
\r
847 * @method findByType
\r
851 * @method getComponent
\r
855 * @method getLayout
\r
859 * @method getUpdater
\r
879 * @event afterLayout
\r
883 * @event beforeadd
\r
887 * @event beforeremove
\r
898 * @cfg {String} allowDomMove @hide
\r
901 * @cfg {String} autoEl @hide
\r
904 * @cfg {String} applyTo @hide
\r
907 * @cfg {String} autoScroll @hide
\r
910 * @cfg {String} bodyBorder @hide
\r
913 * @cfg {String} bodyStyle @hide
\r
916 * @cfg {String} contentEl @hide
\r
919 * @cfg {String} disabledClass @hide
\r
922 * @cfg {String} elements @hide
\r
925 * @cfg {String} html @hide
\r
928 * @cfg {Boolean} preventBodyReset
\r
932 * @property disabled
\r
936 * @method applyToMarkup
\r
948 * @method setDisabled
\r
952 Ext.reg('grid', Ext.grid.GridPanel);/**
953 * @class Ext.grid.GridView
954 * @extends Ext.util.Observable
955 * <p>This class encapsulates the user interface of an {@link Ext.grid.GridPanel}.
956 * Methods of this class may be used to access user interface elements to enable
957 * special display effects. Do not change the DOM structure of the user interface.</p>
958 * <p>This class does not provide ways to manipulate the underlying data. The data
959 * model of a Grid is held in an {@link Ext.data.Store}.</p>
961 * @param {Object} config
963 Ext.grid.GridView = function(config){
964 Ext.apply(this, config);
965 // These events are only used internally by the grid components
968 * @event beforerowremoved
969 * Internal UI Event. Fired before a row is removed.
970 * @param {Ext.grid.GridView} view
971 * @param {Number} rowIndex The index of the row to be removed.
972 * @param {Ext.data.Record} record The Record to be removed
976 * @event beforerowsinserted
977 * Internal UI Event. Fired before rows are inserted.
978 * @param {Ext.grid.GridView} view
979 * @param {Number} firstRow The index of the first row to be inserted.
980 * @param {Number} lastRow The index of the last row to be inserted.
982 "beforerowsinserted",
984 * @event beforerefresh
985 * Internal UI Event. Fired before the view is refreshed.
986 * @param {Ext.grid.GridView} view
991 * Internal UI Event. Fired after a row is removed.
992 * @param {Ext.grid.GridView} view
993 * @param {Number} rowIndex The index of the row that was removed.
994 * @param {Ext.data.Record} record The Record that was removed
998 * @event rowsinserted
999 * Internal UI Event. Fired after rows are inserted.
1000 * @param {Ext.grid.GridView} view
1001 * @param {Number} firstRow The index of the first inserted.
1002 * @param {Number} lastRow The index of the last row inserted.
1007 * Internal UI Event. Fired after a row has been updated.
1008 * @param {Ext.grid.GridView} view
1009 * @param {Number} firstRow The index of the row updated.
1010 * @param {Ext.data.record} record The Record backing the row updated.
1015 * Internal UI Event. Fired after the GridView's body has been refreshed.
1016 * @param {Ext.grid.GridView} view
1020 Ext.grid.GridView.superclass.constructor.call(this);
1023 Ext.extend(Ext.grid.GridView, Ext.util.Observable, {
1025 * Override this function to apply custom CSS classes to rows during rendering. You can also supply custom
1026 * parameters to the row template for the current row to customize how it is rendered using the <b>rowParams</b>
1027 * parameter. This function should return the CSS class name (or empty string '' for none) that will be added
1028 * to the row's wrapping div. To apply multiple class names, simply return them space-delimited within the string
1029 * (e.g., 'my-class another-class'). Example usage:
1033 showPreview: true, // custom property
1034 enableRowBody: true, // required to create a second, full-width row to show expanded Record data
1035 getRowClass: function(record, rowIndex, rp, ds){ // rp = rowParams
1036 if(this.showPreview){
1037 rp.body = '<p>'+record.data.excerpt+'</p>';
1038 return 'x-grid3-row-expanded';
1040 return 'x-grid3-row-collapsed';
1044 * @param {Record} record The {@link Ext.data.Record} corresponding to the current row.
1045 * @param {Number} index The row index.
1046 * @param {Object} rowParams A config object that is passed to the row template during rendering that allows
1047 * customization of various aspects of a grid row.
1048 * <p>If {@link #enableRowBody} is configured <b><tt></tt>true</b>, then the following properties may be set
1049 * by this function, and will be used to render a full-width expansion row below each grid row:</p>
1051 * <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>
1052 * <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>
1054 * The following property will be passed in, and may be appended to:
1056 * <li><code>tstyle</code> : String <div class="sub-desc">A CSS style specification that willl be applied to the <table> element which encapsulates
1057 * both the standard grid row, and any expansion row.</div></li>
1059 * @param {Store} store The {@link Ext.data.Store} this grid is bound to
1060 * @method getRowClass
1061 * @return {String} a CSS class name to add to the row.
1064 * @cfg {Boolean} enableRowBody True to add a second TR element per row that can be used to provide a row body
1065 * that spans beneath the data row. Use the {@link #getRowClass} method's rowParams config to customize the row body.
1068 * @cfg {String} emptyText Default text (html tags are accepted) to display in the grid body when no rows
1069 * are available (defaults to ''). This value will be used to update the <tt>{@link #mainBody}</tt>:
1071 this.mainBody.update('<div class="x-grid-empty">' + this.emptyText + '</div>');
1075 * @cfg {Boolean} headersDisabled True to disable the grid column headers (defaults to <tt>false</tt>).
1076 * Use the {@link Ext.grid.ColumnModel ColumnModel} <tt>{@link Ext.grid.ColumnModel#menuDisabled menuDisabled}</tt>
1077 * config to disable the <i>menu</i> for individual columns. While this config is true the
1078 * following will be disabled:<div class="mdetail-params"><ul>
1079 * <li>clicking on header to sort</li>
1080 * <li>the trigger to reveal the menu.</li>
1084 * <p>A customized implementation of a {@link Ext.dd.DragZone DragZone} which provides default implementations
1085 * of the template methods of DragZone to enable dragging of the selected rows of a GridPanel.
1086 * See {@link Ext.grid.GridDragZone} for details.</p>
1087 * <p>This will <b>only</b> be present:<div class="mdetail-params"><ul>
1088 * <li><i>if</i> the owning GridPanel was configured with {@link Ext.grid.GridPanel#enableDragDrop enableDragDrop}: <tt>true</tt>.</li>
1089 * <li><i>after</i> the owning GridPanel has been rendered.</li>
1091 * @property dragZone
1092 * @type {Ext.grid.GridDragZone}
1095 * @cfg {Boolean} deferEmptyText True to defer <tt>{@link #emptyText}</tt> being applied until the store's
1096 * first load (defaults to <tt>true</tt>).
1098 deferEmptyText : true,
1100 * @cfg {Number} scrollOffset The amount of space to reserve for the vertical scrollbar
1101 * (defaults to <tt>19</tt> pixels).
1105 * @cfg {Boolean} autoFill
1106 * Defaults to <tt>false</tt>. Specify <tt>true</tt> to have the column widths re-proportioned
1107 * when the grid is <b>initially rendered</b>. The
1108 * {@link Ext.grid.Column#width initially configured width}</tt> of each column will be adjusted
1109 * to fit the grid width and prevent horizontal scrolling. If columns are later resized (manually
1110 * or programmatically), the other columns in the grid will <b>not</b> be resized to fit the grid width.
1111 * See <tt>{@link #forceFit}</tt> also.
1115 * @cfg {Boolean} forceFit
1116 * Defaults to <tt>false</tt>. Specify <tt>true</tt> to have the column widths re-proportioned
1117 * at <b>all times</b>. The {@link Ext.grid.Column#width initially configured width}</tt> of each
1118 * column will be adjusted to fit the grid width and prevent horizontal scrolling. If columns are
1119 * later resized (manually or programmatically), the other columns in the grid <b>will</b> be resized
1120 * to fit the grid width. See <tt>{@link #autoFill}</tt> also.
1124 * @cfg {Array} sortClasses The CSS classes applied to a header when it is sorted. (defaults to <tt>["sort-asc", "sort-desc"]</tt>)
1126 sortClasses : ["sort-asc", "sort-desc"],
1128 * @cfg {String} sortAscText The text displayed in the "Sort Ascending" menu item (defaults to <tt>"Sort Ascending"</tt>)
1130 sortAscText : "Sort Ascending",
1132 * @cfg {String} sortDescText The text displayed in the "Sort Descending" menu item (defaults to <tt>"Sort Descending"</tt>)
1134 sortDescText : "Sort Descending",
1136 * @cfg {String} columnsText The text displayed in the "Columns" menu item (defaults to <tt>"Columns"</tt>)
1138 columnsText : "Columns",
1141 * @cfg {String} selectedRowClass The CSS class applied to a selected row (defaults to <tt>"x-grid3-row-selected"</tt>). An
1142 * example overriding the default styling:
1144 .x-grid3-row-selected {background-color: yellow;}
1146 * Note that this only controls the row, and will not do anything for the text inside it. To style inner
1147 * facets (like text) use something like:
1149 .x-grid3-row-selected .x-grid3-cell-inner {
1155 selectedRowClass : "x-grid3-row-selected",
1159 tdClass : 'x-grid3-cell',
1160 hdCls : 'x-grid3-hd',
1164 * @cfg {Number} cellSelectorDepth The number of levels to search for cells in event delegation (defaults to <tt>4</tt>)
1166 cellSelectorDepth : 4,
1168 * @cfg {Number} rowSelectorDepth The number of levels to search for rows in event delegation (defaults to <tt>10</tt>)
1170 rowSelectorDepth : 10,
1173 * @cfg {String} cellSelector The selector used to find cells internally (defaults to <tt>'td.x-grid3-cell'</tt>)
1175 cellSelector : 'td.x-grid3-cell',
1177 * @cfg {String} rowSelector The selector used to find rows internally (defaults to <tt>'div.x-grid3-row'</tt>)
1179 rowSelector : 'div.x-grid3-row',
1182 firstRowCls: 'x-grid3-row-first',
1183 lastRowCls: 'x-grid3-row-last',
1184 rowClsRe: /(?:^|\s+)x-grid3-row-(first|last|alt)(?:\s+|$)/g,
1186 /* -------------------------------- UI Specific ----------------------------- */
1189 initTemplates : function(){
1190 var ts = this.templates || {};
1192 ts.master = new Ext.Template(
1193 '<div class="x-grid3" hidefocus="true">',
1194 '<div class="x-grid3-viewport">',
1195 '<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>',
1196 '<div class="x-grid3-scroller"><div class="x-grid3-body" style="{bstyle}">{body}</div><a href="#" class="x-grid3-focus" tabIndex="-1"></a></div>',
1198 '<div class="x-grid3-resize-marker"> </div>',
1199 '<div class="x-grid3-resize-proxy"> </div>',
1205 ts.header = new Ext.Template(
1206 '<table border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
1207 '<thead><tr class="x-grid3-hd-row">{cells}</tr></thead>',
1213 ts.hcell = new Ext.Template(
1214 '<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>' : '',
1215 '{value}<img class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
1221 ts.body = new Ext.Template('{rows}');
1225 ts.row = new Ext.Template(
1226 '<div class="x-grid3-row {alt}" style="{tstyle}"><table class="x-grid3-row-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
1227 '<tbody><tr>{cells}</tr>',
1228 (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>' : ''),
1229 '</tbody></table></div>'
1234 ts.cell = new Ext.Template(
1235 '<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} {css}" style="{style}" tabIndex="0" {cellAttr}>',
1236 '<div class="x-grid3-cell-inner x-grid3-col-{id}" unselectable="on" {attr}>{value}</div>',
1243 if(t && typeof t.compile == 'function' && !t.compiled){
1244 t.disableFormats = true;
1249 this.templates = ts;
1250 this.colRe = new RegExp("x-grid3-td-([^\\s]+)", "");
1255 if(!this._flyweight){
1256 this._flyweight = new Ext.Element.Flyweight(document.body);
1258 this._flyweight.dom = el;
1259 return this._flyweight;
1263 getEditorParent : function(){
1264 return this.scroller.dom;
1268 initElements : function(){
1269 var E = Ext.Element;
1271 var el = this.grid.getGridEl().dom.firstChild;
1272 var cs = el.childNodes;
1274 this.el = new E(el);
1276 this.mainWrap = new E(cs[0]);
1277 this.mainHd = new E(this.mainWrap.dom.firstChild);
1279 if(this.grid.hideHeaders){
1280 this.mainHd.setDisplayed(false);
1283 this.innerHd = this.mainHd.dom.firstChild;
1284 this.scroller = new E(this.mainWrap.dom.childNodes[1]);
1286 this.scroller.setStyle('overflow-x', 'hidden');
1289 * <i>Read-only</i>. The GridView's body Element which encapsulates all rows in the Grid.
1290 * This {@link Ext.Element Element} is only available after the GridPanel has been rendered.
1292 * @property mainBody
1294 this.mainBody = new E(this.scroller.dom.firstChild);
1296 this.focusEl = new E(this.scroller.dom.childNodes[1]);
1297 this.focusEl.swallowEvent("click", true);
1299 this.resizeMarker = new E(cs[1]);
1300 this.resizeProxy = new E(cs[2]);
1304 getRows : function(){
1305 return this.hasRows() ? this.mainBody.dom.childNodes : [];
1308 // finder methods, used with delegation
1311 findCell : function(el){
1315 return this.fly(el).findParent(this.cellSelector, this.cellSelectorDepth);
1319 * <p>Return the index of the grid column which contains the passed element.</p>
1320 * See also {@link #findRowIndex}
1321 * @param {Element} el The target element
1322 * @return The column index, or <b>false</b> if the target element is not within a row of this GridView.
1324 findCellIndex : function(el, requiredCls){
1325 var cell = this.findCell(el);
1326 if(cell && (!requiredCls || this.fly(cell).hasClass(requiredCls))){
1327 return this.getCellIndex(cell);
1333 getCellIndex : function(el){
1335 var m = el.className.match(this.colRe);
1337 return this.cm.getIndexById(m[1]);
1344 findHeaderCell : function(el){
1345 var cell = this.findCell(el);
1346 return cell && this.fly(cell).hasClass(this.hdCls) ? cell : null;
1350 findHeaderIndex : function(el){
1351 return this.findCellIndex(el, this.hdCls);
1355 * Return the HtmlElement representing the grid row which contains the passed element.
1356 * @param {Element} el The target element
1357 * @return The row element, or null if the target element is not within a row of this GridView.
1359 findRow : function(el){
1363 return this.fly(el).findParent(this.rowSelector, this.rowSelectorDepth);
1367 * <p>Return the index of the grid row which contains the passed element.</p>
1368 * See also {@link #findCellIndex}
1369 * @param {Element} el The target element
1370 * @return The row index, or <b>false</b> if the target element is not within a row of this GridView.
1372 findRowIndex : function(el){
1373 var r = this.findRow(el);
1374 return r ? r.rowIndex : false;
1377 // getter methods for fetching elements dynamically in the grid
1380 * Return the <tt><div></tt> HtmlElement which represents a Grid row for the specified index.
1381 * @param {Number} index The row index
1382 * @return {HtmlElement} The div element.
1384 getRow : function(row){
1385 return this.getRows()[row];
1389 * Returns the grid's <tt><td></tt> HtmlElement at the specified coordinates.
1390 * @param {Number} row The row index in which to find the cell.
1391 * @param {Number} col The column index of the cell.
1392 * @return {HtmlElement} The td at the specified coordinates.
1394 getCell : function(row, col){
1395 return this.getRow(row).getElementsByTagName('td')[col];
1399 * Return the <tt><td></tt> HtmlElement which represents the Grid's header cell for the specified column index.
1400 * @param {Number} index The column index
1401 * @return {HtmlElement} The td element.
1403 getHeaderCell : function(index){
1404 return this.mainHd.dom.getElementsByTagName('td')[index];
1407 // manipulating elements
1409 // private - use getRowClass to apply custom row classes
1410 addRowClass : function(row, cls){
1411 var r = this.getRow(row);
1413 this.fly(r).addClass(cls);
1418 removeRowClass : function(row, cls){
1419 var r = this.getRow(row);
1421 this.fly(r).removeClass(cls);
1426 removeRow : function(row){
1427 Ext.removeNode(this.getRow(row));
1428 this.syncFocusEl(row);
1432 removeRows : function(firstRow, lastRow){
1433 var bd = this.mainBody.dom;
1434 for(var rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){
1435 Ext.removeNode(bd.childNodes[firstRow]);
1437 this.syncFocusEl(firstRow);
1443 getScrollState : function(){
1444 var sb = this.scroller.dom;
1445 return {left: sb.scrollLeft, top: sb.scrollTop};
1449 restoreScroll : function(state){
1450 var sb = this.scroller.dom;
1451 sb.scrollLeft = state.left;
1452 sb.scrollTop = state.top;
1456 * Scrolls the grid to the top
1458 scrollToTop : function(){
1459 this.scroller.dom.scrollTop = 0;
1460 this.scroller.dom.scrollLeft = 0;
1464 syncScroll : function(){
1465 this.syncHeaderScroll();
1466 var mb = this.scroller.dom;
1467 this.grid.fireEvent("bodyscroll", mb.scrollLeft, mb.scrollTop);
1471 syncHeaderScroll : function(){
1472 var mb = this.scroller.dom;
1473 this.innerHd.scrollLeft = mb.scrollLeft;
1474 this.innerHd.scrollLeft = mb.scrollLeft; // second time for IE (1/2 time first fails, other browsers ignore)
1478 updateSortIcon : function(col, dir){
1479 var sc = this.sortClasses;
1480 var hds = this.mainHd.select('td').removeClass(sc);
1481 hds.item(col).addClass(sc[dir == "DESC" ? 1 : 0]);
1485 updateAllColumnWidths : function(){
1486 var tw = this.getTotalWidth(),
1487 clen = this.cm.getColumnCount(),
1491 for(i = 0; i < clen; i++){
1492 ws[i] = this.getColumnWidth(i);
1494 this.innerHd.firstChild.style.width = this.getOffsetWidth();
1495 this.innerHd.firstChild.firstChild.style.width = tw;
1496 this.mainBody.dom.style.width = tw;
1497 for(i = 0; i < clen; i++){
1498 var hd = this.getHeaderCell(i);
1499 hd.style.width = ws[i];
1502 var ns = this.getRows(), row, trow;
1503 for(i = 0, len = ns.length; i < len; i++){
1505 row.style.width = tw;
1507 row.firstChild.style.width = tw;
1508 trow = row.firstChild.rows[0];
1509 for (var j = 0; j < clen; j++) {
1510 trow.childNodes[j].style.width = ws[j];
1515 this.onAllColumnWidthsUpdated(ws, tw);
1519 updateColumnWidth : function(col, width){
1520 var w = this.getColumnWidth(col);
1521 var tw = this.getTotalWidth();
1522 this.innerHd.firstChild.style.width = this.getOffsetWidth();
1523 this.innerHd.firstChild.firstChild.style.width = tw;
1524 this.mainBody.dom.style.width = tw;
1525 var hd = this.getHeaderCell(col);
1528 var ns = this.getRows(), row;
1529 for(var i = 0, len = ns.length; i < len; i++){
1531 row.style.width = tw;
1533 row.firstChild.style.width = tw;
1534 row.firstChild.rows[0].childNodes[col].style.width = w;
1538 this.onColumnWidthUpdated(col, w, tw);
1542 updateColumnHidden : function(col, hidden){
1543 var tw = this.getTotalWidth();
1544 this.innerHd.firstChild.style.width = this.getOffsetWidth();
1545 this.innerHd.firstChild.firstChild.style.width = tw;
1546 this.mainBody.dom.style.width = tw;
1547 var display = hidden ? 'none' : '';
1549 var hd = this.getHeaderCell(col);
1550 hd.style.display = display;
1552 var ns = this.getRows(), row;
1553 for(var i = 0, len = ns.length; i < len; i++){
1555 row.style.width = tw;
1557 row.firstChild.style.width = tw;
1558 row.firstChild.rows[0].childNodes[col].style.display = display;
1562 this.onColumnHiddenUpdated(col, hidden, tw);
1563 delete this.lastViewWidth; // force recalc
1568 doRender : function(cs, rs, ds, startRow, colCount, stripe){
1569 var ts = this.templates, ct = ts.cell, rt = ts.row, last = colCount-1;
1570 var tstyle = 'width:'+this.getTotalWidth()+';';
1572 var buf = [], cb, c, p = {}, rp = {tstyle: tstyle}, r;
1573 for(var j = 0, len = rs.length; j < len; j++){
1575 var rowIndex = (j+startRow);
1576 for(var i = 0; i < colCount; i++){
1579 p.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
1580 p.attr = p.cellAttr = "";
1581 p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
1583 if(Ext.isEmpty(p.value)){
1586 if(this.markDirty && r.dirty && typeof r.modified[c.name] !== 'undefined'){
1587 p.css += ' x-grid3-dirty-cell';
1589 cb[cb.length] = ct.apply(p);
1592 if(stripe && ((rowIndex+1) % 2 === 0)){
1593 alt[0] = "x-grid3-row-alt";
1596 alt[1] = " x-grid3-dirty-row";
1599 if(this.getRowClass){
1600 alt[2] = this.getRowClass(r, rowIndex, rp, ds);
1602 rp.alt = alt.join(" ");
1603 rp.cells = cb.join("");
1604 buf[buf.length] = rt.apply(rp);
1606 return buf.join("");
1610 processRows : function(startRow, skipStripe){
1611 if(!this.ds || this.ds.getCount() < 1){
1614 var rows = this.getRows();
1615 skipStripe = skipStripe || !this.grid.stripeRows;
1616 startRow = startRow || 0;
1617 Ext.each(rows, function(row, idx){
1619 row.className = row.className.replace(this.rowClsRe, ' ');
1620 if (!skipStripe && (idx + 1) % 2 === 0) {
1621 row.className += ' x-grid3-row-alt';
1624 // add first/last-row classes
1626 Ext.fly(rows[0]).addClass(this.firstRowCls);
1628 Ext.fly(rows[rows.length - 1]).addClass(this.lastRowCls);
1631 afterRender : function(){
1632 if(!this.ds || !this.cm){
1635 this.mainBody.dom.innerHTML = this.renderRows() || ' ';
1636 this.processRows(0, true);
1638 if(this.deferEmptyText !== true){
1639 this.applyEmptyText();
1644 renderUI : function(){
1646 var header = this.renderHeaders();
1647 var body = this.templates.body.apply({rows:' '});
1650 var html = this.templates.master.apply({
1653 ostyle: 'width:'+this.getOffsetWidth()+';',
1654 bstyle: 'width:'+this.getTotalWidth()+';'
1659 g.getGridEl().dom.innerHTML = html;
1661 this.initElements();
1663 // get mousedowns early
1664 Ext.fly(this.innerHd).on("click", this.handleHdDown, this);
1667 mouseover: this.handleHdOver,
1668 mouseout: this.handleHdOut,
1669 mousemove: this.handleHdMove
1672 this.scroller.on('scroll', this.syncScroll, this);
1673 if(g.enableColumnResize !== false){
1674 this.splitZone = new Ext.grid.GridView.SplitDragZone(g, this.mainHd.dom);
1677 if(g.enableColumnMove){
1678 this.columnDrag = new Ext.grid.GridView.ColumnDragZone(g, this.innerHd);
1679 this.columnDrop = new Ext.grid.HeaderDropZone(g, this.mainHd.dom);
1682 if(g.enableHdMenu !== false){
1683 this.hmenu = new Ext.menu.Menu({id: g.id + "-hctx"});
1685 {itemId:"asc", text: this.sortAscText, cls: "xg-hmenu-sort-asc"},
1686 {itemId:"desc", text: this.sortDescText, cls: "xg-hmenu-sort-desc"}
1688 if(g.enableColumnHide !== false){
1689 this.colMenu = new Ext.menu.Menu({id:g.id + "-hcols-menu"});
1692 beforeshow: this.beforeColMenuShow,
1693 itemclick: this.handleHdMenuClick
1695 this.hmenu.add('-', {
1698 text: this.columnsText,
1700 iconCls: 'x-cols-icon'
1703 this.hmenu.on("itemclick", this.handleHdMenuClick, this);
1706 if(g.trackMouseOver){
1709 mouseover: this.onRowOver,
1710 mouseout: this.onRowOut
1714 if(g.enableDragDrop || g.enableDrag){
1715 this.dragZone = new Ext.grid.GridDragZone(g, {
1716 ddGroup : g.ddGroup || 'GridDD'
1720 this.updateHeaderSortState();
1725 layout : function(){
1727 return; // not rendered
1730 var c = g.getGridEl();
1731 var csize = c.getSize(true);
1732 var vw = csize.width;
1734 if(!g.hideHeaders && (vw < 20 || csize.height < 20)){ // display: none?
1739 this.scroller.dom.style.overflow = 'visible';
1741 this.scroller.dom.style.position = 'static';
1744 this.el.setSize(csize.width, csize.height);
1746 var hdHeight = this.mainHd.getHeight();
1747 var vh = csize.height - (hdHeight);
1749 this.scroller.setSize(vw, vh);
1751 this.innerHd.style.width = (vw)+'px';
1755 if(this.lastViewWidth != vw){
1756 this.fitColumns(false, false);
1757 this.lastViewWidth = vw;
1761 this.syncHeaderScroll();
1763 this.onLayout(vw, vh);
1766 // template functions for subclasses and plugins
1767 // these functions include precalculated values
1768 onLayout : function(vw, vh){
1772 onColumnWidthUpdated : function(col, w, tw){
1776 onAllColumnWidthsUpdated : function(ws, tw){
1780 onColumnHiddenUpdated : function(col, hidden, tw){
1784 updateColumnText : function(col, text){
1788 afterMove : function(colIndex){
1792 /* ----------------------------------- Core Specific -------------------------------------------*/
1794 init : function(grid){
1797 this.initTemplates();
1798 this.initData(grid.store, grid.colModel);
1803 getColumnId : function(index){
1804 return this.cm.getColumnId(index);
1808 getOffsetWidth : function() {
1809 return (this.cm.getTotalWidth() + this.scrollOffset) + 'px';
1813 renderHeaders : function(){
1815 ts = this.templates,
1819 len = cm.getColumnCount(),
1822 for(var i = 0; i < len; i++){
1823 p.id = cm.getColumnId(i);
1824 p.value = cm.getColumnHeader(i) || "";
1825 p.style = this.getColumnStyle(i, true);
1826 p.tooltip = this.getColumnTooltip(i);
1827 p.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
1828 if(cm.config[i].align == 'right'){
1829 p.istyle = 'padding-right:16px';
1833 cb[cb.length] = ct.apply(p);
1835 return ts.header.apply({cells: cb.join(""), tstyle:'width:'+this.getTotalWidth()+';'});
1839 getColumnTooltip : function(i){
1840 var tt = this.cm.getColumnTooltip(i);
1842 if(Ext.QuickTips.isEnabled()){
1843 return 'ext:qtip="'+tt+'"';
1845 return 'title="'+tt+'"';
1852 beforeUpdate : function(){
1853 this.grid.stopEditing(true);
1857 updateHeaders : function(){
1858 this.innerHd.firstChild.innerHTML = this.renderHeaders();
1859 this.innerHd.firstChild.style.width = this.getOffsetWidth();
1860 this.innerHd.firstChild.firstChild.style.width = this.getTotalWidth();
1864 * Focuses the specified row.
1865 * @param {Number} row The row index
1867 focusRow : function(row){
1868 this.focusCell(row, 0, false);
1872 * Focuses the specified cell.
1873 * @param {Number} row The row index
1874 * @param {Number} col The column index
1876 focusCell : function(row, col, hscroll){
1877 this.syncFocusEl(this.ensureVisible(row, col, hscroll));
1879 this.focusEl.focus();
1881 this.focusEl.focus.defer(1, this.focusEl);
1885 resolveCell : function(row, col, hscroll){
1886 if(typeof row != "number"){
1892 if(row < 0 || row >= this.ds.getCount()){
1895 col = (col !== undefined ? col : 0);
1897 var rowEl = this.getRow(row),
1899 colCount = cm.getColumnCount(),
1901 if(!(hscroll === false && col === 0)){
1902 while(col < colCount && cm.isHidden(col)){
1905 cellEl = this.getCell(row, col);
1908 return {row: rowEl, cell: cellEl};
1911 getResolvedXY : function(resolved){
1915 var s = this.scroller.dom, c = resolved.cell, r = resolved.row;
1916 return c ? Ext.fly(c).getXY() : [this.el.getX(), Ext.fly(r).getY()];
1919 syncFocusEl : function(row, col, hscroll){
1921 if(!Ext.isArray(xy)){
1922 row = Math.min(row, Math.max(0, this.getRows().length-1));
1923 xy = this.getResolvedXY(this.resolveCell(row, col, hscroll));
1925 this.focusEl.setXY(xy||this.scroller.getXY());
1928 ensureVisible : function(row, col, hscroll){
1929 var resolved = this.resolveCell(row, col, hscroll);
1930 if(!resolved || !resolved.row){
1934 var rowEl = resolved.row,
1935 cellEl = resolved.cell,
1936 c = this.scroller.dom,
1941 while(p && p != stop){
1942 ctop += p.offsetTop;
1945 ctop -= this.mainHd.dom.offsetHeight;
1947 var cbot = ctop + rowEl.offsetHeight,
1948 ch = c.clientHeight,
1951 stop = parseInt(c.scrollTop, 10);
1956 }else if(cbot > sbot){
1957 c.scrollTop = cbot-ch;
1960 if(hscroll !== false){
1961 var cleft = parseInt(cellEl.offsetLeft, 10);
1962 var cright = cleft + cellEl.offsetWidth;
1964 var sleft = parseInt(c.scrollLeft, 10);
1965 var sright = sleft + c.clientWidth;
1967 c.scrollLeft = cleft;
1968 }else if(cright > sright){
1969 c.scrollLeft = cright-c.clientWidth;
1972 return this.getResolvedXY(resolved);
1976 insertRows : function(dm, firstRow, lastRow, isUpdate){
1977 var last = dm.getCount() - 1;
1978 if(!isUpdate && firstRow === 0 && lastRow >= last){
1982 this.fireEvent("beforerowsinserted", this, firstRow, lastRow);
1984 var html = this.renderRows(firstRow, lastRow),
1985 before = this.getRow(firstRow);
1988 Ext.fly(this.getRow(0)).removeClass(this.firstRowCls);
1990 Ext.DomHelper.insertHtml('beforeBegin', before, html);
1992 var r = this.getRow(last - 1);
1994 Ext.fly(r).removeClass(this.lastRowCls);
1996 Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html);
1999 this.fireEvent("rowsinserted", this, firstRow, lastRow);
2000 this.processRows(firstRow);
2001 }else if(firstRow === 0 || firstRow >= last){
2002 //ensure first/last row is kept after an update.
2003 Ext.fly(this.getRow(firstRow)).addClass(firstRow === 0 ? this.firstRowCls : this.lastRowCls);
2006 this.syncFocusEl(firstRow);
2010 deleteRows : function(dm, firstRow, lastRow){
2011 if(dm.getRowCount()<1){
2014 this.fireEvent("beforerowsdeleted", this, firstRow, lastRow);
2016 this.removeRows(firstRow, lastRow);
2018 this.processRows(firstRow);
2019 this.fireEvent("rowsdeleted", this, firstRow, lastRow);
2024 getColumnStyle : function(col, isHeader){
2025 var style = !isHeader ? (this.cm.config[col].css || '') : '';
2026 style += 'width:'+this.getColumnWidth(col)+';';
2027 if(this.cm.isHidden(col)){
2028 style += 'display:none;';
2030 var align = this.cm.config[col].align;
2032 style += 'text-align:'+align+';';
2038 getColumnWidth : function(col){
2039 var w = this.cm.getColumnWidth(col);
2040 if(typeof w == 'number'){
2041 return (Ext.isBorderBox ? w : (w-this.borderWidth > 0 ? w-this.borderWidth:0)) + 'px';
2047 getTotalWidth : function(){
2048 return this.cm.getTotalWidth()+'px';
2052 fitColumns : function(preventRefresh, onlyExpand, omitColumn){
2053 var cm = this.cm, i;
2054 var tw = cm.getTotalWidth(false);
2055 var aw = this.grid.getGridEl().getWidth(true)-this.scrollOffset;
2057 if(aw < 20){ // not initialized, so don't screw up the default widths
2060 var extra = aw - tw;
2066 var vc = cm.getColumnCount(true);
2067 var ac = vc-(typeof omitColumn == 'number' ? 1 : 0);
2070 omitColumn = undefined;
2072 var colCount = cm.getColumnCount();
2077 for (i = 0; i < colCount; i++){
2078 if(!cm.isHidden(i) && !cm.isFixed(i) && i !== omitColumn){
2079 w = cm.getColumnWidth(i);
2086 var frac = (aw - cm.getTotalWidth())/width;
2087 while (cols.length){
2090 cm.setColumnWidth(i, Math.max(this.grid.minColumnWidth, Math.floor(w + w*frac)), true);
2093 if((tw = cm.getTotalWidth(false)) > aw){
2094 var adjustCol = ac != vc ? omitColumn : extraCol;
2095 cm.setColumnWidth(adjustCol, Math.max(1,
2096 cm.getColumnWidth(adjustCol)- (tw-aw)), true);
2099 if(preventRefresh !== true){
2100 this.updateAllColumnWidths();
2108 autoExpand : function(preventUpdate){
2109 var g = this.grid, cm = this.cm;
2110 if(!this.userResized && g.autoExpandColumn){
2111 var tw = cm.getTotalWidth(false);
2112 var aw = this.grid.getGridEl().getWidth(true)-this.scrollOffset;
2114 var ci = cm.getIndexById(g.autoExpandColumn);
2115 var currentWidth = cm.getColumnWidth(ci);
2116 var cw = Math.min(Math.max(((aw-tw)+currentWidth), g.autoExpandMin), g.autoExpandMax);
2117 if(cw != currentWidth){
2118 cm.setColumnWidth(ci, cw, true);
2119 if(preventUpdate !== true){
2120 this.updateColumnWidth(ci, cw);
2128 getColumnData : function(){
2129 // build a map for all the columns
2130 var cs = [], cm = this.cm, colCount = cm.getColumnCount();
2131 for(var i = 0; i < colCount; i++){
2132 var name = cm.getDataIndex(i);
2134 name : (typeof name == 'undefined' ? this.ds.fields.get(i).name : name),
2135 renderer : cm.getRenderer(i),
2136 id : cm.getColumnId(i),
2137 style : this.getColumnStyle(i)
2144 renderRows : function(startRow, endRow){
2145 // pull in all the crap needed to render rows
2146 var g = this.grid, cm = g.colModel, ds = g.store, stripe = g.stripeRows;
2147 var colCount = cm.getColumnCount();
2149 if(ds.getCount() < 1){
2153 var cs = this.getColumnData();
2155 startRow = startRow || 0;
2156 endRow = typeof endRow == "undefined"? ds.getCount()-1 : endRow;
2158 // records to render
2159 var rs = ds.getRange(startRow, endRow);
2161 return this.doRender(cs, rs, ds, startRow, colCount, stripe);
2165 renderBody : function(){
2166 var markup = this.renderRows() || ' ';
2167 return this.templates.body.apply({rows: markup});
2171 refreshRow : function(record){
2172 var ds = this.ds, index;
2173 if(typeof record == 'number'){
2175 record = ds.getAt(index);
2180 index = ds.indexOf(record);
2185 this.insertRows(ds, index, index, true);
2186 this.getRow(index).rowIndex = index;
2187 this.onRemove(ds, record, index+1, true);
2188 this.fireEvent("rowupdated", this, index, record);
2192 * Refreshs the grid UI
2193 * @param {Boolean} headersToo (optional) True to also refresh the headers
2195 refresh : function(headersToo){
2196 this.fireEvent("beforerefresh", this);
2197 this.grid.stopEditing(true);
2199 var result = this.renderBody();
2200 this.mainBody.update(result).setWidth(this.getTotalWidth());
2201 if(headersToo === true){
2202 this.updateHeaders();
2203 this.updateHeaderSortState();
2205 this.processRows(0, true);
2207 this.applyEmptyText();
2208 this.fireEvent("refresh", this);
2212 applyEmptyText : function(){
2213 if(this.emptyText && !this.hasRows()){
2214 this.mainBody.update('<div class="x-grid-empty">' + this.emptyText + '</div>');
2219 updateHeaderSortState : function(){
2220 var state = this.ds.getSortState();
2224 if(!this.sortState || (this.sortState.field != state.field || this.sortState.direction != state.direction)){
2225 this.grid.fireEvent('sortchange', this.grid, state);
2227 this.sortState = state;
2228 var sortColumn = this.cm.findColumnIndex(state.field);
2229 if(sortColumn != -1){
2230 var sortDir = state.direction;
2231 this.updateSortIcon(sortColumn, sortDir);
2236 destroy : function(){
2238 Ext.menu.MenuMgr.unregister(this.colMenu);
2239 this.colMenu.destroy();
2240 delete this.colMenu;
2243 Ext.menu.MenuMgr.unregister(this.hmenu);
2244 this.hmenu.destroy();
2247 if(this.grid.enableColumnMove){
2248 var dds = Ext.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id];
2251 if(!dds[dd].config.isTarget && dds[dd].dragElId){
2252 var elid = dds[dd].dragElId;
2254 Ext.get(elid).remove();
2255 } else if(dds[dd].config.isTarget){
2256 dds[dd].proxyTop.remove();
2257 dds[dd].proxyBottom.remove();
2260 if(Ext.dd.DDM.locationCache[dd]){
2261 delete Ext.dd.DDM.locationCache[dd];
2264 delete Ext.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id];
2269 this.dragZone.unreg();
2272 Ext.fly(this.innerHd).removeAllListeners();
2273 Ext.removeNode(this.innerHd);
2275 Ext.destroy(this.resizeMarker, this.resizeProxy, this.focusEl, this.mainBody,
2276 this.scroller, this.mainHd, this.mainWrap, this.dragZone,
2277 this.splitZone, this.columnDrag, this.columnDrop);
2279 this.initData(null, null);
2280 Ext.EventManager.removeResizeListener(this.onWindowResize, this);
2281 this.purgeListeners();
2285 onDenyColumnHide : function(){
2290 render : function(){
2292 var ct = this.grid.ownerCt;
2293 if (ct && ct.getLayout()){
2294 ct.on('afterlayout', function(){
2295 this.fitColumns(true, true);
2296 this.updateHeaders();
2297 }, this, {single: true});
2299 this.fitColumns(true, true);
2301 }else if(this.forceFit){
2302 this.fitColumns(true, false);
2303 }else if(this.grid.autoExpandColumn){
2304 this.autoExpand(true);
2310 /* --------------------------------- Model Events and Handlers --------------------------------*/
2312 initData : function(ds, cm){
2314 this.ds.un("load", this.onLoad, this);
2315 this.ds.un("datachanged", this.onDataChange, this);
2316 this.ds.un("add", this.onAdd, this);
2317 this.ds.un("remove", this.onRemove, this);
2318 this.ds.un("update", this.onUpdate, this);
2319 this.ds.un("clear", this.onClear, this);
2320 if(this.ds !== ds && this.ds.autoDestroy){
2328 datachanged: this.onDataChange,
2330 remove: this.onRemove,
2331 update: this.onUpdate,
2338 this.cm.un("configchange", this.onColConfigChange, this);
2339 this.cm.un("widthchange", this.onColWidthChange, this);
2340 this.cm.un("headerchange", this.onHeaderChange, this);
2341 this.cm.un("hiddenchange", this.onHiddenChange, this);
2342 this.cm.un("columnmoved", this.onColumnMove, this);
2345 delete this.lastViewWidth;
2348 configchange: this.onColConfigChange,
2349 widthchange: this.onColWidthChange,
2350 headerchange: this.onHeaderChange,
2351 hiddenchange: this.onHiddenChange,
2352 columnmoved: this.onColumnMove
2359 onDataChange : function(){
2361 this.updateHeaderSortState();
2362 this.syncFocusEl(0);
2366 onClear : function(){
2368 this.syncFocusEl(0);
2372 onUpdate : function(ds, record){
2373 this.refreshRow(record);
2377 onAdd : function(ds, records, index){
2378 this.insertRows(ds, index, index + (records.length-1));
2382 onRemove : function(ds, record, index, isUpdate){
2383 if(isUpdate !== true){
2384 this.fireEvent("beforerowremoved", this, index, record);
2386 this.removeRow(index);
2387 if(isUpdate !== true){
2388 this.processRows(index);
2389 this.applyEmptyText();
2390 this.fireEvent("rowremoved", this, index, record);
2395 onLoad : function(){
2400 onColWidthChange : function(cm, col, width){
2401 this.updateColumnWidth(col, width);
2405 onHeaderChange : function(cm, col, text){
2406 this.updateHeaders();
2410 onHiddenChange : function(cm, col, hidden){
2411 this.updateColumnHidden(col, hidden);
2415 onColumnMove : function(cm, oldIndex, newIndex){
2416 this.indexMap = null;
2417 var s = this.getScrollState();
2419 this.restoreScroll(s);
2420 this.afterMove(newIndex);
2421 this.grid.fireEvent('columnmove', oldIndex, newIndex);
2425 onColConfigChange : function(){
2426 delete this.lastViewWidth;
2427 this.indexMap = null;
2431 /* -------------------- UI Events and Handlers ------------------------------ */
2433 initUI : function(grid){
2434 grid.on("headerclick", this.onHeaderClick, this);
2438 initEvents : function(){
2442 onHeaderClick : function(g, index){
2443 if(this.headersDisabled || !this.cm.isSortable(index)){
2446 g.stopEditing(true);
2447 g.store.sort(this.cm.getDataIndex(index));
2451 onRowOver : function(e, t){
2453 if((row = this.findRowIndex(t)) !== false){
2454 this.addRowClass(row, "x-grid3-row-over");
2459 onRowOut : function(e, t){
2461 if((row = this.findRowIndex(t)) !== false && !e.within(this.getRow(row), true)){
2462 this.removeRowClass(row, "x-grid3-row-over");
2467 handleWheel : function(e){
2468 e.stopPropagation();
2472 onRowSelect : function(row){
2473 this.addRowClass(row, this.selectedRowClass);
2477 onRowDeselect : function(row){
2478 this.removeRowClass(row, this.selectedRowClass);
2482 onCellSelect : function(row, col){
2483 var cell = this.getCell(row, col);
2485 this.fly(cell).addClass("x-grid3-cell-selected");
2490 onCellDeselect : function(row, col){
2491 var cell = this.getCell(row, col);
2493 this.fly(cell).removeClass("x-grid3-cell-selected");
2498 onColumnSplitterMoved : function(i, w){
2499 this.userResized = true;
2500 var cm = this.grid.colModel;
2501 cm.setColumnWidth(i, w, true);
2504 this.fitColumns(true, false, i);
2505 this.updateAllColumnWidths();
2507 this.updateColumnWidth(i, w);
2508 this.syncHeaderScroll();
2511 this.grid.fireEvent("columnresize", i, w);
2515 handleHdMenuClick : function(item){
2516 var index = this.hdCtxIndex;
2517 var cm = this.cm, ds = this.ds;
2518 switch(item.itemId){
2520 ds.sort(cm.getDataIndex(index), "ASC");
2523 ds.sort(cm.getDataIndex(index), "DESC");
2526 index = cm.getIndexById(item.itemId.substr(4));
2528 if(item.checked && cm.getColumnsBy(this.isHideableColumn, this).length <= 1){
2529 this.onDenyColumnHide();
2532 cm.setHidden(index, item.checked);
2539 isHideableColumn : function(c){
2540 return !c.hidden && !c.fixed;
2544 beforeColMenuShow : function(){
2545 var cm = this.cm, colCount = cm.getColumnCount();
2546 this.colMenu.removeAll();
2547 for(var i = 0; i < colCount; i++){
2548 if(cm.config[i].fixed !== true && cm.config[i].hideable !== false){
2549 this.colMenu.add(new Ext.menu.CheckItem({
2550 itemId: "col-"+cm.getColumnId(i),
2551 text: cm.getColumnHeader(i),
2552 checked: !cm.isHidden(i),
2554 disabled: cm.config[i].hideable === false
2561 handleHdDown : function(e, t){
2562 if(Ext.fly(t).hasClass('x-grid3-hd-btn')){
2564 var hd = this.findHeaderCell(t);
2565 Ext.fly(hd).addClass('x-grid3-hd-menu-open');
2566 var index = this.getCellIndex(hd);
2567 this.hdCtxIndex = index;
2568 var ms = this.hmenu.items, cm = this.cm;
2569 ms.get("asc").setDisabled(!cm.isSortable(index));
2570 ms.get("desc").setDisabled(!cm.isSortable(index));
2571 this.hmenu.on("hide", function(){
2572 Ext.fly(hd).removeClass('x-grid3-hd-menu-open');
2573 }, this, {single:true});
2574 this.hmenu.show(t, "tl-bl?");
2579 handleHdOver : function(e, t){
2580 var hd = this.findHeaderCell(t);
2581 if(hd && !this.headersDisabled){
2583 this.activeHdIndex = this.getCellIndex(hd);
2584 var fly = this.fly(hd);
2585 this.activeHdRegion = fly.getRegion();
2586 if(!this.cm.isMenuDisabled(this.activeHdIndex)){
2587 fly.addClass("x-grid3-hd-over");
2588 this.activeHdBtn = fly.child('.x-grid3-hd-btn');
2589 if(this.activeHdBtn){
2590 this.activeHdBtn.dom.style.height = (hd.firstChild.offsetHeight-1)+'px';
2597 handleHdMove : function(e, t){
2598 if(this.activeHd && !this.headersDisabled){
2599 var hw = this.splitHandleWidth || 5;
2600 var r = this.activeHdRegion;
2601 var x = e.getPageX();
2602 var ss = this.activeHd.style;
2603 if(x - r.left <= hw && this.cm.isResizable(this.activeHdIndex-1)){
2604 ss.cursor = Ext.isAir ? 'move' : Ext.isWebKit ? 'e-resize' : 'col-resize'; // col-resize not always supported
2605 }else if(r.right - x <= (!this.activeHdBtn ? hw : 2) && this.cm.isResizable(this.activeHdIndex)){
2606 ss.cursor = Ext.isAir ? 'move' : Ext.isWebKit ? 'w-resize' : 'col-resize';
2614 handleHdOut : function(e, t){
2615 var hd = this.findHeaderCell(t);
2616 if(hd && (!Ext.isIE || !e.within(hd, true))){
2617 this.activeHd = null;
2618 this.fly(hd).removeClass("x-grid3-hd-over");
2619 hd.style.cursor = '';
2624 hasRows : function(){
2625 var fc = this.mainBody.dom.firstChild;
2626 return fc && fc.nodeType == 1 && fc.className != 'x-grid-empty';
2630 bind : function(d, c){
2631 this.initData(d, c);
2637 // This is a support class used internally by the Grid components
2638 Ext.grid.GridView.SplitDragZone = function(grid, hd){
2640 this.view = grid.getView();
2641 this.marker = this.view.resizeMarker;
2642 this.proxy = this.view.resizeProxy;
2643 Ext.grid.GridView.SplitDragZone.superclass.constructor.call(this, hd,
2644 "gridSplitters" + this.grid.getGridEl().id, {
2645 dragElId : Ext.id(this.proxy.dom), resizeFrame:false
2647 this.scroll = false;
2648 this.hw = this.view.splitHandleWidth || 5;
2650 Ext.extend(Ext.grid.GridView.SplitDragZone, Ext.dd.DDProxy, {
2652 b4StartDrag : function(x, y){
2653 this.view.headersDisabled = true;
2654 var h = this.view.mainWrap.getHeight();
2655 this.marker.setHeight(h);
2657 this.marker.alignTo(this.view.getHeaderCell(this.cellIndex), 'tl-tl', [-2, 0]);
2658 this.proxy.setHeight(h);
2659 var w = this.cm.getColumnWidth(this.cellIndex);
2660 var minw = Math.max(w-this.grid.minColumnWidth, 0);
2661 this.resetConstraints();
2662 this.setXConstraint(minw, 1000);
2663 this.setYConstraint(0, 0);
2664 this.minX = x - minw;
2665 this.maxX = x + 1000;
2667 Ext.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
2671 handleMouseDown : function(e){
2672 var t = this.view.findHeaderCell(e.getTarget());
2674 var xy = this.view.fly(t).getXY(), x = xy[0], y = xy[1];
2675 var exy = e.getXY(), ex = exy[0];
2676 var w = t.offsetWidth, adjust = false;
2677 if((ex - x) <= this.hw){
2679 }else if((x+w) - ex <= this.hw){
2682 if(adjust !== false){
2683 this.cm = this.grid.colModel;
2684 var ci = this.view.getCellIndex(t);
2686 if (ci + adjust < 0) {
2689 while(this.cm.isHidden(ci+adjust)){
2696 this.cellIndex = ci+adjust;
2698 if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
2699 Ext.grid.GridView.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
2701 }else if(this.view.columnDrag){
2702 this.view.columnDrag.callHandleMouseDown(e);
2707 endDrag : function(e){
2710 var endX = Math.max(this.minX, e.getPageX());
2711 var diff = endX - this.startPos;
2712 v.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
2713 setTimeout(function(){
2714 v.headersDisabled = false;
2718 autoOffset : function(){
2723 // This is a support class used internally by the Grid components
\r
2724 Ext.grid.HeaderDragZone = function(grid, hd, hd2){
\r
2726 this.view = grid.getView();
\r
2727 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
\r
2728 Ext.grid.HeaderDragZone.superclass.constructor.call(this, hd);
\r
2730 this.setHandleElId(Ext.id(hd));
\r
2731 this.setOuterHandleElId(Ext.id(hd2));
\r
2733 this.scroll = false;
\r
2735 Ext.extend(Ext.grid.HeaderDragZone, Ext.dd.DragZone, {
\r
2736 maxDragWidth: 120,
\r
2737 getDragData : function(e){
\r
2738 var t = Ext.lib.Event.getTarget(e);
\r
2739 var h = this.view.findHeaderCell(t);
\r
2741 return {ddel: h.firstChild, header:h};
\r
2746 onInitDrag : function(e){
\r
2747 this.view.headersDisabled = true;
\r
2748 var clone = this.dragData.ddel.cloneNode(true);
\r
2749 clone.id = Ext.id();
\r
2750 clone.style.width = Math.min(this.dragData.header.offsetWidth,this.maxDragWidth) + "px";
\r
2751 this.proxy.update(clone);
\r
2755 afterValidDrop : function(){
\r
2756 var v = this.view;
\r
2757 setTimeout(function(){
\r
2758 v.headersDisabled = false;
\r
2762 afterInvalidDrop : function(){
\r
2763 var v = this.view;
\r
2764 setTimeout(function(){
\r
2765 v.headersDisabled = false;
\r
2771 // This is a support class used internally by the Grid components
\r
2772 Ext.grid.HeaderDropZone = function(grid, hd, hd2){
\r
2774 this.view = grid.getView();
\r
2775 // split the proxies so they don't interfere with mouse events
\r
2776 this.proxyTop = Ext.DomHelper.append(document.body, {
\r
2777 cls:"col-move-top", html:" "
\r
2779 this.proxyBottom = Ext.DomHelper.append(document.body, {
\r
2780 cls:"col-move-bottom", html:" "
\r
2782 this.proxyTop.hide = this.proxyBottom.hide = function(){
\r
2783 this.setLeftTop(-100,-100);
\r
2784 this.setStyle("visibility", "hidden");
\r
2786 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
\r
2787 // temporarily disabled
\r
2788 //Ext.dd.ScrollManager.register(this.view.scroller.dom);
\r
2789 Ext.grid.HeaderDropZone.superclass.constructor.call(this, grid.getGridEl().dom);
\r
2791 Ext.extend(Ext.grid.HeaderDropZone, Ext.dd.DropZone, {
\r
2792 proxyOffsets : [-4, -9],
\r
2793 fly: Ext.Element.fly,
\r
2795 getTargetFromEvent : function(e){
\r
2796 var t = Ext.lib.Event.getTarget(e);
\r
2797 var cindex = this.view.findCellIndex(t);
\r
2798 if(cindex !== false){
\r
2799 return this.view.getHeaderCell(cindex);
\r
2803 nextVisible : function(h){
\r
2804 var v = this.view, cm = this.grid.colModel;
\r
2805 h = h.nextSibling;
\r
2807 if(!cm.isHidden(v.getCellIndex(h))){
\r
2810 h = h.nextSibling;
\r
2815 prevVisible : function(h){
\r
2816 var v = this.view, cm = this.grid.colModel;
\r
2817 h = h.prevSibling;
\r
2819 if(!cm.isHidden(v.getCellIndex(h))){
\r
2822 h = h.prevSibling;
\r
2827 positionIndicator : function(h, n, e){
\r
2828 var x = Ext.lib.Event.getPageX(e);
\r
2829 var r = Ext.lib.Dom.getRegion(n.firstChild);
\r
2830 var px, pt, py = r.top + this.proxyOffsets[1];
\r
2831 if((r.right - x) <= (r.right-r.left)/2){
\r
2832 px = r.right+this.view.borderWidth;
\r
2839 if(this.grid.colModel.isFixed(this.view.getCellIndex(n))){
\r
2843 px += this.proxyOffsets[0];
\r
2844 this.proxyTop.setLeftTop(px, py);
\r
2845 this.proxyTop.show();
\r
2846 if(!this.bottomOffset){
\r
2847 this.bottomOffset = this.view.mainHd.getHeight();
\r
2849 this.proxyBottom.setLeftTop(px, py+this.proxyTop.dom.offsetHeight+this.bottomOffset);
\r
2850 this.proxyBottom.show();
\r
2854 onNodeEnter : function(n, dd, e, data){
\r
2855 if(data.header != n){
\r
2856 this.positionIndicator(data.header, n, e);
\r
2860 onNodeOver : function(n, dd, e, data){
\r
2861 var result = false;
\r
2862 if(data.header != n){
\r
2863 result = this.positionIndicator(data.header, n, e);
\r
2866 this.proxyTop.hide();
\r
2867 this.proxyBottom.hide();
\r
2869 return result ? this.dropAllowed : this.dropNotAllowed;
\r
2872 onNodeOut : function(n, dd, e, data){
\r
2873 this.proxyTop.hide();
\r
2874 this.proxyBottom.hide();
\r
2877 onNodeDrop : function(n, dd, e, data){
\r
2878 var h = data.header;
\r
2880 var cm = this.grid.colModel;
\r
2881 var x = Ext.lib.Event.getPageX(e);
\r
2882 var r = Ext.lib.Dom.getRegion(n.firstChild);
\r
2883 var pt = (r.right - x) <= ((r.right-r.left)/2) ? "after" : "before";
\r
2884 var oldIndex = this.view.getCellIndex(h);
\r
2885 var newIndex = this.view.getCellIndex(n);
\r
2886 if(pt == "after"){
\r
2889 if(oldIndex < newIndex){
\r
2892 cm.moveColumn(oldIndex, newIndex);
\r
2893 this.grid.fireEvent("columnmove", oldIndex, newIndex);
\r
2901 Ext.grid.GridView.ColumnDragZone = function(grid, hd){
\r
2902 Ext.grid.GridView.ColumnDragZone.superclass.constructor.call(this, grid, hd, null);
\r
2903 this.proxy.el.addClass('x-grid3-col-dd');
\r
2906 Ext.extend(Ext.grid.GridView.ColumnDragZone, Ext.grid.HeaderDragZone, {
\r
2907 handleMouseDown : function(e){
\r
2911 callHandleMouseDown : function(e){
\r
2912 Ext.grid.GridView.ColumnDragZone.superclass.handleMouseDown.call(this, e);
\r
2915 // This is a support class used internally by the Grid components
2916 Ext.grid.SplitDragZone = function(grid, hd, hd2){
2918 this.view = grid.getView();
2919 this.proxy = this.view.resizeProxy;
2920 Ext.grid.SplitDragZone.superclass.constructor.call(this, hd,
2921 "gridSplitters" + this.grid.getGridEl().id, {
2922 dragElId : Ext.id(this.proxy.dom), resizeFrame:false
2924 this.setHandleElId(Ext.id(hd));
2925 this.setOuterHandleElId(Ext.id(hd2));
2926 this.scroll = false;
2928 Ext.extend(Ext.grid.SplitDragZone, Ext.dd.DDProxy, {
2929 fly: Ext.Element.fly,
2931 b4StartDrag : function(x, y){
2932 this.view.headersDisabled = true;
2933 this.proxy.setHeight(this.view.mainWrap.getHeight());
2934 var w = this.cm.getColumnWidth(this.cellIndex);
2935 var minw = Math.max(w-this.grid.minColumnWidth, 0);
2936 this.resetConstraints();
2937 this.setXConstraint(minw, 1000);
2938 this.setYConstraint(0, 0);
2939 this.minX = x - minw;
2940 this.maxX = x + 1000;
2942 Ext.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
2946 handleMouseDown : function(e){
2947 var ev = Ext.EventObject.setEvent(e);
2948 var t = this.fly(ev.getTarget());
2949 if(t.hasClass("x-grid-split")){
2950 this.cellIndex = this.view.getCellIndex(t.dom);
2952 this.cm = this.grid.colModel;
2953 if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
2954 Ext.grid.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
2959 endDrag : function(e){
2960 this.view.headersDisabled = false;
2961 var endX = Math.max(this.minX, Ext.lib.Event.getPageX(e));
2962 var diff = endX - this.startPos;
2963 this.view.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
2966 autoOffset : function(){
2970 * @class Ext.grid.GridDragZone
2971 * @extends Ext.dd.DragZone
2972 * <p>A customized implementation of a {@link Ext.dd.DragZone DragZone} which provides default implementations of two of the
2973 * template methods of DragZone to enable dragging of the selected rows of a GridPanel.</p>
2974 * <p>A cooperating {@link Ext.dd.DropZone DropZone} must be created who's template method implementations of
2975 * {@link Ext.dd.DropZone#onNodeEnter onNodeEnter}, {@link Ext.dd.DropZone#onNodeOver onNodeOver},
2976 * {@link Ext.dd.DropZone#onNodeOut onNodeOut} and {@link Ext.dd.DropZone#onNodeDrop onNodeDrop}</p> are able
2977 * to process the {@link #getDragData data} which is provided.
2979 Ext.grid.GridDragZone = function(grid, config){
2980 this.view = grid.getView();
2981 Ext.grid.GridDragZone.superclass.constructor.call(this, this.view.mainBody.dom, config);
2982 this.scroll = false;
2984 this.ddel = document.createElement('div');
2985 this.ddel.className = 'x-grid-dd-wrap';
2988 Ext.extend(Ext.grid.GridDragZone, Ext.dd.DragZone, {
2992 * <p>The provided implementation of the getDragData method which collects the data to be dragged from the GridPanel on mousedown.</p>
2993 * <p>This data is available for processing in the {@link Ext.dd.DropZone#onNodeEnter onNodeEnter}, {@link Ext.dd.DropZone#onNodeOver onNodeOver},
2994 * {@link Ext.dd.DropZone#onNodeOut onNodeOut} and {@link Ext.dd.DropZone#onNodeDrop onNodeDrop} methods of a cooperating {@link Ext.dd.DropZone DropZone}.</p>
2995 * <p>The data object contains the following properties:<ul>
2996 * <li><b>grid</b> : Ext.Grid.GridPanel<div class="sub-desc">The GridPanel from which the data is being dragged.</div></li>
2997 * <li><b>ddel</b> : htmlElement<div class="sub-desc">An htmlElement which provides the "picture" of the data being dragged.</div></li>
2998 * <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>
2999 * <li><b>selections</b> : Array<div class="sub-desc">An Array of the selected Records which are being dragged from the GridPanel.</div></li>
3002 getDragData : function(e){
3003 var t = Ext.lib.Event.getTarget(e);
3004 var rowIndex = this.view.findRowIndex(t);
3005 if(rowIndex !== false){
3006 var sm = this.grid.selModel;
3007 if(!sm.isSelected(rowIndex) || e.hasModifier()){
3008 sm.handleMouseDown(this.grid, rowIndex, e);
3010 return {grid: this.grid, ddel: this.ddel, rowIndex: rowIndex, selections:sm.getSelections()};
3016 * <p>The provided implementation of the onInitDrag method. Sets the <tt>innerHTML</tt> of the drag proxy which provides the "picture"
3017 * of the data being dragged.</p>
3018 * <p>The <tt>innerHTML</tt> data is found by calling the owning GridPanel's {@link Ext.grid.GridPanel#getDragDropText getDragDropText}.</p>
3020 onInitDrag : function(e){
3021 var data = this.dragData;
3022 this.ddel.innerHTML = this.grid.getDragDropText();
3023 this.proxy.update(this.ddel);
3028 * An empty immplementation. Implement this to provide behaviour after a repair of an invalid drop. An implementation might highlight
3029 * the selected rows to show that they have not been dragged.
3031 afterRepair : function(){
3032 this.dragging = false;
3036 * <p>An empty implementation. Implement this to provide coordinates for the drag proxy to slide back to after an invalid drop.</p>
3037 * <p>Called before a repair of an invalid drop to get the XY to animate to.</p>
3038 * @param {EventObject} e The mouse up event
3039 * @return {Array} The xy location (e.g. [100, 200])
3041 getRepairXY : function(e, data){
3045 onEndDrag : function(data, e){
3049 onValidDrop : function(dd, e, id){
3054 beforeInvalidDrop : function(e, id){
3059 * @class Ext.grid.ColumnModel
3060 * @extends Ext.util.Observable
3061 * <p>After the data has been read into the client side cache (<b>{@link Ext.data.Store Store}</b>),
3062 * the ColumnModel is used to configure how and what parts of that data will be displayed in the
3063 * vertical slices (columns) of the grid. The Ext.grid.ColumnModel Class is the default implementation
3064 * of a ColumnModel used by implentations of {@link Ext.grid.GridPanel GridPanel}.</p>
3065 * <p>Data is mapped into the store's records and then indexed into the ColumnModel using the
3066 * <tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt>:</p>
3068 {data source} == mapping ==> {data store} == <b><tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt></b> ==> {ColumnModel}
3070 * <p>Each {@link Ext.grid.Column Column} in the grid's ColumnModel is configured with a
3071 * <tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt> to specify how the data within
3072 * each record in the store is indexed into the ColumnModel.</p>
3073 * <p>There are two ways to initialize the ColumnModel class:</p>
3074 * <p><u>Initialization Method 1: an Array</u></p>
3076 var colModel = new Ext.grid.ColumnModel([
3077 { header: "Ticker", width: 60, sortable: true},
3078 { header: "Company Name", width: 150, sortable: true, id: 'company'},
3079 { header: "Market Cap.", width: 100, sortable: true},
3080 { header: "$ Sales", width: 100, sortable: true, renderer: money},
3081 { header: "Employees", width: 100, sortable: true, resizable: false}
3084 * <p>The ColumnModel may be initialized with an Array of {@link Ext.grid.Column} column configuration
3085 * objects to define the initial layout / display of the columns in the Grid. The order of each
3086 * {@link Ext.grid.Column} column configuration object within the specified Array defines the initial
3087 * order of the column display. A Column's display may be initially hidden using the
3088 * <tt>{@link Ext.grid.Column#hidden hidden}</tt></b> config property (and then shown using the column
3089 * header menu). Field's that are not included in the ColumnModel will not be displayable at all.</p>
3090 * <p>How each column in the grid correlates (maps) to the {@link Ext.data.Record} field in the
3091 * {@link Ext.data.Store Store} the column draws its data from is configured through the
3092 * <b><tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt></b>. If the
3093 * <b><tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt></b> is not explicitly defined (as shown in the
3094 * example above) it will use the column configuration's index in the Array as the index.</p>
3095 * <p>See <b><tt>{@link Ext.grid.Column}</tt></b> for additional configuration options for each column.</p>
3096 * <p><u>Initialization Method 2: an Object</u></p>
3097 * <p>In order to use configuration options from <tt>Ext.grid.ColumnModel</tt>, an Object may be used to
3098 * initialize the ColumnModel. The column configuration Array will be specified in the <tt><b>{@link #columns}</b></tt>
3099 * config property. The <tt><b>{@link #defaults}</b></tt> config property can be used to apply defaults
3100 * for all columns, e.g.:</p><pre><code>
3101 var colModel = new Ext.grid.ColumnModel({
3103 { header: "Ticker", width: 60, menuDisabled: false},
3104 { header: "Company Name", width: 150, id: 'company'},
3105 { header: "Market Cap."},
3106 { header: "$ Sales", renderer: money},
3107 { header: "Employees", resizable: false}
3115 {@link #hiddenchange}: function(cm, colIndex, hidden) {
3116 saveConfig(colIndex, hidden);
3121 * <p>In both examples above, the ability to apply a CSS class to all cells in a column (including the
3122 * header) is demonstrated through the use of the <b><tt>{@link Ext.grid.Column#id id}</tt></b> config
3123 * option. This column could be styled by including the following css:</p><pre><code>
3124 //add this css *after* the core css is loaded
3125 .x-grid3-td-company {
3126 color: red; // entire column will have red font
3128 // modify the header row only, adding an icon to the column header
3129 .x-grid3-hd-company {
3130 background: transparent
3131 url(../../resources/images/icons/silk/building.png)
3132 no-repeat 3px 3px ! important;
3136 * Note that the "Company Name" column could be specified as the
3137 * <b><tt>{@link Ext.grid.GridPanel}.{@link Ext.grid.GridPanel#autoExpandColumn autoExpandColumn}</tt></b>.
3139 * @param {Mixed} config Specify either an Array of {@link Ext.grid.Column} configuration objects or specify
3140 * a configuration Object (see introductory section discussion utilizing Initialization Method 2 above).
3142 Ext.grid.ColumnModel = function(config){
3144 * An Array of {@link Ext.grid.Column Column definition} objects representing the configuration
3145 * of this ColumnModel. See {@link Ext.grid.Column} for the configuration properties that may
3151 Ext.apply(this, config);
3152 this.setConfig(config.columns, true);
3154 this.setConfig(config, true);
3158 * @event widthchange
3159 * Fires when the width of a column is programmaticially changed using
3160 * <code>{@link #setColumnWidth}</code>.
3161 * Note internal resizing suppresses the event from firing. See also
3162 * {@link Ext.grid.GridPanel}.<code>{@link #columnresize}</code>.
3163 * @param {ColumnModel} this
3164 * @param {Number} columnIndex The column index
3165 * @param {Number} newWidth The new width
3169 * @event headerchange
3170 * Fires when the text of a header changes.
3171 * @param {ColumnModel} this
3172 * @param {Number} columnIndex The column index
3173 * @param {String} newText The new header text
3177 * @event hiddenchange
3178 * Fires when a column is hidden or "unhidden".
3179 * @param {ColumnModel} this
3180 * @param {Number} columnIndex The column index
3181 * @param {Boolean} hidden true if hidden, false otherwise
3185 * @event columnmoved
3186 * Fires when a column is moved.
3187 * @param {ColumnModel} this
3188 * @param {Number} oldIndex
3189 * @param {Number} newIndex
3193 * @event configchange
3194 * Fires when the configuration is changed
3195 * @param {ColumnModel} this
3199 Ext.grid.ColumnModel.superclass.constructor.call(this);
3201 Ext.extend(Ext.grid.ColumnModel, Ext.util.Observable, {
3203 * @cfg {Number} defaultWidth (optional) The width of columns which have no <tt>{@link #width}</tt>
3204 * specified (defaults to <tt>100</tt>). This property shall preferably be configured through the
3205 * <tt><b>{@link #defaults}</b></tt> config property.
3209 * @cfg {Boolean} defaultSortable (optional) Default sortable of columns which have no
3210 * sortable specified (defaults to <tt>false</tt>). This property shall preferably be configured
3211 * through the <tt><b>{@link #defaults}</b></tt> config property.
3213 defaultSortable: false,
3215 * @cfg {Array} columns An Array of object literals. The config options defined by
3216 * <b>{@link Ext.grid.Column}</b> are the options which may appear in the object literal for each
3217 * individual column definition.
3220 * @cfg {Object} defaults Object literal which will be used to apply {@link Ext.grid.Column}
3221 * configuration options to all <tt><b>{@link #columns}</b></tt>. Configuration options specified with
3222 * individual {@link Ext.grid.Column column} configs will supersede these <tt><b>{@link #defaults}</b></tt>.
3226 * Returns the id of the column at the specified index.
3227 * @param {Number} index The column index
3228 * @return {String} the id
3230 getColumnId : function(index){
3231 return this.config[index].id;
3234 getColumnAt : function(index){
3235 return this.config[index];
3239 * <p>Reconfigures this column model according to the passed Array of column definition objects.
3240 * For a description of the individual properties of a column definition object, see the
3241 * <a href="#Ext.grid.ColumnModel-configs">Config Options</a>.</p>
3242 * <p>Causes the {@link #configchange} event to be fired. A {@link Ext.grid.GridPanel GridPanel}
3243 * using this ColumnModel will listen for this event and refresh its UI automatically.</p>
3244 * @param {Array} config Array of Column definition objects.
3245 * @param {Boolean} initial Specify <tt>true</tt> to bypass cleanup which deletes the <tt>totalWidth</tt>
3246 * and destroys existing editors.
3248 setConfig : function(config, initial){
3250 if(!initial){ // cleanup
3251 delete this.totalWidth;
3252 for(i = 0, len = this.config.length; i < len; i++){
3260 // backward compatibility
3261 this.defaults = Ext.apply({
3262 width: this.defaultWidth,
3263 sortable: this.defaultSortable
3266 this.config = config;
3268 // if no id, create one
3269 for(i = 0, len = config.length; i < len; i++){
3270 c = Ext.applyIf(config[i], this.defaults);
3272 var cls = Ext.grid.Column.types[c.xtype || 'gridcolumn'];
3276 this.lookup[c.id] = c;
3279 this.fireEvent('configchange', this);
3284 * Returns the column for a specified id.
3285 * @param {String} id The column id
3286 * @return {Object} the column
3288 getColumnById : function(id){
3289 return this.lookup[id];
3293 * Returns the index for a specified column id.
3294 * @param {String} id The column id
3295 * @return {Number} the index, or -1 if not found
3297 getIndexById : function(id){
3298 for(var i = 0, len = this.config.length; i < len; i++){
3299 if(this.config[i].id == id){
3307 * Moves a column from one position to another.
3308 * @param {Number} oldIndex The index of the column to move.
3309 * @param {Number} newIndex The position at which to reinsert the coolumn.
3311 moveColumn : function(oldIndex, newIndex){
3312 var c = this.config[oldIndex];
3313 this.config.splice(oldIndex, 1);
3314 this.config.splice(newIndex, 0, c);
3315 this.dataMap = null;
3316 this.fireEvent("columnmoved", this, oldIndex, newIndex);
3320 * Returns the number of columns.
3321 * @param {Boolean} visibleOnly Optional. Pass as true to only include visible columns.
3324 getColumnCount : function(visibleOnly){
3325 if(visibleOnly === true){
3327 for(var i = 0, len = this.config.length; i < len; i++){
3328 if(!this.isHidden(i)){
3334 return this.config.length;
3338 * Returns the column configs that return true by the passed function that is called
3339 * with (columnConfig, index)
3341 // returns an array of column config objects for all hidden columns
3342 var columns = grid.getColumnModel().getColumnsBy(function(c){
3346 * @param {Function} fn
3347 * @param {Object} scope (optional)
3348 * @return {Array} result
3350 getColumnsBy : function(fn, scope){
3352 for(var i = 0, len = this.config.length; i < len; i++){
3353 var c = this.config[i];
3354 if(fn.call(scope||this, c, i) === true){
3362 * Returns true if the specified column is sortable.
3363 * @param {Number} col The column index
3366 isSortable : function(col){
3367 return this.config[col].sortable;
3371 * Returns true if the specified column menu is disabled.
3372 * @param {Number} col The column index
3375 isMenuDisabled : function(col){
3376 return !!this.config[col].menuDisabled;
3380 * Returns the rendering (formatting) function defined for the column.
3381 * @param {Number} col The column index.
3382 * @return {Function} The function used to render the cell. See {@link #setRenderer}.
3384 getRenderer : function(col){
3385 if(!this.config[col].renderer){
3386 return Ext.grid.ColumnModel.defaultRenderer;
3388 return this.config[col].renderer;
3392 * Sets the rendering (formatting) function for a column. See {@link Ext.util.Format} for some
3393 * default formatting functions.
3394 * @param {Number} col The column index
3395 * @param {Function} fn The function to use to process the cell's raw data
3396 * to return HTML markup for the grid view. The render function is called with
3397 * the following parameters:<ul>
3398 * <li><b>value</b> : Object<p class="sub-desc">The data value for the cell.</p></li>
3399 * <li><b>metadata</b> : Object<p class="sub-desc">An object in which you may set the following attributes:<ul>
3400 * <li><b>css</b> : String<p class="sub-desc">A CSS class name to add to the cell's TD element.</p></li>
3401 * <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
3402 * (e.g. 'style="color:red;"').</p></li></ul></p></li>
3403 * <li><b>record</b> : Ext.data.record<p class="sub-desc">The {@link Ext.data.Record} from which the data was extracted.</p></li>
3404 * <li><b>rowIndex</b> : Number<p class="sub-desc">Row index</p></li>
3405 * <li><b>colIndex</b> : Number<p class="sub-desc">Column index</p></li>
3406 * <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>
3408 setRenderer : function(col, fn){
3409 this.config[col].renderer = fn;
3413 * Returns the width for the specified column.
3414 * @param {Number} col The column index
3417 getColumnWidth : function(col){
3418 return this.config[col].width;
3422 * Sets the width for a column.
3423 * @param {Number} col The column index
3424 * @param {Number} width The new width
3425 * @param {Boolean} suppressEvent True to suppress firing the <code>{@link #widthchange}</code>
3426 * event. Defaults to false.
3428 setColumnWidth : function(col, width, suppressEvent){
3429 this.config[col].width = width;
3430 this.totalWidth = null;
3432 this.fireEvent("widthchange", this, col, width);
3437 * Returns the total width of all columns.
3438 * @param {Boolean} includeHidden True to include hidden column widths
3441 getTotalWidth : function(includeHidden){
3442 if(!this.totalWidth){
3443 this.totalWidth = 0;
3444 for(var i = 0, len = this.config.length; i < len; i++){
3445 if(includeHidden || !this.isHidden(i)){
3446 this.totalWidth += this.getColumnWidth(i);
3450 return this.totalWidth;
3454 * Returns the header for the specified column.
3455 * @param {Number} col The column index
3458 getColumnHeader : function(col){
3459 return this.config[col].header;
3463 * Sets the header for a column.
3464 * @param {Number} col The column index
3465 * @param {String} header The new header
3467 setColumnHeader : function(col, header){
3468 this.config[col].header = header;
3469 this.fireEvent("headerchange", this, col, header);
3473 * Returns the tooltip for the specified column.
3474 * @param {Number} col The column index
3477 getColumnTooltip : function(col){
3478 return this.config[col].tooltip;
3481 * Sets the tooltip for a column.
3482 * @param {Number} col The column index
3483 * @param {String} tooltip The new tooltip
3485 setColumnTooltip : function(col, tooltip){
3486 this.config[col].tooltip = tooltip;
3490 * Returns the dataIndex for the specified column.
3492 // Get field name for the column
3493 var fieldName = grid.getColumnModel().getDataIndex(columnIndex);
3495 * @param {Number} col The column index
3496 * @return {String} The column's dataIndex
3498 getDataIndex : function(col){
3499 return this.config[col].dataIndex;
3503 * Sets the dataIndex for a column.
3504 * @param {Number} col The column index
3505 * @param {String} dataIndex The new dataIndex
3507 setDataIndex : function(col, dataIndex){
3508 this.config[col].dataIndex = dataIndex;
3512 * Finds the index of the first matching column for the given dataIndex.
3513 * @param {String} col The dataIndex to find
3514 * @return {Number} The column index, or -1 if no match was found
3516 findColumnIndex : function(dataIndex){
3517 var c = this.config;
3518 for(var i = 0, len = c.length; i < len; i++){
3519 if(c[i].dataIndex == dataIndex){
3527 * Returns true if the cell is editable.
3529 var store = new Ext.data.Store({...});
3530 var colModel = new Ext.grid.ColumnModel({
3532 isCellEditable: function(col, row) {
3533 var record = store.getAt(row);
3534 if (record.get('readonly')) { // replace with your condition
3537 return Ext.grid.ColumnModel.prototype.isCellEditable.call(this, col, row);
3540 var grid = new Ext.grid.GridPanel({
3546 * @param {Number} colIndex The column index
3547 * @param {Number} rowIndex The row index
3550 isCellEditable : function(colIndex, rowIndex){
3551 return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false;
3555 * Returns the editor defined for the cell/column.
3556 * @param {Number} colIndex The column index
3557 * @param {Number} rowIndex The row index
3558 * @return {Ext.Editor} The {@link Ext.Editor Editor} that was created to wrap
3559 * the {@link Ext.form.Field Field} used to edit the cell.
3561 getCellEditor : function(colIndex, rowIndex){
3562 return this.config[colIndex].getCellEditor(rowIndex);
3566 * Sets if a column is editable.
3567 * @param {Number} col The column index
3568 * @param {Boolean} editable True if the column is editable
3570 setEditable : function(col, editable){
3571 this.config[col].editable = editable;
3576 * Returns true if the column is hidden.
3577 * @param {Number} colIndex The column index
3580 isHidden : function(colIndex){
3581 return this.config[colIndex].hidden;
3586 * Returns true if the column width cannot be changed
3588 isFixed : function(colIndex){
3589 return this.config[colIndex].fixed;
3593 * Returns true if the column can be resized
3596 isResizable : function(colIndex){
3597 return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
3600 * Sets if a column is hidden.
3602 myGrid.getColumnModel().setHidden(0, true); // hide column 0 (0 = the first column).
3604 * @param {Number} colIndex The column index
3605 * @param {Boolean} hidden True if the column is hidden
3607 setHidden : function(colIndex, hidden){
3608 var c = this.config[colIndex];
3609 if(c.hidden !== hidden){
3611 this.totalWidth = null;
3612 this.fireEvent("hiddenchange", this, colIndex, hidden);
3617 * Sets the editor for a column and destroys the prior editor.
3618 * @param {Number} col The column index
3619 * @param {Object} editor The editor object
3621 setEditor : function(col, editor){
3622 Ext.destroy(this.config[col].editor);
3623 this.config[col].editor = editor;
3627 * Destroys this column model by purging any event listeners, and removing any editors.
3629 destroy : function(){
3630 for(var i = 0, c = this.config, len = c.length; i < len; i++){
3631 Ext.destroy(c[i].editor);
3633 this.purgeListeners();
3638 Ext.grid.ColumnModel.defaultRenderer = function(value){
3639 if(typeof value == "string" && value.length < 1){
3644 * @class Ext.grid.AbstractSelectionModel
\r
3645 * @extends Ext.util.Observable
\r
3646 * Abstract base class for grid SelectionModels. It provides the interface that should be
\r
3647 * implemented by descendant classes. This class should not be directly instantiated.
\r
3650 Ext.grid.AbstractSelectionModel = function(){
\r
3651 this.locked = false;
\r
3652 Ext.grid.AbstractSelectionModel.superclass.constructor.call(this);
\r
3655 Ext.extend(Ext.grid.AbstractSelectionModel, Ext.util.Observable, {
\r
3657 * The GridPanel for which this SelectionModel is handling selection. Read-only.
\r
3662 /** @ignore Called by the grid automatically. Do not call directly. */
\r
3663 init : function(grid){
\r
3665 this.initEvents();
\r
3669 * Locks the selections.
\r
3671 lock : function(){
\r
3672 this.locked = true;
\r
3676 * Unlocks the selections.
\r
3678 unlock : function(){
\r
3679 this.locked = false;
\r
3683 * Returns true if the selections are locked.
\r
3684 * @return {Boolean}
\r
3686 isLocked : function(){
\r
3687 return this.locked;
\r
3690 destroy: function(){
\r
3691 this.purgeListeners();
\r
3694 * @class Ext.grid.RowSelectionModel
3695 * @extends Ext.grid.AbstractSelectionModel
3696 * The default SelectionModel used by {@link Ext.grid.GridPanel}.
3697 * It supports multiple selections and keyboard selection/navigation. The objects stored
3698 * as selections and returned by {@link #getSelected}, and {@link #getSelections} are
3699 * the {@link Ext.data.Record Record}s which provide the data for the selected rows.
3701 * @param {Object} config
3703 Ext.grid.RowSelectionModel = function(config){
3704 Ext.apply(this, config);
3705 this.selections = new Ext.util.MixedCollection(false, function(o){
3710 this.lastActive = false;
3714 * @event selectionchange
3715 * Fires when the selection changes
3716 * @param {SelectionModel} this
3720 * @event beforerowselect
3721 * Fires before a row is selected, return false to cancel the selection.
3722 * @param {SelectionModel} this
3723 * @param {Number} rowIndex The index to be selected
3724 * @param {Boolean} keepExisting False if other selections will be cleared
3725 * @param {Record} record The record to be selected
3730 * Fires when a row is selected.
3731 * @param {SelectionModel} this
3732 * @param {Number} rowIndex The selected index
3733 * @param {Ext.data.Record} r The selected record
3737 * @event rowdeselect
3738 * Fires when a row is deselected. To prevent deselection
3739 * {@link Ext.grid.AbstractSelectionModel#lock lock the selections}.
3740 * @param {SelectionModel} this
3741 * @param {Number} rowIndex
3742 * @param {Record} record
3747 Ext.grid.RowSelectionModel.superclass.constructor.call(this);
3750 Ext.extend(Ext.grid.RowSelectionModel, Ext.grid.AbstractSelectionModel, {
3752 * @cfg {Boolean} singleSelect
3753 * <tt>true</tt> to allow selection of only one row at a time (defaults to <tt>false</tt>
3754 * allowing multiple selections)
3756 singleSelect : false,
3759 * @cfg {Boolean} moveEditorOnEnter
3760 * <tt>false</tt> to turn off moving the editor to the next row down when the enter key is pressed
3761 * or the next row up when shift + enter keys are pressed.
3764 initEvents : function(){
3766 if(!this.grid.enableDragDrop && !this.grid.enableDrag){
3767 this.grid.on("rowmousedown", this.handleMouseDown, this);
3768 }else{ // allow click to work like normal
3769 this.grid.on("rowclick", function(grid, rowIndex, e) {
3770 if(e.button === 0 && !e.shiftKey && !e.ctrlKey) {
3771 this.selectRow(rowIndex, false);
3772 grid.view.focusRow(rowIndex);
3777 this.rowNav = new Ext.KeyNav(this.grid.getGridEl(), {
3779 if(!e.shiftKey || this.singleSelect){
3780 this.selectPrevious(false);
3781 }else if(this.last !== false && this.lastActive !== false){
3782 var last = this.last;
3783 this.selectRange(this.last, this.lastActive-1);
3784 this.grid.getView().focusRow(this.lastActive);
3789 this.selectFirstRow();
3792 "down" : function(e){
3793 if(!e.shiftKey || this.singleSelect){
3794 this.selectNext(false);
3795 }else if(this.last !== false && this.lastActive !== false){
3796 var last = this.last;
3797 this.selectRange(this.last, this.lastActive+1);
3798 this.grid.getView().focusRow(this.lastActive);
3803 this.selectFirstRow();
3809 var view = this.grid.view;
3810 view.on("refresh", this.onRefresh, this);
3811 view.on("rowupdated", this.onRowUpdated, this);
3812 view.on("rowremoved", this.onRemove, this);
3816 onRefresh : function(){
3817 var ds = this.grid.store, index;
3818 var s = this.getSelections();
3819 this.clearSelections(true);
3820 for(var i = 0, len = s.length; i < len; i++){
3822 if((index = ds.indexOfId(r.id)) != -1){
3823 this.selectRow(index, true);
3826 if(s.length != this.selections.getCount()){
3827 this.fireEvent("selectionchange", this);
3832 onRemove : function(v, index, r){
3833 if(this.selections.remove(r) !== false){
3834 this.fireEvent('selectionchange', this);
3839 onRowUpdated : function(v, index, r){
3840 if(this.isSelected(r)){
3841 v.onRowSelect(index);
3847 * @param {Array} records The records to select
3848 * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
3850 selectRecords : function(records, keepExisting){
3852 this.clearSelections();
3854 var ds = this.grid.store;
3855 for(var i = 0, len = records.length; i < len; i++){
3856 this.selectRow(ds.indexOf(records[i]), true);
3861 * Gets the number of selected rows.
3864 getCount : function(){
3865 return this.selections.length;
3869 * Selects the first row in the grid.
3871 selectFirstRow : function(){
3876 * Select the last row.
3877 * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
3879 selectLastRow : function(keepExisting){
3880 this.selectRow(this.grid.store.getCount() - 1, keepExisting);
3884 * Selects the row immediately following the last selected row.
3885 * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
3886 * @return {Boolean} <tt>true</tt> if there is a next row, else <tt>false</tt>
3888 selectNext : function(keepExisting){
3890 this.selectRow(this.last+1, keepExisting);
3891 this.grid.getView().focusRow(this.last);
3898 * Selects the row that precedes the last selected row.
3899 * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
3900 * @return {Boolean} <tt>true</tt> if there is a previous row, else <tt>false</tt>
3902 selectPrevious : function(keepExisting){
3903 if(this.hasPrevious()){
3904 this.selectRow(this.last-1, keepExisting);
3905 this.grid.getView().focusRow(this.last);
3912 * Returns true if there is a next record to select
3915 hasNext : function(){
3916 return this.last !== false && (this.last+1) < this.grid.store.getCount();
3920 * Returns true if there is a previous record to select
3923 hasPrevious : function(){
3929 * Returns the selected records
3930 * @return {Array} Array of selected records
3932 getSelections : function(){
3933 return [].concat(this.selections.items);
3937 * Returns the first selected record.
3940 getSelected : function(){
3941 return this.selections.itemAt(0);
3945 * Calls the passed function with each selection. If the function returns
3946 * <tt>false</tt>, iteration is stopped and this function returns
3947 * <tt>false</tt>. Otherwise it returns <tt>true</tt>.
3948 * @param {Function} fn
3949 * @param {Object} scope (optional)
3950 * @return {Boolean} true if all selections were iterated
3952 each : function(fn, scope){
3953 var s = this.getSelections();
3954 for(var i = 0, len = s.length; i < len; i++){
3955 if(fn.call(scope || this, s[i], i) === false){
3963 * Clears all selections if the selection model
3964 * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}.
3965 * @param {Boolean} fast (optional) <tt>true</tt> to bypass the
3966 * conditional checks and events described in {@link #deselectRow}.
3968 clearSelections : function(fast){
3969 if(this.isLocked()){
3973 var ds = this.grid.store;
3974 var s = this.selections;
3976 this.deselectRow(ds.indexOfId(r.id));
3980 this.selections.clear();
3987 * Selects all rows if the selection model
3988 * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}.
3990 selectAll : function(){
3991 if(this.isLocked()){
3994 this.selections.clear();
3995 for(var i = 0, len = this.grid.store.getCount(); i < len; i++){
3996 this.selectRow(i, true);
4001 * Returns <tt>true</tt> if there is a selection.
4004 hasSelection : function(){
4005 return this.selections.length > 0;
4009 * Returns <tt>true</tt> if the specified row is selected.
4010 * @param {Number/Record} index The record or index of the record to check
4013 isSelected : function(index){
4014 var r = typeof index == "number" ? this.grid.store.getAt(index) : index;
4015 return (r && this.selections.key(r.id) ? true : false);
4019 * Returns <tt>true</tt> if the specified record id is selected.
4020 * @param {String} id The id of record to check
4023 isIdSelected : function(id){
4024 return (this.selections.key(id) ? true : false);
4028 handleMouseDown : function(g, rowIndex, e){
4029 if(e.button !== 0 || this.isLocked()){
4032 var view = this.grid.getView();
4033 if(e.shiftKey && !this.singleSelect && this.last !== false){
4034 var last = this.last;
4035 this.selectRange(last, rowIndex, e.ctrlKey);
4036 this.last = last; // reset the last
4037 view.focusRow(rowIndex);
4039 var isSelected = this.isSelected(rowIndex);
4040 if(e.ctrlKey && isSelected){
4041 this.deselectRow(rowIndex);
4042 }else if(!isSelected || this.getCount() > 1){
4043 this.selectRow(rowIndex, e.ctrlKey || e.shiftKey);
4044 view.focusRow(rowIndex);
4050 * Selects multiple rows.
4051 * @param {Array} rows Array of the indexes of the row to select
4052 * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep
4053 * existing selections (defaults to <tt>false</tt>)
4055 selectRows : function(rows, keepExisting){
4057 this.clearSelections();
4059 for(var i = 0, len = rows.length; i < len; i++){
4060 this.selectRow(rows[i], true);
4065 * Selects a range of rows if the selection model
4066 * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}.
4067 * All rows in between startRow and endRow are also selected.
4068 * @param {Number} startRow The index of the first row in the range
4069 * @param {Number} endRow The index of the last row in the range
4070 * @param {Boolean} keepExisting (optional) True to retain existing selections
4072 selectRange : function(startRow, endRow, keepExisting){
4074 if(this.isLocked()){
4078 this.clearSelections();
4080 if(startRow <= endRow){
4081 for(i = startRow; i <= endRow; i++){
4082 this.selectRow(i, true);
4085 for(i = startRow; i >= endRow; i--){
4086 this.selectRow(i, true);
4092 * Deselects a range of rows if the selection model
4093 * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}.
4094 * All rows in between startRow and endRow are also deselected.
4095 * @param {Number} startRow The index of the first row in the range
4096 * @param {Number} endRow The index of the last row in the range
4098 deselectRange : function(startRow, endRow, preventViewNotify){
4099 if(this.isLocked()){
4102 for(var i = startRow; i <= endRow; i++){
4103 this.deselectRow(i, preventViewNotify);
4108 * Selects a row. Before selecting a row, checks if the selection model
4109 * {@link Ext.grid.AbstractSelectionModel#isLocked is locked} and fires the
4110 * {@link #beforerowselect} event. If these checks are satisfied the row
4111 * will be selected and followed up by firing the {@link #rowselect} and
4112 * {@link #selectionchange} events.
4113 * @param {Number} row The index of the row to select
4114 * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
4115 * @param {Boolean} preventViewNotify (optional) Specify <tt>true</tt> to
4116 * prevent notifying the view (disables updating the selected appearance)
4118 selectRow : function(index, keepExisting, preventViewNotify){
4119 if(this.isLocked() || (index < 0 || index >= this.grid.store.getCount()) || (keepExisting && this.isSelected(index))){
4122 var r = this.grid.store.getAt(index);
4123 if(r && this.fireEvent("beforerowselect", this, index, keepExisting, r) !== false){
4124 if(!keepExisting || this.singleSelect){
4125 this.clearSelections();
4127 this.selections.add(r);
4128 this.last = this.lastActive = index;
4129 if(!preventViewNotify){
4130 this.grid.getView().onRowSelect(index);
4132 this.fireEvent("rowselect", this, index, r);
4133 this.fireEvent("selectionchange", this);
4138 * Deselects a row. Before deselecting a row, checks if the selection model
4139 * {@link Ext.grid.AbstractSelectionModel#isLocked is locked}.
4140 * If this check is satisfied the row will be deselected and followed up by
4141 * firing the {@link #rowdeselect} and {@link #selectionchange} events.
4142 * @param {Number} row The index of the row to deselect
4143 * @param {Boolean} preventViewNotify (optional) Specify <tt>true</tt> to
4144 * prevent notifying the view (disables updating the selected appearance)
4146 deselectRow : function(index, preventViewNotify){
4147 if(this.isLocked()){
4150 if(this.last == index){
4153 if(this.lastActive == index){
4154 this.lastActive = false;
4156 var r = this.grid.store.getAt(index);
4158 this.selections.remove(r);
4159 if(!preventViewNotify){
4160 this.grid.getView().onRowDeselect(index);
4162 this.fireEvent("rowdeselect", this, index, r);
4163 this.fireEvent("selectionchange", this);
4168 restoreLast : function(){
4170 this.last = this._last;
4175 acceptsNav : function(row, col, cm){
4176 return !cm.isHidden(col) && cm.isCellEditable(col, row);
4180 onEditorKey : function(field, e){
4181 var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
4182 var shift = e.shiftKey;
4187 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
4189 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
4191 }else if(k == e.ENTER){
4194 if(this.moveEditorOnEnter !== false){
4196 newCell = g.walkCells(ed.row - 1, ed.col, -1, this.acceptsNav, this);
4198 newCell = g.walkCells(ed.row + 1, ed.col, 1, this.acceptsNav, this);
4201 }else if(k == e.ESC){
4205 g.startEditing(newCell[0], newCell[1]);
4209 destroy: function(){
4211 this.rowNav.disable();
4214 Ext.grid.RowSelectionModel.superclass.destroy.call(this);
4217 * @class Ext.grid.Column
\r
4218 * <p>This class encapsulates column configuration data to be used in the initialization of a
\r
4219 * {@link Ext.grid.ColumnModel ColumnModel}.</p>
\r
4220 * <p>While subclasses are provided to render data in different ways, this class renders a passed
\r
4221 * data field unchanged and is usually used for textual columns.</p>
\r
4223 Ext.grid.Column = function(config){
\r
4224 Ext.apply(this, config);
\r
4226 if(typeof this.renderer == 'string'){
\r
4227 this.renderer = Ext.util.Format[this.renderer];
\r
4228 } else if(Ext.isObject(this.renderer)){
\r
4229 this.scope = this.renderer.scope;
\r
4230 this.renderer = this.renderer.fn;
\r
4232 this.renderer = this.renderer.createDelegate(this.scope || config);
\r
4234 if(this.id === undefined){
\r
4235 this.id = ++Ext.grid.Column.AUTO_ID;
\r
4238 this.editor = Ext.create(this.editor, 'textfield');
\r
4242 Ext.grid.Column.AUTO_ID = 0;
\r
4244 Ext.grid.Column.prototype = {
\r
4246 * @cfg {Boolean} editable Optional. Defaults to <tt>true</tt>, enabling the configured
\r
4247 * <tt>{@link #editor}</tt>. Set to <tt>false</tt> to initially disable editing on this column.
\r
4248 * The initial configuration may be dynamically altered using
\r
4249 * {@link Ext.grid.ColumnModel}.{@link Ext.grid.ColumnModel#setEditable setEditable()}.
\r
4252 * @cfg {String} id Optional. A name which identifies this column (defaults to the column's initial
\r
4253 * ordinal position.) The <tt>id</tt> is used to create a CSS <b>class</b> name which is applied to all
\r
4254 * table cells (including headers) in that column (in this context the <tt>id</tt> does not need to be
\r
4255 * unique). The class name takes the form of <pre>x-grid3-td-<b>id</b></pre>
\r
4256 * Header cells will also receive this class name, but will also have the class <pre>x-grid3-hd</pre>
\r
4257 * So, to target header cells, use CSS selectors such as:<pre>.x-grid3-hd-row .x-grid3-td-<b>id</b></pre>
\r
4258 * The {@link Ext.grid.GridPanel#autoExpandColumn} grid config option references the column via this
\r
4259 * unique identifier.
\r
4262 * @cfg {String} header Optional. The header text to be used as innerHTML
\r
4263 * (html tags are accepted) to display in the Grid view. <b>Note</b>: to
\r
4264 * have a clickable header with no text displayed use <tt>' '</tt>.
\r
4267 * @cfg {Boolean} groupable Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option
\r
4268 * may be used to disable the header menu item to group by the column selected. Defaults to <tt>true</tt>,
\r
4269 * which enables the header menu group option. Set to <tt>false</tt> to disable (but still show) the
\r
4270 * group option in the header menu for the column. See also <code>{@link #groupName}</code>.
\r
4273 * @cfg {String} groupName Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option
\r
4274 * may be used to specify the text with which to prefix the group field value in the group header line.
\r
4275 * See also {@link #groupRenderer} and
\r
4276 * {@link Ext.grid.GroupingView}.{@link Ext.grid.GroupingView#showGroupName showGroupName}.
\r
4279 * @cfg {Function} groupRenderer <p>Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option
\r
4280 * may be used to specify the function used to format the grouping field value for display in the group
\r
4281 * {@link #groupName header}. If a <tt><b>groupRenderer</b></tt> is not specified, the configured
\r
4282 * <tt><b>{@link #renderer}</b></tt> will be called; if a <tt><b>{@link #renderer}</b></tt> is also not specified
\r
4283 * the new value of the group field will be used.</p>
\r
4284 * <p>The called function (either the <tt><b>groupRenderer</b></tt> or <tt><b>{@link #renderer}</b></tt>) will be
\r
4285 * passed the following parameters:
\r
4286 * <div class="mdetail-params"><ul>
\r
4287 * <li><b>v</b> : Object<p class="sub-desc">The new value of the group field.</p></li>
\r
4288 * <li><b>unused</b> : undefined<p class="sub-desc">Unused parameter.</p></li>
\r
4289 * <li><b>r</b> : Ext.data.Record<p class="sub-desc">The Record providing the data
\r
4290 * for the row which caused group change.</p></li>
\r
4291 * <li><b>rowIndex</b> : Number<p class="sub-desc">The row index of the Record which caused group change.</p></li>
\r
4292 * <li><b>colIndex</b> : Number<p class="sub-desc">The column index of the group field.</p></li>
\r
4293 * <li><b>ds</b> : Ext.data.Store<p class="sub-desc">The Store which is providing the data Model.</p></li>
\r
4295 * <p>The function should return a string value.</p>
\r
4298 * @cfg {String} emptyGroupText Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option
\r
4299 * may be used to specify the text to display when there is an empty group value. Defaults to the
\r
4300 * {@link Ext.grid.GroupingView}.{@link Ext.grid.GroupingView#emptyGroupText emptyGroupText}.
\r
4303 * @cfg {String} dataIndex <p><b>Required</b>. The name of the field in the
\r
4304 * grid's {@link Ext.data.Store}'s {@link Ext.data.Record} definition from
\r
4305 * which to draw the column's value.</p>
\r
4308 * @cfg {Number} width
\r
4309 * Optional. The initial width in pixels of the column.
\r
4310 * The width of each column can also be affected if any of the following are configured:
\r
4311 * <div class="mdetail-params"><ul>
\r
4312 * <li>{@link Ext.grid.GridPanel}.<tt>{@link Ext.grid.GridPanel#autoExpandColumn autoExpandColumn}</tt></li>
\r
4313 * <li>{@link Ext.grid.GridView}.<tt>{@link Ext.grid.GridView#forceFit forceFit}</tt>
\r
4314 * <div class="sub-desc">
\r
4315 * <p>By specifying <tt>forceFit:true</tt>, {@link #fixed non-fixed width} columns will be
\r
4316 * re-proportioned (based on the relative initial widths) to fill the width of the grid so
\r
4317 * that no horizontal scrollbar is shown.</p>
\r
4319 * <li>{@link Ext.grid.GridView}.<tt>{@link Ext.grid.GridView#autoFill autoFill}</tt></li>
\r
4320 * <li>{@link Ext.grid.GridPanel}.<tt>{@link Ext.grid.GridPanel#minColumnWidth minColumnWidth}</tt></li>
\r
4321 * <br><p><b>Note</b>: when the width of each column is determined, a space on the right side
\r
4322 * is reserved for the vertical scrollbar. The
\r
4323 * {@link Ext.grid.GridView}.<tt>{@link Ext.grid.GridView#scrollOffset scrollOffset}</tt>
\r
4324 * can be modified to reduce or eliminate the reserved offset.</p>
\r
4327 * @cfg {Boolean} sortable Optional. <tt>true</tt> if sorting is to be allowed on this column.
\r
4328 * Defaults to the value of the {@link #defaultSortable} property.
\r
4329 * Whether local/remote sorting is used is specified in {@link Ext.data.Store#remoteSort}.
\r
4332 * @cfg {Boolean} fixed Optional. <tt>true</tt> if the column width cannot be changed. Defaults to <tt>false</tt>.
\r
4335 * @cfg {Boolean} resizable Optional. <tt>false</tt> to disable column resizing. Defaults to <tt>true</tt>.
\r
4338 * @cfg {Boolean} menuDisabled Optional. <tt>true</tt> to disable the column menu. Defaults to <tt>false</tt>.
\r
4341 * @cfg {Boolean} hidden Optional. <tt>true</tt> to hide the column. Defaults to <tt>false</tt>.
\r
4344 * @cfg {String} tooltip Optional. A text string to use as the column header's tooltip. If Quicktips
\r
4345 * are enabled, this value will be used as the text of the quick tip, otherwise it will be set as the
\r
4346 * header's HTML title attribute. Defaults to ''.
\r
4349 * @cfg {Mixed} renderer
\r
4350 * <p>For an alternative to specifying a renderer see <code>{@link #xtype}</code></p>
\r
4351 * <p>Optional. A renderer is an 'interceptor' method which can be used transform data (value,
\r
4352 * appearance, etc.) before it is rendered). This may be specified in either of three ways:
\r
4353 * <div class="mdetail-params"><ul>
\r
4354 * <li>A renderer function used to return HTML markup for a cell given the cell's data value.</li>
\r
4355 * <li>A string which references a property name of the {@link Ext.util.Format} class which
\r
4356 * provides a renderer function.</li>
\r
4357 * <li>An object specifying both the renderer function, and its execution scope (<tt><b>this</b></tt>
\r
4358 * reference) e.g.:<pre style="margin-left:1.2em"><code>
\r
4360 fn: this.gridRenderer,
\r
4363 </code></pre></li></ul></div>
\r
4364 * If not specified, the default renderer uses the raw data value.</p>
\r
4365 * <p>For information about the renderer function (passed parameters, etc.), see
\r
4366 * {@link Ext.grid.ColumnModel#setRenderer}. An example of specifying renderer function inline:</p><pre><code>
\r
4367 var companyColumn = {
\r
4368 header: 'Company Name',
\r
4369 dataIndex: 'company',
\r
4370 renderer: function(value, metaData, record, rowIndex, colIndex, store) {
\r
4371 // provide the logic depending on business rules
\r
4372 // name of your own choosing to manipulate the cell depending upon
\r
4373 // the data in the underlying Record object.
\r
4374 if (value == 'whatever') {
\r
4375 //metaData.css : String : A CSS class name to add to the TD element of the cell.
\r
4376 //metaData.attr : String : An html attribute definition string to apply to
\r
4377 // the data container element within the table
\r
4378 // cell (e.g. 'style="color:red;"').
\r
4379 metaData.css = 'name-of-css-class-you-will-define';
\r
4385 * See also {@link #scope}.
\r
4388 * @cfg {String} xtype Optional. A String which references a predefined {@link Ext.grid.Column} subclass
\r
4389 * type which is preconfigured with an appropriate <code>{@link #renderer}</code> to be easily
\r
4390 * configured into a ColumnModel. The predefined {@link Ext.grid.Column} subclass types are:
\r
4391 * <div class="mdetail-params"><ul>
\r
4392 * <li><b><tt>gridcolumn</tt></b> : {@link Ext.grid.Column} (<b>Default</b>)<p class="sub-desc"></p></li>
\r
4393 * <li><b><tt>booleancolumn</tt></b> : {@link Ext.grid.BooleanColumn}<p class="sub-desc"></p></li>
\r
4394 * <li><b><tt>numbercolumn</tt></b> : {@link Ext.grid.NumberColumn}<p class="sub-desc"></p></li>
\r
4395 * <li><b><tt>datecolumn</tt></b> : {@link Ext.grid.DateColumn}<p class="sub-desc"></p></li>
\r
4396 * <li><b><tt>templatecolumn</tt></b> : {@link Ext.grid.TemplateColumn}<p class="sub-desc"></p></li>
\r
4398 * <p>Configuration properties for the specified <code>xtype</code> may be specified with
\r
4399 * the Column configuration properties, for example:</p>
\r
4401 var grid = new Ext.grid.GridPanel({
\r
4404 header: 'Last Updated',
\r
4405 dataIndex: 'lastChange',
\r
4408 //renderer: Ext.util.Format.dateRenderer('m/d/Y'),
\r
4409 xtype: 'datecolumn', // use xtype instead of renderer
\r
4410 format: 'M/d/Y' // configuration property for {@link Ext.grid.DateColumn}
\r
4418 * @cfg {Object} scope Optional. The scope (<tt><b>this</b></tt> reference) in which to execute the
\r
4419 * renderer. Defaults to the Column configuration object.
\r
4422 * @cfg {String} align Optional. Set the CSS text-align property of the column. Defaults to undefined.
\r
4425 * @cfg {String} css Optional. An inline style definition string which is applied to all table cells in the column
\r
4426 * (excluding headers). Defaults to undefined.
\r
4429 * @cfg {Boolean} hideable Optional. Specify as <tt>false</tt> to prevent the user from hiding this column
\r
4430 * (defaults to true). To disallow column hiding globally for all columns in the grid, use
\r
4431 * {@link Ext.grid.GridPanel#enableColumnHide} instead.
\r
4434 * @cfg {Ext.form.Field} editor Optional. The {@link Ext.form.Field} to use when editing values in this column
\r
4435 * if editing is supported by the grid. See <tt>{@link #editable}</tt> also.
\r
4438 // private. Used by ColumnModel to avoid reprocessing
\r
4441 * Optional. A function which returns displayable data when passed the following parameters:
\r
4442 * <div class="mdetail-params"><ul>
\r
4443 * <li><b>value</b> : Object<p class="sub-desc">The data value for the cell.</p></li>
\r
4444 * <li><b>metadata</b> : Object<p class="sub-desc">An object in which you may set the following attributes:<ul>
\r
4445 * <li><b>css</b> : String<p class="sub-desc">A CSS class name to add to the cell's TD element.</p></li>
\r
4446 * <li><b>attr</b> : String<p class="sub-desc">An HTML attribute definition string to apply to the data container
\r
4447 * element <i>within</i> the table cell (e.g. 'style="color:red;"').</p></li></ul></p></li>
\r
4448 * <li><b>record</b> : Ext.data.record<p class="sub-desc">The {@link Ext.data.Record} from which the data was
\r
4449 * extracted.</p></li>
\r
4450 * <li><b>rowIndex</b> : Number<p class="sub-desc">Row index</p></li>
\r
4451 * <li><b>colIndex</b> : Number<p class="sub-desc">Column index</p></li>
\r
4452 * <li><b>store</b> : Ext.data.Store<p class="sub-desc">The {@link Ext.data.Store} object from which the Record
\r
4453 * was extracted.</p></li>
\r
4455 * @property renderer
\r
4458 renderer : function(value){
\r
4459 if(typeof value == 'string' && value.length < 1){
\r
4466 getEditor: function(rowIndex){
\r
4467 return this.editable !== false ? this.editor : null;
\r
4471 * Returns the {@link Ext.Editor editor} defined for this column that was created to wrap the {@link Ext.form.Field Field}
\r
4472 * used to edit the cell.
\r
4473 * @param {Number} rowIndex The row index
\r
4474 * @return {Ext.Editor}
\r
4476 getCellEditor: function(rowIndex){
\r
4477 var editor = this.getEditor(rowIndex);
\r
4479 if(!editor.startEdit){
\r
4480 if(!editor.gridEditor){
\r
4481 editor.gridEditor = new Ext.grid.GridEditor(editor);
\r
4483 return editor.gridEditor;
\r
4484 }else if(editor.startEdit){
\r
4493 * @class Ext.grid.BooleanColumn
\r
4494 * @extends Ext.grid.Column
\r
4495 * <p>A Column definition class which renders boolean data fields. See the {@link Ext.grid.ColumnModel#xtype xtype}
\r
4496 * config option of {@link Ext.grid.ColumnModel} for more details.</p>
\r
4498 Ext.grid.BooleanColumn = Ext.extend(Ext.grid.Column, {
\r
4500 * @cfg {String} trueText
\r
4501 * The string returned by the renderer when the column value is not falsey (defaults to <tt>'true'</tt>).
\r
4505 * @cfg {String} falseText
\r
4506 * The string returned by the renderer when the column value is falsey (but not undefined) (defaults to
\r
4507 * <tt>'false'</tt>).
\r
4509 falseText: 'false',
\r
4511 * @cfg {String} undefinedText
\r
4512 * The string returned by the renderer when the column value is undefined (defaults to <tt>' '</tt>).
\r
4514 undefinedText: ' ',
\r
4516 constructor: function(cfg){
\r
4517 Ext.grid.BooleanColumn.superclass.constructor.call(this, cfg);
\r
4518 var t = this.trueText, f = this.falseText, u = this.undefinedText;
\r
4519 this.renderer = function(v){
\r
4520 if(v === undefined){
\r
4523 if(!v || v === 'false'){
\r
4532 * @class Ext.grid.NumberColumn
\r
4533 * @extends Ext.grid.Column
\r
4534 * <p>A Column definition class which renders a numeric data field according to a {@link #format} string. See the
\r
4535 * {@link Ext.grid.ColumnModel#xtype xtype} config option of {@link Ext.grid.ColumnModel} for more details.</p>
\r
4537 Ext.grid.NumberColumn = Ext.extend(Ext.grid.Column, {
\r
4539 * @cfg {String} format
\r
4540 * A formatting string as used by {@link Ext.util.Format#number} to format a numeric value for this Column
\r
4541 * (defaults to <tt>'0,000.00'</tt>).
\r
4543 format : '0,000.00',
\r
4544 constructor: function(cfg){
\r
4545 Ext.grid.NumberColumn.superclass.constructor.call(this, cfg);
\r
4546 this.renderer = Ext.util.Format.numberRenderer(this.format);
\r
4551 * @class Ext.grid.DateColumn
\r
4552 * @extends Ext.grid.Column
\r
4553 * <p>A Column definition class which renders a passed date according to the default locale, or a configured
\r
4554 * {@link #format}. See the {@link Ext.grid.ColumnModel#xtype xtype} config option of {@link Ext.grid.ColumnModel}
\r
4555 * for more details.</p>
\r
4557 Ext.grid.DateColumn = Ext.extend(Ext.grid.Column, {
\r
4559 * @cfg {String} format
\r
4560 * A formatting string as used by {@link Date#format} to format a Date for this Column
\r
4561 * (defaults to <tt>'m/d/Y'</tt>).
\r
4564 constructor: function(cfg){
\r
4565 Ext.grid.DateColumn.superclass.constructor.call(this, cfg);
\r
4566 this.renderer = Ext.util.Format.dateRenderer(this.format);
\r
4571 * @class Ext.grid.TemplateColumn
\r
4572 * @extends Ext.grid.Column
\r
4573 * <p>A Column definition class which renders a value by processing a {@link Ext.data.Record Record}'s
\r
4574 * {@link Ext.data.Record#data data} using a {@link #tpl configured} {@link Ext.XTemplate XTemplate}.
\r
4575 * See the {@link Ext.grid.ColumnModel#xtype xtype} config option of {@link Ext.grid.ColumnModel} for more
\r
4578 Ext.grid.TemplateColumn = Ext.extend(Ext.grid.Column, {
\r
4580 * @cfg {String/XTemplate} tpl
\r
4581 * An {@link Ext.XTemplate XTemplate}, or an XTemplate <i>definition string</i> to use to process a
\r
4582 * {@link Ext.data.Record Record}'s {@link Ext.data.Record#data data} to produce a column's rendered value.
\r
4584 constructor: function(cfg){
\r
4585 Ext.grid.TemplateColumn.superclass.constructor.call(this, cfg);
\r
4586 var tpl = typeof Ext.isObject(this.tpl) ? this.tpl : new Ext.XTemplate(this.tpl);
\r
4587 this.renderer = function(value, p, r){
\r
4588 return tpl.apply(r.data);
\r
4597 * @member Ext.grid.Column
\r
4599 * <p>An object containing predefined Column classes keyed by a mnemonic code which may be referenced
\r
4600 * by the {@link Ext.grid.ColumnModel#xtype xtype} config option of ColumnModel.</p>
\r
4601 * <p>This contains the following properties</p><div class="mdesc-details"><ul>
\r
4602 * <li>gridcolumn : <b>{@link Ext.grid.Column Column constructor}</b></li>
\r
4603 * <li>booleancolumn : <b>{@link Ext.grid.BooleanColumn BooleanColumn constructor}</b></li>
\r
4604 * <li>numbercolumn : <b>{@link Ext.grid.NumberColumn NumberColumn constructor}</b></li>
\r
4605 * <li>datecolumn : <b>{@link Ext.grid.DateColumn DateColumn constructor}</b></li>
\r
4606 * <li>templatecolumn : <b>{@link Ext.grid.TemplateColumn TemplateColumn constructor}</b></li>
\r
4609 Ext.grid.Column.types = {
\r
4610 gridcolumn : Ext.grid.Column,
\r
4611 booleancolumn: Ext.grid.BooleanColumn,
\r
4612 numbercolumn: Ext.grid.NumberColumn,
\r
4613 datecolumn: Ext.grid.DateColumn,
\r
4614 templatecolumn: Ext.grid.TemplateColumn
\r
4616 * @class Ext.grid.RowNumberer
4617 * This is a utility class that can be passed into a {@link Ext.grid.ColumnModel} as a column config that provides
4618 * an automatic row numbering column.
4621 // This is a typical column config with the first column providing row numbers
4622 var colModel = new Ext.grid.ColumnModel([
4623 new Ext.grid.RowNumberer(),
4624 {header: "Name", width: 80, sortable: true},
4625 {header: "Code", width: 50, sortable: true},
4626 {header: "Description", width: 200, sortable: true}
4630 * @param {Object} config The configuration options
4632 Ext.grid.RowNumberer = function(config){
4633 Ext.apply(this, config);
4635 this.renderer = this.renderer.createDelegate(this);
4639 Ext.grid.RowNumberer.prototype = {
4641 * @cfg {String} header Any valid text or HTML fragment to display in the header cell for the row
4642 * number column (defaults to '').
4646 * @cfg {Number} width The default width in pixels of the row number column (defaults to 23).
4650 * @cfg {Boolean} sortable True if the row number column is sortable (defaults to false).
4663 renderer : function(v, p, record, rowIndex){
4665 p.cellAttr = 'rowspan="'+this.rowspan+'"';
4670 * @class Ext.grid.CheckboxSelectionModel
\r
4671 * @extends Ext.grid.RowSelectionModel
\r
4672 * A custom selection model that renders a column of checkboxes that can be toggled to select or deselect rows.
\r
4674 * @param {Object} config The configuration options
\r
4676 Ext.grid.CheckboxSelectionModel = Ext.extend(Ext.grid.RowSelectionModel, {
\r
4679 * @cfg {Boolean} checkOnly <tt>true</tt> if rows can only be selected by clicking on the
\r
4680 * checkbox column (defaults to <tt>false</tt>).
\r
4683 * @cfg {String} header Any valid text or HTML fragment to display in the header cell for the
\r
4684 * checkbox column. Defaults to:<pre><code>
\r
4685 * '<div class="x-grid3-hd-checker">&#160;</div>'</tt>
\r
4687 * The default CSS class of <tt>'x-grid3-hd-checker'</tt> displays a checkbox in the header
\r
4688 * and provides support for automatic check all/none behavior on header click. This string
\r
4689 * can be replaced by any valid HTML fragment, including a simple text string (e.g.,
\r
4690 * <tt>'Select Rows'</tt>), but the automatic check all/none behavior will only work if the
\r
4691 * <tt>'x-grid3-hd-checker'</tt> class is supplied.
\r
4693 header: '<div class="x-grid3-hd-checker"> </div>',
\r
4695 * @cfg {Number} width The default width in pixels of the checkbox column (defaults to <tt>20</tt>).
\r
4699 * @cfg {Boolean} sortable <tt>true</tt> if the checkbox column is sortable (defaults to
\r
4700 * <tt>false</tt>).
\r
4705 menuDisabled:true,
\r
4710 constructor: function(){
\r
4711 Ext.grid.CheckboxSelectionModel.superclass.constructor.apply(this, arguments);
\r
4713 if(this.checkOnly){
\r
4714 this.handleMouseDown = Ext.emptyFn;
\r
4719 initEvents : function(){
\r
4720 Ext.grid.CheckboxSelectionModel.superclass.initEvents.call(this);
\r
4721 this.grid.on('render', function(){
\r
4722 var view = this.grid.getView();
\r
4723 view.mainBody.on('mousedown', this.onMouseDown, this);
\r
4724 Ext.fly(view.innerHd).on('mousedown', this.onHdMouseDown, this);
\r
4730 onMouseDown : function(e, t){
\r
4731 if(e.button === 0 && t.className == 'x-grid3-row-checker'){ // Only fire if left-click
\r
4733 var row = e.getTarget('.x-grid3-row');
\r
4735 var index = row.rowIndex;
\r
4736 if(this.isSelected(index)){
\r
4737 this.deselectRow(index);
\r
4739 this.selectRow(index, true);
\r
4746 onHdMouseDown : function(e, t){
\r
4747 if(t.className == 'x-grid3-hd-checker'){
\r
4749 var hd = Ext.fly(t.parentNode);
\r
4750 var isChecked = hd.hasClass('x-grid3-hd-checker-on');
\r
4752 hd.removeClass('x-grid3-hd-checker-on');
\r
4753 this.clearSelections();
\r
4755 hd.addClass('x-grid3-hd-checker-on');
\r
4762 renderer : function(v, p, record){
\r
4763 return '<div class="x-grid3-row-checker"> </div>';
\r