/*!
- * Ext JS Library 3.0.0
- * Copyright(c) 2006-2009 Ext JS, LLC
+ * Ext JS Library 3.2.1
+ * Copyright(c) 2006-2010 Ext JS, Inc.
* licensing@extjs.com
* http://www.extjs.com/license
*/
-/**\r
- * @class Ext.grid.GridPanel\r
- * @extends Ext.Panel\r
- * <p>This class represents the primary interface of a component based grid control to represent data\r
- * in a tabular format of rows and columns. The GridPanel is composed of the following:</p>\r
- * <div class="mdetail-params"><ul>\r
- * <li><b>{@link Ext.data.Store Store}</b> : The Model holding the data records (rows)\r
- * <div class="sub-desc"></div></li>\r
- * <li><b>{@link Ext.grid.ColumnModel Column model}</b> : Column makeup\r
- * <div class="sub-desc"></div></li>\r
- * <li><b>{@link Ext.grid.GridView View}</b> : Encapsulates the user interface \r
- * <div class="sub-desc"></div></li>\r
- * <li><b>{@link Ext.grid.AbstractSelectionModel selection model}</b> : Selection behavior \r
- * <div class="sub-desc"></div></li>\r
- * </ul></div>\r
- * <p>Example usage:</p>\r
- * <pre><code>\r
-var grid = new Ext.grid.GridPanel({\r
- {@link #store}: new (@link Ext.data.Store}({\r
- {@link Ext.data.Store#autoDestroy autoDestroy}: true,\r
- {@link Ext.data.Store#reader reader}: reader,\r
- {@link Ext.data.Store#data data}: xg.dummyData\r
- }),\r
- {@link #columns}: [\r
- {id: 'company', header: 'Company', width: 200, sortable: true, dataIndex: 'company'},\r
- {header: 'Price', width: 120, sortable: true, renderer: Ext.util.Format.usMoney, dataIndex: 'price'},\r
- {header: 'Change', width: 120, sortable: true, dataIndex: 'change'},\r
- {header: '% Change', width: 120, sortable: true, dataIndex: 'pctChange'},\r
- // instead of specifying renderer: Ext.util.Format.dateRenderer('m/d/Y') use xtype\r
- {header: 'Last Updated', width: 135, sortable: true, dataIndex: 'lastChange', xtype: 'datecolumn', format: 'M d, Y'}\r
- ],\r
- {@link #viewConfig}: {\r
- {@link Ext.grid.GridView#forceFit forceFit}: true,\r
-\r
-// Return CSS class to apply to rows depending upon data values\r
- {@link Ext.grid.GridView#getRowClass getRowClass}: function(record, index) {\r
- var c = record.{@link Ext.data.Record#get get}('change');\r
- if (c < 0) {\r
- return 'price-fall';\r
- } else if (c > 0) {\r
- return 'price-rise';\r
- }\r
- }\r
- },\r
- {@link #sm}: new Ext.grid.RowSelectionModel({singleSelect:true}),\r
- width: 600,\r
- height: 300,\r
- frame: true,\r
- title: 'Framed with Row Selection and Horizontal Scrolling',\r
- iconCls: 'icon-grid'\r
-});\r
- * </code></pre>\r
- * <p><b><u>Notes:</u></b></p>\r
- * <div class="mdetail-params"><ul>\r
- * <li>Although this class inherits many configuration options from base classes, some of them\r
- * (such as autoScroll, autoWidth, layout, items, etc) are not used by this class, and will\r
- * have no effect.</li>\r
- * <li>A grid <b>requires</b> a width in which to scroll its columns, and a height in which to\r
- * scroll its rows. These dimensions can either be set explicitly through the\r
- * <tt>{@link Ext.BoxComponent#height height}</tt> and <tt>{@link Ext.BoxComponent#width width}</tt>\r
- * configuration options or implicitly set by using the grid as a child item of a\r
- * {@link Ext.Container Container} which will have a {@link Ext.Container#layout layout manager}\r
- * provide the sizing of its child items (for example the Container of the Grid may specify\r
- * <tt>{@link Ext.Container#layout layout}:'fit'</tt>).</li>\r
- * <li>To access the data in a Grid, it is necessary to use the data model encapsulated\r
- * by the {@link #store Store}. See the {@link #cellclick} event for more details.</li>\r
- * </ul></div>\r
- * @constructor\r
- * @param {Object} config The config object\r
- * @xtype grid\r
- */\r
-Ext.grid.GridPanel = Ext.extend(Ext.Panel, {\r
- /**\r
- * @cfg {String} autoExpandColumn\r
- * <p>The <tt>{@link Ext.grid.Column#id id}</tt> of a {@link Ext.grid.Column column} in\r
- * this grid that should expand to fill unused space. This value specified here can not\r
- * be <tt>0</tt>.</p>\r
- * <br><p><b>Note</b>: If the Grid's {@link Ext.grid.GridView view} is configured with\r
- * <tt>{@link Ext.grid.GridView#forceFit forceFit}=true</tt> the <tt>autoExpandColumn</tt>\r
- * is ignored. See {@link Ext.grid.Column}.<tt>{@link Ext.grid.Column#width width}</tt>\r
- * for additional details.</p>\r
- * <p>See <tt>{@link #autoExpandMax}</tt> and <tt>{@link #autoExpandMin}</tt> also.</p>\r
- */\r
- autoExpandColumn : false,\r
- /**\r
- * @cfg {Number} autoExpandMax The maximum width the <tt>{@link #autoExpandColumn}</tt>\r
- * can have (if enabled). Defaults to <tt>1000</tt>.\r
- */\r
- autoExpandMax : 1000,\r
- /**\r
- * @cfg {Number} autoExpandMin The minimum width the <tt>{@link #autoExpandColumn}</tt>\r
- * can have (if enabled). Defaults to <tt>50</tt>.\r
- */\r
- autoExpandMin : 50,\r
- /**\r
- * @cfg {Boolean} columnLines <tt>true</tt> to add css for column separation lines.\r
- * Default is <tt>false</tt>.\r
- */\r
- columnLines : false,\r
- /**\r
- * @cfg {Object} cm Shorthand for <tt>{@link #colModel}</tt>.\r
- */\r
- /**\r
- * @cfg {Object} colModel The {@link Ext.grid.ColumnModel} to use when rendering the grid (required).\r
- */\r
- /**\r
- * @cfg {Array} columns An array of {@link Ext.grid.Column columns} to auto create a\r
- * {@link Ext.grid.ColumnModel}. The ColumnModel may be explicitly created via the\r
- * <tt>{@link #colModel}</tt> configuration property.\r
- */\r
- /**\r
- * @cfg {String} ddGroup The DD group this GridPanel belongs to. Defaults to <tt>'GridDD'</tt> if not specified.\r
- */\r
- /**\r
- * @cfg {String} ddText\r
- * Configures the text in the drag proxy. Defaults to:\r
- * <pre><code>\r
- * ddText : '{0} selected row{1}'\r
- * </code></pre>\r
- * <tt>{0}</tt> is replaced with the number of selected rows.\r
- */\r
- ddText : '{0} selected row{1}',\r
- /**\r
- * @cfg {Boolean} deferRowRender <P>Defaults to <tt>true</tt> to enable deferred row rendering.</p>\r
- * <p>This allows the GridPanel to be initially rendered empty, with the expensive update of the row\r
- * structure deferred so that layouts with GridPanels appear more quickly.</p>\r
- */\r
- deferRowRender : true,\r
- /**\r
- * @cfg {Boolean} disableSelection <p><tt>true</tt> to disable selections in the grid. Defaults to <tt>false</tt>.</p>\r
- * <p>Ignored if a {@link #selModel SelectionModel} is specified.</p>\r
- */\r
- /**\r
- * @cfg {Boolean} enableColumnResize <tt>false</tt> to turn off column resizing for the whole grid. Defaults to <tt>true</tt>.\r
- */\r
- /**\r
- * @cfg {Boolean} enableColumnHide Defaults to <tt>true</tt> to enable hiding of columns with the header context menu.\r
- */\r
- enableColumnHide : true,\r
- /**\r
- * @cfg {Boolean} enableColumnMove Defaults to <tt>true</tt> to enable drag and drop reorder of columns. <tt>false</tt>\r
- * to turn off column reordering via drag drop.\r
- */\r
- enableColumnMove : true,\r
- /**\r
- * @cfg {Boolean} enableDragDrop <p>Enables dragging of the selected rows of the GridPanel. Defaults to <tt>false</tt>.</p>\r
- * <p>Setting this to <b><tt>true</tt></b> causes this GridPanel's {@link #getView GridView} to\r
- * create an instance of {@link Ext.grid.GridDragZone}. <b>Note</b>: this is available only <b>after</b>\r
- * the Grid has been rendered as the GridView's <tt>{@link Ext.grid.GridView#dragZone dragZone}</tt>\r
- * property.</p>\r
- * <p>A cooperating {@link Ext.dd.DropZone DropZone} must be created who's implementations of\r
- * {@link Ext.dd.DropZone#onNodeEnter onNodeEnter}, {@link Ext.dd.DropZone#onNodeOver onNodeOver},\r
- * {@link Ext.dd.DropZone#onNodeOut onNodeOut} and {@link Ext.dd.DropZone#onNodeDrop onNodeDrop} are able\r
- * to process the {@link Ext.grid.GridDragZone#getDragData data} which is provided.</p>\r
- */\r
- enableDragDrop : false,\r
- /**\r
- * @cfg {Boolean} enableHdMenu Defaults to <tt>true</tt> to enable the drop down button for menu in the headers.\r
- */\r
- enableHdMenu : true,\r
- /**\r
- * @cfg {Boolean} hideHeaders True to hide the grid's header. Defaults to <code>false</code>.\r
- */\r
- /**\r
- * @cfg {Object} loadMask An {@link Ext.LoadMask} config or true to mask the grid while\r
- * loading. Defaults to <code>false</code>.\r
- */\r
- loadMask : false,\r
- /**\r
- * @cfg {Number} maxHeight Sets the maximum height of the grid - ignored if <tt>autoHeight</tt> is not on.\r
- */\r
- /**\r
- * @cfg {Number} minColumnWidth The minimum width a column can be resized to. Defaults to <tt>25</tt>.\r
- */\r
- minColumnWidth : 25,\r
- /**\r
- * @cfg {Object} sm Shorthand for <tt>{@link #selModel}</tt>.\r
- */\r
- /**\r
- * @cfg {Object} selModel Any subclass of {@link Ext.grid.AbstractSelectionModel} that will provide\r
- * the selection model for the grid (defaults to {@link Ext.grid.RowSelectionModel} if not specified).\r
- */\r
- /**\r
- * @cfg {Ext.data.Store} store The {@link Ext.data.Store} the grid should use as its data source (required).\r
- */\r
- /**\r
- * @cfg {Boolean} stripeRows <tt>true</tt> to stripe the rows. Default is <tt>false</tt>.\r
- * <p>This causes the CSS class <tt><b>x-grid3-row-alt</b></tt> to be added to alternate rows of\r
- * the grid. A default CSS rule is provided which sets a background colour, but you can override this\r
- * with a rule which either overrides the <b>background-color</b> style using the '!important'\r
- * modifier, or which uses a CSS selector of higher specificity.</p>\r
- */\r
- stripeRows : false,\r
- /**\r
- * @cfg {Boolean} trackMouseOver True to highlight rows when the mouse is over. Default is <tt>true</tt>\r
- * for GridPanel, but <tt>false</tt> for EditorGridPanel.\r
- */\r
- trackMouseOver : true,\r
- /**\r
- * @cfg {Array} stateEvents\r
- * An array of events that, when fired, should trigger this component to save its state.\r
- * Defaults to:<pre><code>\r
- * stateEvents: ['columnmove', 'columnresize', 'sortchange']\r
- * </code></pre>\r
- * <p>These can be any types of events supported by this component, including browser or\r
- * custom events (e.g., <tt>['click', 'customerchange']</tt>).</p>\r
- * <p>See {@link Ext.Component#stateful} for an explanation of saving and restoring\r
- * Component state.</p>\r
- */\r
- stateEvents : ['columnmove', 'columnresize', 'sortchange'],\r
- /**\r
- * @cfg {Object} view The {@link Ext.grid.GridView} used by the grid. This can be set\r
- * before a call to {@link Ext.Component#render render()}.\r
- */\r
- view : null,\r
- /**\r
- * @cfg {Object} viewConfig A config object that will be applied to the grid's UI view. Any of\r
- * the config options available for {@link Ext.grid.GridView} can be specified here. This option\r
- * is ignored if <tt>{@link #view}</tt> is specified.\r
- */\r
-\r
- // private\r
- rendered : false,\r
- // private\r
- viewReady : false,\r
-\r
- // private\r
- initComponent : function(){\r
- Ext.grid.GridPanel.superclass.initComponent.call(this);\r
-\r
- if(this.columnLines){\r
- this.cls = (this.cls || '') + ' x-grid-with-col-lines';\r
- }\r
- // override any provided value since it isn't valid\r
- // and is causing too many bug reports ;)\r
- this.autoScroll = false;\r
- this.autoWidth = false;\r
-\r
- if(Ext.isArray(this.columns)){\r
- this.colModel = new Ext.grid.ColumnModel(this.columns);\r
- delete this.columns;\r
- }\r
-\r
- // check and correct shorthanded configs\r
- if(this.ds){\r
- this.store = this.ds;\r
- delete this.ds;\r
- }\r
- if(this.cm){\r
- this.colModel = this.cm;\r
- delete this.cm;\r
- }\r
- if(this.sm){\r
- this.selModel = this.sm;\r
- delete this.sm;\r
- }\r
- this.store = Ext.StoreMgr.lookup(this.store);\r
-\r
- this.addEvents(\r
- // raw events\r
- /**\r
- * @event click\r
- * The raw click event for the entire grid.\r
- * @param {Ext.EventObject} e\r
- */\r
- 'click',\r
- /**\r
- * @event dblclick\r
- * The raw dblclick event for the entire grid.\r
- * @param {Ext.EventObject} e\r
- */\r
- 'dblclick',\r
- /**\r
- * @event contextmenu\r
- * The raw contextmenu event for the entire grid.\r
- * @param {Ext.EventObject} e\r
- */\r
- 'contextmenu',\r
- /**\r
- * @event mousedown\r
- * The raw mousedown event for the entire grid.\r
- * @param {Ext.EventObject} e\r
- */\r
- 'mousedown',\r
- /**\r
- * @event mouseup\r
- * The raw mouseup event for the entire grid.\r
- * @param {Ext.EventObject} e\r
- */\r
- 'mouseup',\r
- /**\r
- * @event mouseover\r
- * The raw mouseover event for the entire grid.\r
- * @param {Ext.EventObject} e\r
- */\r
- 'mouseover',\r
- /**\r
- * @event mouseout\r
- * The raw mouseout event for the entire grid.\r
- * @param {Ext.EventObject} e\r
- */\r
- 'mouseout',\r
- /**\r
- * @event keypress\r
- * The raw keypress event for the entire grid.\r
- * @param {Ext.EventObject} e\r
- */\r
- 'keypress',\r
- /**\r
- * @event keydown\r
- * The raw keydown event for the entire grid.\r
- * @param {Ext.EventObject} e\r
- */\r
- 'keydown',\r
-\r
- // custom events\r
- /**\r
- * @event cellmousedown\r
- * Fires before a cell is clicked\r
- * @param {Grid} this\r
- * @param {Number} rowIndex\r
- * @param {Number} columnIndex\r
- * @param {Ext.EventObject} e\r
- */\r
- 'cellmousedown',\r
- /**\r
- * @event rowmousedown\r
- * Fires before a row is clicked\r
- * @param {Grid} this\r
- * @param {Number} rowIndex\r
- * @param {Ext.EventObject} e\r
- */\r
- 'rowmousedown',\r
- /**\r
- * @event headermousedown\r
- * Fires before a header is clicked\r
- * @param {Grid} this\r
- * @param {Number} columnIndex\r
- * @param {Ext.EventObject} e\r
- */\r
- 'headermousedown',\r
-\r
- /**\r
- * @event cellclick\r
- * Fires when a cell is clicked.\r
- * The data for the cell is drawn from the {@link Ext.data.Record Record}\r
- * for this row. To access the data in the listener function use the\r
- * following technique:\r
- * <pre><code>\r
-function(grid, rowIndex, columnIndex, e) {\r
- var record = grid.getStore().getAt(rowIndex); // Get the Record\r
- var fieldName = grid.getColumnModel().getDataIndex(columnIndex); // Get field name\r
- var data = record.get(fieldName);\r
-}\r
-</code></pre>\r
- * @param {Grid} this\r
- * @param {Number} rowIndex\r
- * @param {Number} columnIndex\r
- * @param {Ext.EventObject} e\r
- */\r
- 'cellclick',\r
- /**\r
- * @event celldblclick\r
- * Fires when a cell is double clicked\r
- * @param {Grid} this\r
- * @param {Number} rowIndex\r
- * @param {Number} columnIndex\r
- * @param {Ext.EventObject} e\r
- */\r
- 'celldblclick',\r
- /**\r
- * @event rowclick\r
- * Fires when a row is clicked\r
- * @param {Grid} this\r
- * @param {Number} rowIndex\r
- * @param {Ext.EventObject} e\r
- */\r
- 'rowclick',\r
- /**\r
- * @event rowdblclick\r
- * Fires when a row is double clicked\r
- * @param {Grid} this\r
- * @param {Number} rowIndex\r
- * @param {Ext.EventObject} e\r
- */\r
- 'rowdblclick',\r
- /**\r
- * @event headerclick\r
- * Fires when a header is clicked\r
- * @param {Grid} this\r
- * @param {Number} columnIndex\r
- * @param {Ext.EventObject} e\r
- */\r
- 'headerclick',\r
- /**\r
- * @event headerdblclick\r
- * Fires when a header cell is double clicked\r
- * @param {Grid} this\r
- * @param {Number} columnIndex\r
- * @param {Ext.EventObject} e\r
- */\r
- 'headerdblclick',\r
- /**\r
- * @event rowcontextmenu\r
- * Fires when a row is right clicked\r
- * @param {Grid} this\r
- * @param {Number} rowIndex\r
- * @param {Ext.EventObject} e\r
- */\r
- 'rowcontextmenu',\r
- /**\r
- * @event cellcontextmenu\r
- * Fires when a cell is right clicked\r
- * @param {Grid} this\r
- * @param {Number} rowIndex\r
- * @param {Number} cellIndex\r
- * @param {Ext.EventObject} e\r
- */\r
- 'cellcontextmenu',\r
- /**\r
- * @event headercontextmenu\r
- * Fires when a header is right clicked\r
- * @param {Grid} this\r
- * @param {Number} columnIndex\r
- * @param {Ext.EventObject} e\r
- */\r
- 'headercontextmenu',\r
- /**\r
- * @event bodyscroll\r
- * Fires when the body element is scrolled\r
- * @param {Number} scrollLeft\r
- * @param {Number} scrollTop\r
- */\r
- 'bodyscroll',\r
- /**\r
- * @event columnresize\r
- * Fires when the user resizes a column\r
- * @param {Number} columnIndex\r
- * @param {Number} newSize\r
- */\r
- 'columnresize',\r
- /**\r
- * @event columnmove\r
- * Fires when the user moves a column\r
- * @param {Number} oldIndex\r
- * @param {Number} newIndex\r
- */\r
- 'columnmove',\r
- /**\r
- * @event sortchange\r
- * Fires when the grid's store sort changes\r
- * @param {Grid} this\r
- * @param {Object} sortInfo An object with the keys field and direction\r
- */\r
- 'sortchange',\r
- /**\r
- * @event reconfigure\r
- * Fires when the grid is reconfigured with a new store and/or column model.\r
- * @param {Grid} this\r
- * @param {Ext.data.Store} store The new store\r
- * @param {Ext.grid.ColumnModel} colModel The new column model\r
- */\r
- 'reconfigure'\r
- );\r
- },\r
-\r
- // private\r
- onRender : function(ct, position){\r
- Ext.grid.GridPanel.superclass.onRender.apply(this, arguments);\r
-\r
- var c = this.body;\r
-\r
- this.el.addClass('x-grid-panel');\r
-\r
- var view = this.getView();\r
- view.init(this);\r
-\r
- this.mon(c, {\r
- mousedown: this.onMouseDown,\r
- click: this.onClick,\r
- dblclick: this.onDblClick,\r
- contextmenu: this.onContextMenu,\r
- keydown: this.onKeyDown,\r
- scope: this\r
- });\r
-\r
- this.relayEvents(c, ['mousedown','mouseup','mouseover','mouseout','keypress']);\r
-\r
- this.getSelectionModel().init(this);\r
- this.view.render();\r
- },\r
-\r
- // private\r
- initEvents : function(){\r
- Ext.grid.GridPanel.superclass.initEvents.call(this);\r
-\r
- if(this.loadMask){\r
- this.loadMask = new Ext.LoadMask(this.bwrap,\r
- Ext.apply({store:this.store}, this.loadMask));\r
- }\r
- },\r
-\r
- initStateEvents : function(){\r
- Ext.grid.GridPanel.superclass.initStateEvents.call(this);\r
- this.mon(this.colModel, 'hiddenchange', this.saveState, this, {delay: 100});\r
- },\r
-\r
- applyState : function(state){\r
- var cm = this.colModel;\r
- var cs = state.columns;\r
- if(cs){\r
- for(var i = 0, len = cs.length; i < len; i++){\r
- var s = cs[i];\r
- var c = cm.getColumnById(s.id);\r
- if(c){\r
- c.hidden = s.hidden;\r
- c.width = s.width;\r
- var oldIndex = cm.getIndexById(s.id);\r
- if(oldIndex != i){\r
- cm.moveColumn(oldIndex, i);\r
- }\r
- }\r
- }\r
- }\r
- if(state.sort && this.store){\r
- this.store[this.store.remoteSort ? 'setDefaultSort' : 'sort'](state.sort.field, state.sort.direction);\r
- }\r
- delete state.columns;\r
- delete state.sort;\r
- Ext.grid.GridPanel.superclass.applyState.call(this, state);\r
- },\r
-\r
- getState : function(){\r
- var o = {columns: []};\r
- for(var i = 0, c; (c = this.colModel.config[i]); i++){\r
- o.columns[i] = {\r
- id: c.id,\r
- width: c.width\r
- };\r
- if(c.hidden){\r
- o.columns[i].hidden = true;\r
- }\r
- }\r
- if(this.store){\r
- var ss = this.store.getSortState();\r
- if(ss){\r
- o.sort = ss;\r
- }\r
- }\r
- return o;\r
- },\r
-\r
- // private\r
- afterRender : function(){\r
- Ext.grid.GridPanel.superclass.afterRender.call(this);\r
- this.view.layout();\r
- if(this.deferRowRender){\r
- this.view.afterRender.defer(10, this.view);\r
- }else{\r
- this.view.afterRender();\r
- }\r
- this.viewReady = true;\r
- },\r
-\r
- /**\r
- * <p>Reconfigures the grid to use a different Store and Column Model\r
- * and fires the 'reconfigure' event. The View will be bound to the new\r
- * objects and refreshed.</p>\r
- * <p>Be aware that upon reconfiguring a GridPanel, certain existing settings <i>may</i> become\r
- * invalidated. For example the configured {@link #autoExpandColumn} may no longer exist in the\r
- * new ColumnModel. Also, an existing {@link Ext.PagingToolbar PagingToolbar} will still be bound\r
- * to the old Store, and will need rebinding. Any {@link #plugins} might also need reconfiguring\r
- * with the new data.</p>\r
- * @param {Ext.data.Store} store The new {@link Ext.data.Store} object\r
- * @param {Ext.grid.ColumnModel} colModel The new {@link Ext.grid.ColumnModel} object\r
- */\r
- reconfigure : function(store, colModel){\r
- if(this.loadMask){\r
- this.loadMask.destroy();\r
- this.loadMask = new Ext.LoadMask(this.bwrap,\r
- Ext.apply({}, {store:store}, this.initialConfig.loadMask));\r
- }\r
- this.view.initData(store, colModel);\r
- this.store = store;\r
- this.colModel = colModel;\r
- if(this.rendered){\r
- this.view.refresh(true);\r
- }\r
- this.fireEvent('reconfigure', this, store, colModel);\r
- },\r
-\r
- // private\r
- onKeyDown : function(e){\r
- this.fireEvent('keydown', e);\r
- },\r
-\r
- // private\r
- onDestroy : function(){\r
- if(this.rendered){\r
- var c = this.body;\r
- c.removeAllListeners();\r
- c.update('');\r
- Ext.destroy(this.view, this.loadMask);\r
- }else if(this.store && this.store.autoDestroy){\r
- this.store.destroy();\r
- }\r
- Ext.destroy(this.colModel, this.selModel);\r
- this.store = this.selModel = this.colModel = this.view = this.loadMask = null;\r
- Ext.grid.GridPanel.superclass.onDestroy.call(this);\r
- },\r
-\r
- // private\r
- processEvent : function(name, e){\r
- this.fireEvent(name, e);\r
- var t = e.getTarget();\r
- var v = this.view;\r
- var header = v.findHeaderIndex(t);\r
- if(header !== false){\r
- this.fireEvent('header' + name, this, header, e);\r
- }else{\r
- var row = v.findRowIndex(t);\r
- var cell = v.findCellIndex(t);\r
- if(row !== false){\r
- this.fireEvent('row' + name, this, row, e);\r
- if(cell !== false){\r
- this.fireEvent('cell' + name, this, row, cell, e);\r
- }\r
- }\r
- }\r
- },\r
-\r
- // private\r
- onClick : function(e){\r
- this.processEvent('click', e);\r
- },\r
-\r
- // private\r
- onMouseDown : function(e){\r
- this.processEvent('mousedown', e);\r
- },\r
-\r
- // private\r
- onContextMenu : function(e, t){\r
- this.processEvent('contextmenu', e);\r
- },\r
-\r
- // private\r
- onDblClick : function(e){\r
- this.processEvent('dblclick', e);\r
- },\r
-\r
- // private\r
- walkCells : function(row, col, step, fn, scope){\r
- var cm = this.colModel, clen = cm.getColumnCount();\r
- var ds = this.store, rlen = ds.getCount(), first = true;\r
- if(step < 0){\r
- if(col < 0){\r
- row--;\r
- first = false;\r
- }\r
- while(row >= 0){\r
- if(!first){\r
- col = clen-1;\r
- }\r
- first = false;\r
- while(col >= 0){\r
- if(fn.call(scope || this, row, col, cm) === true){\r
- return [row, col];\r
- }\r
- col--;\r
- }\r
- row--;\r
- }\r
- } else {\r
- if(col >= clen){\r
- row++;\r
- first = false;\r
- }\r
- while(row < rlen){\r
- if(!first){\r
- col = 0;\r
- }\r
- first = false;\r
- while(col < clen){\r
- if(fn.call(scope || this, row, col, cm) === true){\r
- return [row, col];\r
- }\r
- col++;\r
- }\r
- row++;\r
- }\r
- }\r
- return null;\r
- },\r
-\r
- // private\r
- onResize : function(){\r
- Ext.grid.GridPanel.superclass.onResize.apply(this, arguments);\r
- if(this.viewReady){\r
- this.view.layout();\r
- }\r
- },\r
-\r
- /**\r
- * Returns the grid's underlying element.\r
- * @return {Element} The element\r
- */\r
- getGridEl : function(){\r
- return this.body;\r
- },\r
-\r
- // private for compatibility, overridden by editor grid\r
- stopEditing : Ext.emptyFn,\r
-\r
- /**\r
- * Returns the grid's selection model configured by the <code>{@link #selModel}</code>\r
- * configuration option. If no selection model was configured, this will create\r
- * and return a {@link Ext.grid.RowSelectionModel RowSelectionModel}.\r
- * @return {SelectionModel}\r
- */\r
- getSelectionModel : function(){\r
- if(!this.selModel){\r
- this.selModel = new Ext.grid.RowSelectionModel(\r
- this.disableSelection ? {selectRow: Ext.emptyFn} : null);\r
- }\r
- return this.selModel;\r
- },\r
-\r
- /**\r
- * Returns the grid's data store.\r
- * @return {Ext.data.Store} The store\r
- */\r
- getStore : function(){\r
- return this.store;\r
- },\r
-\r
- /**\r
- * Returns the grid's ColumnModel.\r
- * @return {Ext.grid.ColumnModel} The column model\r
- */\r
- getColumnModel : function(){\r
- return this.colModel;\r
- },\r
-\r
- /**\r
- * Returns the grid's GridView object.\r
- * @return {Ext.grid.GridView} The grid view\r
- */\r
- getView : function(){\r
- if(!this.view){\r
- this.view = new Ext.grid.GridView(this.viewConfig);\r
- }\r
- return this.view;\r
- },\r
- /**\r
- * Called to get grid's drag proxy text, by default returns this.ddText.\r
- * @return {String} The text\r
- */\r
- getDragDropText : function(){\r
- var count = this.selModel.getCount();\r
- return String.format(this.ddText, count, count == 1 ? '' : 's');\r
- }\r
-\r
- /** \r
- * @cfg {String/Number} activeItem \r
- * @hide \r
- */\r
- /** \r
- * @cfg {Boolean} autoDestroy \r
- * @hide \r
- */\r
- /** \r
- * @cfg {Object/String/Function} autoLoad \r
- * @hide \r
- */\r
- /** \r
- * @cfg {Boolean} autoWidth \r
- * @hide \r
- */\r
- /** \r
- * @cfg {Boolean/Number} bufferResize \r
- * @hide \r
- */\r
- /** \r
- * @cfg {String} defaultType \r
- * @hide \r
- */\r
- /** \r
- * @cfg {Object} defaults \r
- * @hide \r
- */\r
- /** \r
- * @cfg {Boolean} hideBorders \r
- * @hide \r
- */\r
- /** \r
- * @cfg {Mixed} items \r
- * @hide \r
- */\r
- /** \r
- * @cfg {String} layout \r
- * @hide \r
- */\r
- /** \r
- * @cfg {Object} layoutConfig \r
- * @hide \r
- */\r
- /** \r
- * @cfg {Boolean} monitorResize \r
- * @hide \r
- */\r
- /** \r
- * @property items \r
- * @hide \r
- */\r
- /** \r
- * @method add \r
- * @hide \r
- */\r
- /** \r
- * @method cascade \r
- * @hide \r
- */\r
- /** \r
- * @method doLayout \r
- * @hide \r
- */\r
- /** \r
- * @method find \r
- * @hide \r
- */\r
- /** \r
- * @method findBy \r
- * @hide \r
- */\r
- /** \r
- * @method findById \r
- * @hide \r
- */\r
- /** \r
- * @method findByType \r
- * @hide \r
- */\r
- /** \r
- * @method getComponent \r
- * @hide \r
- */\r
- /** \r
- * @method getLayout \r
- * @hide \r
- */\r
- /** \r
- * @method getUpdater \r
- * @hide \r
- */\r
- /** \r
- * @method insert \r
- * @hide \r
- */\r
- /** \r
- * @method load \r
- * @hide \r
- */\r
- /** \r
- * @method remove \r
- * @hide \r
- */\r
- /** \r
- * @event add \r
- * @hide \r
- */\r
- /** \r
- * @event afterLayout \r
- * @hide \r
- */\r
- /** \r
- * @event beforeadd \r
- * @hide \r
- */\r
- /** \r
- * @event beforeremove \r
- * @hide \r
- */\r
- /** \r
- * @event remove \r
- * @hide \r
- */\r
-\r
-\r
-\r
- /**\r
- * @cfg {String} allowDomMove @hide\r
- */\r
- /**\r
- * @cfg {String} autoEl @hide\r
- */\r
- /**\r
- * @cfg {String} applyTo @hide\r
- */\r
- /**\r
- * @cfg {String} autoScroll @hide\r
- */\r
- /**\r
- * @cfg {String} bodyBorder @hide\r
- */\r
- /**\r
- * @cfg {String} bodyStyle @hide\r
- */\r
- /**\r
- * @cfg {String} contentEl @hide\r
- */\r
- /**\r
- * @cfg {String} disabledClass @hide\r
- */\r
- /**\r
- * @cfg {String} elements @hide\r
- */\r
- /**\r
- * @cfg {String} html @hide\r
- */\r
- /**\r
- * @cfg {Boolean} preventBodyReset\r
- * @hide\r
- */\r
- /**\r
- * @property disabled\r
- * @hide\r
- */\r
- /**\r
- * @method applyToMarkup\r
- * @hide\r
- */\r
- /**\r
- * @method enable\r
- * @hide\r
- */\r
- /**\r
- * @method disable\r
- * @hide\r
- */\r
- /**\r
- * @method setDisabled\r
- * @hide\r
- */\r
-});\r
+/**
+ * @class Ext.grid.GridPanel
+ * @extends Ext.Panel
+ * <p>This class represents the primary interface of a component based grid control to represent data
+ * in a tabular format of rows and columns. The GridPanel is composed of the following:</p>
+ * <div class="mdetail-params"><ul>
+ * <li><b>{@link Ext.data.Store Store}</b> : The Model holding the data records (rows)
+ * <div class="sub-desc"></div></li>
+ * <li><b>{@link Ext.grid.ColumnModel Column model}</b> : Column makeup
+ * <div class="sub-desc"></div></li>
+ * <li><b>{@link Ext.grid.GridView View}</b> : Encapsulates the user interface
+ * <div class="sub-desc"></div></li>
+ * <li><b>{@link Ext.grid.AbstractSelectionModel selection model}</b> : Selection behavior
+ * <div class="sub-desc"></div></li>
+ * </ul></div>
+ * <p>Example usage:</p>
+ * <pre><code>
+var grid = new Ext.grid.GridPanel({
+ {@link #store}: new {@link Ext.data.Store}({
+ {@link Ext.data.Store#autoDestroy autoDestroy}: true,
+ {@link Ext.data.Store#reader reader}: reader,
+ {@link Ext.data.Store#data data}: xg.dummyData
+ }),
+ {@link #colModel}: new {@link Ext.grid.ColumnModel}({
+ {@link Ext.grid.ColumnModel#defaults defaults}: {
+ width: 120,
+ sortable: true
+ },
+ {@link Ext.grid.ColumnModel#columns columns}: [
+ {id: 'company', header: 'Company', width: 200, sortable: true, dataIndex: 'company'},
+ {header: 'Price', renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
+ {header: 'Change', dataIndex: 'change'},
+ {header: '% Change', dataIndex: 'pctChange'},
+ // instead of specifying renderer: Ext.util.Format.dateRenderer('m/d/Y') use xtype
+ {
+ header: 'Last Updated', width: 135, dataIndex: 'lastChange',
+ xtype: 'datecolumn', format: 'M d, Y'
+ }
+ ],
+ }),
+ {@link #viewConfig}: {
+ {@link Ext.grid.GridView#forceFit forceFit}: true,
+
+// Return CSS class to apply to rows depending upon data values
+ {@link Ext.grid.GridView#getRowClass getRowClass}: function(record, index) {
+ var c = record.{@link Ext.data.Record#get get}('change');
+ if (c < 0) {
+ return 'price-fall';
+ } else if (c > 0) {
+ return 'price-rise';
+ }
+ }
+ },
+ {@link #sm}: new Ext.grid.RowSelectionModel({singleSelect:true}),
+ width: 600,
+ height: 300,
+ frame: true,
+ title: 'Framed with Row Selection and Horizontal Scrolling',
+ iconCls: 'icon-grid'
+});
+ * </code></pre>
+ * <p><b><u>Notes:</u></b></p>
+ * <div class="mdetail-params"><ul>
+ * <li>Although this class inherits many configuration options from base classes, some of them
+ * (such as autoScroll, autoWidth, layout, items, etc) are not used by this class, and will
+ * have no effect.</li>
+ * <li>A grid <b>requires</b> a width in which to scroll its columns, and a height in which to
+ * scroll its rows. These dimensions can either be set explicitly through the
+ * <tt>{@link Ext.BoxComponent#height height}</tt> and <tt>{@link Ext.BoxComponent#width width}</tt>
+ * configuration options or implicitly set by using the grid as a child item of a
+ * {@link Ext.Container Container} which will have a {@link Ext.Container#layout layout manager}
+ * provide the sizing of its child items (for example the Container of the Grid may specify
+ * <tt>{@link Ext.Container#layout layout}:'fit'</tt>).</li>
+ * <li>To access the data in a Grid, it is necessary to use the data model encapsulated
+ * by the {@link #store Store}. See the {@link #cellclick} event for more details.</li>
+ * </ul></div>
+ * @constructor
+ * @param {Object} config The config object
+ * @xtype grid
+ */
+Ext.grid.GridPanel = Ext.extend(Ext.Panel, {
+ /**
+ * @cfg {String} autoExpandColumn
+ * <p>The <tt>{@link Ext.grid.Column#id id}</tt> of a {@link Ext.grid.Column column} in
+ * this grid that should expand to fill unused space. This value specified here can not
+ * be <tt>0</tt>.</p>
+ * <br><p><b>Note</b>: If the Grid's {@link Ext.grid.GridView view} is configured with
+ * <tt>{@link Ext.grid.GridView#forceFit forceFit}=true</tt> the <tt>autoExpandColumn</tt>
+ * is ignored. See {@link Ext.grid.Column}.<tt>{@link Ext.grid.Column#width width}</tt>
+ * for additional details.</p>
+ * <p>See <tt>{@link #autoExpandMax}</tt> and <tt>{@link #autoExpandMin}</tt> also.</p>
+ */
+ autoExpandColumn : false,
+ /**
+ * @cfg {Number} autoExpandMax The maximum width the <tt>{@link #autoExpandColumn}</tt>
+ * can have (if enabled). Defaults to <tt>1000</tt>.
+ */
+ autoExpandMax : 1000,
+ /**
+ * @cfg {Number} autoExpandMin The minimum width the <tt>{@link #autoExpandColumn}</tt>
+ * can have (if enabled). Defaults to <tt>50</tt>.
+ */
+ autoExpandMin : 50,
+ /**
+ * @cfg {Boolean} columnLines <tt>true</tt> to add css for column separation lines.
+ * Default is <tt>false</tt>.
+ */
+ columnLines : false,
+ /**
+ * @cfg {Object} cm Shorthand for <tt>{@link #colModel}</tt>.
+ */
+ /**
+ * @cfg {Object} colModel The {@link Ext.grid.ColumnModel} to use when rendering the grid (required).
+ */
+ /**
+ * @cfg {Array} columns An array of {@link Ext.grid.Column columns} to auto create a
+ * {@link Ext.grid.ColumnModel}. The ColumnModel may be explicitly created via the
+ * <tt>{@link #colModel}</tt> configuration property.
+ */
+ /**
+ * @cfg {String} ddGroup The DD group this GridPanel belongs to. Defaults to <tt>'GridDD'</tt> if not specified.
+ */
+ /**
+ * @cfg {String} ddText
+ * Configures the text in the drag proxy. Defaults to:
+ * <pre><code>
+ * ddText : '{0} selected row{1}'
+ * </code></pre>
+ * <tt>{0}</tt> is replaced with the number of selected rows.
+ */
+ ddText : '{0} selected row{1}',
+ /**
+ * @cfg {Boolean} deferRowRender <P>Defaults to <tt>true</tt> to enable deferred row rendering.</p>
+ * <p>This allows the GridPanel to be initially rendered empty, with the expensive update of the row
+ * structure deferred so that layouts with GridPanels appear more quickly.</p>
+ */
+ deferRowRender : true,
+ /**
+ * @cfg {Boolean} disableSelection <p><tt>true</tt> to disable selections in the grid. Defaults to <tt>false</tt>.</p>
+ * <p>Ignored if a {@link #selModel SelectionModel} is specified.</p>
+ */
+ /**
+ * @cfg {Boolean} enableColumnResize <tt>false</tt> to turn off column resizing for the whole grid. Defaults to <tt>true</tt>.
+ */
+ /**
+ * @cfg {Boolean} enableColumnHide
+ * Defaults to <tt>true</tt> to enable {@link Ext.grid.Column#hidden hiding of columns}
+ * with the {@link #enableHdMenu header menu}.
+ */
+ enableColumnHide : true,
+ /**
+ * @cfg {Boolean} enableColumnMove Defaults to <tt>true</tt> to enable drag and drop reorder of columns. <tt>false</tt>
+ * to turn off column reordering via drag drop.
+ */
+ enableColumnMove : true,
+ /**
+ * @cfg {Boolean} enableDragDrop <p>Enables dragging of the selected rows of the GridPanel. Defaults to <tt>false</tt>.</p>
+ * <p>Setting this to <b><tt>true</tt></b> causes this GridPanel's {@link #getView GridView} to
+ * create an instance of {@link Ext.grid.GridDragZone}. <b>Note</b>: this is available only <b>after</b>
+ * the Grid has been rendered as the GridView's <tt>{@link Ext.grid.GridView#dragZone dragZone}</tt>
+ * property.</p>
+ * <p>A cooperating {@link Ext.dd.DropZone DropZone} must be created who's implementations of
+ * {@link Ext.dd.DropZone#onNodeEnter onNodeEnter}, {@link Ext.dd.DropZone#onNodeOver onNodeOver},
+ * {@link Ext.dd.DropZone#onNodeOut onNodeOut} and {@link Ext.dd.DropZone#onNodeDrop onNodeDrop} are able
+ * to process the {@link Ext.grid.GridDragZone#getDragData data} which is provided.</p>
+ */
+ enableDragDrop : false,
+ /**
+ * @cfg {Boolean} enableHdMenu Defaults to <tt>true</tt> to enable the drop down button for menu in the headers.
+ */
+ enableHdMenu : true,
+ /**
+ * @cfg {Boolean} hideHeaders True to hide the grid's header. Defaults to <code>false</code>.
+ */
+ /**
+ * @cfg {Object} loadMask An {@link Ext.LoadMask} config or true to mask the grid while
+ * loading. Defaults to <code>false</code>.
+ */
+ loadMask : false,
+ /**
+ * @cfg {Number} maxHeight Sets the maximum height of the grid - ignored if <tt>autoHeight</tt> is not on.
+ */
+ /**
+ * @cfg {Number} minColumnWidth The minimum width a column can be resized to. Defaults to <tt>25</tt>.
+ */
+ minColumnWidth : 25,
+ /**
+ * @cfg {Object} sm Shorthand for <tt>{@link #selModel}</tt>.
+ */
+ /**
+ * @cfg {Object} selModel Any subclass of {@link Ext.grid.AbstractSelectionModel} that will provide
+ * the selection model for the grid (defaults to {@link Ext.grid.RowSelectionModel} if not specified).
+ */
+ /**
+ * @cfg {Ext.data.Store} store The {@link Ext.data.Store} the grid should use as its data source (required).
+ */
+ /**
+ * @cfg {Boolean} stripeRows <tt>true</tt> to stripe the rows. Default is <tt>false</tt>.
+ * <p>This causes the CSS class <tt><b>x-grid3-row-alt</b></tt> to be added to alternate rows of
+ * the grid. A default CSS rule is provided which sets a background colour, but you can override this
+ * with a rule which either overrides the <b>background-color</b> style using the '!important'
+ * modifier, or which uses a CSS selector of higher specificity.</p>
+ */
+ stripeRows : false,
+ /**
+ * @cfg {Boolean} trackMouseOver True to highlight rows when the mouse is over. Default is <tt>true</tt>
+ * for GridPanel, but <tt>false</tt> for EditorGridPanel.
+ */
+ trackMouseOver : true,
+ /**
+ * @cfg {Array} stateEvents
+ * An array of events that, when fired, should trigger this component to save its state.
+ * Defaults to:<pre><code>
+ * stateEvents: ['columnmove', 'columnresize', 'sortchange', 'groupchange']
+ * </code></pre>
+ * <p>These can be any types of events supported by this component, including browser or
+ * custom events (e.g., <tt>['click', 'customerchange']</tt>).</p>
+ * <p>See {@link Ext.Component#stateful} for an explanation of saving and restoring
+ * Component state.</p>
+ */
+ stateEvents : ['columnmove', 'columnresize', 'sortchange', 'groupchange'],
+ /**
+ * @cfg {Object} view The {@link Ext.grid.GridView} used by the grid. This can be set
+ * before a call to {@link Ext.Component#render render()}.
+ */
+ view : null,
+
+ /**
+ * @cfg {Array} bubbleEvents
+ * <p>An array of events that, when fired, should be bubbled to any parent container.
+ * See {@link Ext.util.Observable#enableBubble}.
+ * Defaults to <tt>[]</tt>.
+ */
+ bubbleEvents: [],
+
+ /**
+ * @cfg {Object} viewConfig A config object that will be applied to the grid's UI view. Any of
+ * the config options available for {@link Ext.grid.GridView} can be specified here. This option
+ * is ignored if <tt>{@link #view}</tt> is specified.
+ */
+
+ // private
+ rendered : false,
+ // private
+ viewReady : false,
+
+ // private
+ initComponent : function(){
+ Ext.grid.GridPanel.superclass.initComponent.call(this);
+
+ if(this.columnLines){
+ this.cls = (this.cls || '') + ' x-grid-with-col-lines';
+ }
+ // override any provided value since it isn't valid
+ // and is causing too many bug reports ;)
+ this.autoScroll = false;
+ this.autoWidth = false;
+
+ if(Ext.isArray(this.columns)){
+ this.colModel = new Ext.grid.ColumnModel(this.columns);
+ delete this.columns;
+ }
+
+ // check and correct shorthanded configs
+ if(this.ds){
+ this.store = this.ds;
+ delete this.ds;
+ }
+ if(this.cm){
+ this.colModel = this.cm;
+ delete this.cm;
+ }
+ if(this.sm){
+ this.selModel = this.sm;
+ delete this.sm;
+ }
+ this.store = Ext.StoreMgr.lookup(this.store);
+
+ this.addEvents(
+ // raw events
+ /**
+ * @event click
+ * The raw click event for the entire grid.
+ * @param {Ext.EventObject} e
+ */
+ 'click',
+ /**
+ * @event dblclick
+ * The raw dblclick event for the entire grid.
+ * @param {Ext.EventObject} e
+ */
+ 'dblclick',
+ /**
+ * @event contextmenu
+ * The raw contextmenu event for the entire grid.
+ * @param {Ext.EventObject} e
+ */
+ 'contextmenu',
+ /**
+ * @event mousedown
+ * The raw mousedown event for the entire grid.
+ * @param {Ext.EventObject} e
+ */
+ 'mousedown',
+ /**
+ * @event mouseup
+ * The raw mouseup event for the entire grid.
+ * @param {Ext.EventObject} e
+ */
+ 'mouseup',
+ /**
+ * @event mouseover
+ * The raw mouseover event for the entire grid.
+ * @param {Ext.EventObject} e
+ */
+ 'mouseover',
+ /**
+ * @event mouseout
+ * The raw mouseout event for the entire grid.
+ * @param {Ext.EventObject} e
+ */
+ 'mouseout',
+ /**
+ * @event keypress
+ * The raw keypress event for the entire grid.
+ * @param {Ext.EventObject} e
+ */
+ 'keypress',
+ /**
+ * @event keydown
+ * The raw keydown event for the entire grid.
+ * @param {Ext.EventObject} e
+ */
+ 'keydown',
+
+ // custom events
+ /**
+ * @event cellmousedown
+ * Fires before a cell is clicked
+ * @param {Grid} this
+ * @param {Number} rowIndex
+ * @param {Number} columnIndex
+ * @param {Ext.EventObject} e
+ */
+ 'cellmousedown',
+ /**
+ * @event rowmousedown
+ * Fires before a row is clicked
+ * @param {Grid} this
+ * @param {Number} rowIndex
+ * @param {Ext.EventObject} e
+ */
+ 'rowmousedown',
+ /**
+ * @event headermousedown
+ * Fires before a header is clicked
+ * @param {Grid} this
+ * @param {Number} columnIndex
+ * @param {Ext.EventObject} e
+ */
+ 'headermousedown',
+
+ /**
+ * @event groupmousedown
+ * Fires before a group header is clicked. <b>Only applies for grids with a {@link Ext.grid.GroupingView GroupingView}</b>.
+ * @param {Grid} this
+ * @param {String} groupField
+ * @param {String} groupValue
+ * @param {Ext.EventObject} e
+ */
+ 'groupmousedown',
+
+ /**
+ * @event rowbodymousedown
+ * Fires before the row body is clicked. <b>Only applies for grids with {@link Ext.grid.GridView#enableRowBody enableRowBody} configured.</b>
+ * @param {Grid} this
+ * @param {Number} rowIndex
+ * @param {Ext.EventObject} e
+ */
+ 'rowbodymousedown',
+
+ /**
+ * @event containermousedown
+ * Fires before the container is clicked. The container consists of any part of the grid body that is not covered by a row.
+ * @param {Grid} this
+ * @param {Ext.EventObject} e
+ */
+ 'containermousedown',
+
+ /**
+ * @event cellclick
+ * Fires when a cell is clicked.
+ * The data for the cell is drawn from the {@link Ext.data.Record Record}
+ * for this row. To access the data in the listener function use the
+ * following technique:
+ * <pre><code>
+function(grid, rowIndex, columnIndex, e) {
+ var record = grid.getStore().getAt(rowIndex); // Get the Record
+ var fieldName = grid.getColumnModel().getDataIndex(columnIndex); // Get field name
+ var data = record.get(fieldName);
+}
+</code></pre>
+ * @param {Grid} this
+ * @param {Number} rowIndex
+ * @param {Number} columnIndex
+ * @param {Ext.EventObject} e
+ */
+ 'cellclick',
+ /**
+ * @event celldblclick
+ * Fires when a cell is double clicked
+ * @param {Grid} this
+ * @param {Number} rowIndex
+ * @param {Number} columnIndex
+ * @param {Ext.EventObject} e
+ */
+ 'celldblclick',
+ /**
+ * @event rowclick
+ * Fires when a row is clicked
+ * @param {Grid} this
+ * @param {Number} rowIndex
+ * @param {Ext.EventObject} e
+ */
+ 'rowclick',
+ /**
+ * @event rowdblclick
+ * Fires when a row is double clicked
+ * @param {Grid} this
+ * @param {Number} rowIndex
+ * @param {Ext.EventObject} e
+ */
+ 'rowdblclick',
+ /**
+ * @event headerclick
+ * Fires when a header is clicked
+ * @param {Grid} this
+ * @param {Number} columnIndex
+ * @param {Ext.EventObject} e
+ */
+ 'headerclick',
+ /**
+ * @event headerdblclick
+ * Fires when a header cell is double clicked
+ * @param {Grid} this
+ * @param {Number} columnIndex
+ * @param {Ext.EventObject} e
+ */
+ 'headerdblclick',
+ /**
+ * @event groupclick
+ * Fires when group header is clicked. <b>Only applies for grids with a {@link Ext.grid.GroupingView GroupingView}</b>.
+ * @param {Grid} this
+ * @param {String} groupField
+ * @param {String} groupValue
+ * @param {Ext.EventObject} e
+ */
+ 'groupclick',
+ /**
+ * @event groupdblclick
+ * Fires when group header is double clicked. <b>Only applies for grids with a {@link Ext.grid.GroupingView GroupingView}</b>.
+ * @param {Grid} this
+ * @param {String} groupField
+ * @param {String} groupValue
+ * @param {Ext.EventObject} e
+ */
+ 'groupdblclick',
+ /**
+ * @event containerclick
+ * Fires when the container is clicked. The container consists of any part of the grid body that is not covered by a row.
+ * @param {Grid} this
+ * @param {Ext.EventObject} e
+ */
+ 'containerclick',
+ /**
+ * @event containerdblclick
+ * Fires when the container is double clicked. The container consists of any part of the grid body that is not covered by a row.
+ * @param {Grid} this
+ * @param {Ext.EventObject} e
+ */
+ 'containerdblclick',
+
+ /**
+ * @event rowbodyclick
+ * Fires when the row body is clicked. <b>Only applies for grids with {@link Ext.grid.GridView#enableRowBody enableRowBody} configured.</b>
+ * @param {Grid} this
+ * @param {Number} rowIndex
+ * @param {Ext.EventObject} e
+ */
+ 'rowbodyclick',
+ /**
+ * @event rowbodydblclick
+ * Fires when the row body is double clicked. <b>Only applies for grids with {@link Ext.grid.GridView#enableRowBody enableRowBody} configured.</b>
+ * @param {Grid} this
+ * @param {Number} rowIndex
+ * @param {Ext.EventObject} e
+ */
+ 'rowbodydblclick',
+
+ /**
+ * @event rowcontextmenu
+ * Fires when a row is right clicked
+ * @param {Grid} this
+ * @param {Number} rowIndex
+ * @param {Ext.EventObject} e
+ */
+ 'rowcontextmenu',
+ /**
+ * @event cellcontextmenu
+ * Fires when a cell is right clicked
+ * @param {Grid} this
+ * @param {Number} rowIndex
+ * @param {Number} cellIndex
+ * @param {Ext.EventObject} e
+ */
+ 'cellcontextmenu',
+ /**
+ * @event headercontextmenu
+ * Fires when a header is right clicked
+ * @param {Grid} this
+ * @param {Number} columnIndex
+ * @param {Ext.EventObject} e
+ */
+ 'headercontextmenu',
+ /**
+ * @event groupcontextmenu
+ * Fires when group header is right clicked. <b>Only applies for grids with a {@link Ext.grid.GroupingView GroupingView}</b>.
+ * @param {Grid} this
+ * @param {String} groupField
+ * @param {String} groupValue
+ * @param {Ext.EventObject} e
+ */
+ 'groupcontextmenu',
+ /**
+ * @event containercontextmenu
+ * Fires when the container is right clicked. The container consists of any part of the grid body that is not covered by a row.
+ * @param {Grid} this
+ * @param {Ext.EventObject} e
+ */
+ 'containercontextmenu',
+ /**
+ * @event rowbodycontextmenu
+ * Fires when the row body is right clicked. <b>Only applies for grids with {@link Ext.grid.GridView#enableRowBody enableRowBody} configured.</b>
+ * @param {Grid} this
+ * @param {Number} rowIndex
+ * @param {Ext.EventObject} e
+ */
+ 'rowbodycontextmenu',
+ /**
+ * @event bodyscroll
+ * Fires when the body element is scrolled
+ * @param {Number} scrollLeft
+ * @param {Number} scrollTop
+ */
+ 'bodyscroll',
+ /**
+ * @event columnresize
+ * Fires when the user resizes a column
+ * @param {Number} columnIndex
+ * @param {Number} newSize
+ */
+ 'columnresize',
+ /**
+ * @event columnmove
+ * Fires when the user moves a column
+ * @param {Number} oldIndex
+ * @param {Number} newIndex
+ */
+ 'columnmove',
+ /**
+ * @event sortchange
+ * Fires when the grid's store sort changes
+ * @param {Grid} this
+ * @param {Object} sortInfo An object with the keys field and direction
+ */
+ 'sortchange',
+ /**
+ * @event groupchange
+ * Fires when the grid's grouping changes (only applies for grids with a {@link Ext.grid.GroupingView GroupingView})
+ * @param {Grid} this
+ * @param {String} groupField A string with the grouping field, null if the store is not grouped.
+ */
+ 'groupchange',
+ /**
+ * @event reconfigure
+ * Fires when the grid is reconfigured with a new store and/or column model.
+ * @param {Grid} this
+ * @param {Ext.data.Store} store The new store
+ * @param {Ext.grid.ColumnModel} colModel The new column model
+ */
+ 'reconfigure',
+ /**
+ * @event viewready
+ * Fires when the grid view is available (use this for selecting a default row).
+ * @param {Grid} this
+ */
+ 'viewready'
+ );
+ },
+
+ // private
+ onRender : function(ct, position){
+ Ext.grid.GridPanel.superclass.onRender.apply(this, arguments);
+
+ var c = this.getGridEl();
+
+ this.el.addClass('x-grid-panel');
+
+ this.mon(c, {
+ scope: this,
+ mousedown: this.onMouseDown,
+ click: this.onClick,
+ dblclick: this.onDblClick,
+ contextmenu: this.onContextMenu
+ });
+
+ this.relayEvents(c, ['mousedown','mouseup','mouseover','mouseout','keypress', 'keydown']);
+
+ var view = this.getView();
+ view.init(this);
+ view.render();
+ this.getSelectionModel().init(this);
+ },
+
+ // private
+ initEvents : function(){
+ Ext.grid.GridPanel.superclass.initEvents.call(this);
+
+ if(this.loadMask){
+ this.loadMask = new Ext.LoadMask(this.bwrap,
+ Ext.apply({store:this.store}, this.loadMask));
+ }
+ },
+
+ initStateEvents : function(){
+ Ext.grid.GridPanel.superclass.initStateEvents.call(this);
+ this.mon(this.colModel, 'hiddenchange', this.saveState, this, {delay: 100});
+ },
+
+ applyState : function(state){
+ var cm = this.colModel,
+ cs = state.columns,
+ store = this.store,
+ s,
+ c,
+ oldIndex;
+
+ if(cs){
+ for(var i = 0, len = cs.length; i < len; i++){
+ s = cs[i];
+ c = cm.getColumnById(s.id);
+ if(c){
+ c.hidden = s.hidden;
+ c.width = s.width;
+ oldIndex = cm.getIndexById(s.id);
+ if(oldIndex != i){
+ cm.moveColumn(oldIndex, i);
+ }
+ }
+ }
+ }
+ if(store){
+ s = state.sort;
+ if(s){
+ store[store.remoteSort ? 'setDefaultSort' : 'sort'](s.field, s.direction);
+ }
+ s = state.group;
+ if(store.groupBy){
+ if(s){
+ store.groupBy(s);
+ }else{
+ store.clearGrouping();
+ }
+ }
+
+ }
+ var o = Ext.apply({}, state);
+ delete o.columns;
+ delete o.sort;
+ Ext.grid.GridPanel.superclass.applyState.call(this, o);
+ },
+
+ getState : function(){
+ var o = {columns: []},
+ store = this.store,
+ ss,
+ gs;
+
+ for(var i = 0, c; (c = this.colModel.config[i]); i++){
+ o.columns[i] = {
+ id: c.id,
+ width: c.width
+ };
+ if(c.hidden){
+ o.columns[i].hidden = true;
+ }
+ }
+ if(store){
+ ss = store.getSortState();
+ if(ss){
+ o.sort = ss;
+ }
+ if(store.getGroupState){
+ gs = store.getGroupState();
+ if(gs){
+ o.group = gs;
+ }
+ }
+ }
+ return o;
+ },
+
+ // private
+ afterRender : function(){
+ Ext.grid.GridPanel.superclass.afterRender.call(this);
+ var v = this.view;
+ this.on('bodyresize', v.layout, v);
+ v.layout();
+ if(this.deferRowRender){
+ if (!this.deferRowRenderTask){
+ this.deferRowRenderTask = new Ext.util.DelayedTask(v.afterRender, this.view);
+ }
+ this.deferRowRenderTask.delay(10);
+ }else{
+ v.afterRender();
+ }
+ this.viewReady = true;
+ },
+
+ /**
+ * <p>Reconfigures the grid to use a different Store and Column Model
+ * and fires the 'reconfigure' event. The View will be bound to the new
+ * objects and refreshed.</p>
+ * <p>Be aware that upon reconfiguring a GridPanel, certain existing settings <i>may</i> become
+ * invalidated. For example the configured {@link #autoExpandColumn} may no longer exist in the
+ * new ColumnModel. Also, an existing {@link Ext.PagingToolbar PagingToolbar} will still be bound
+ * to the old Store, and will need rebinding. Any {@link #plugins} might also need reconfiguring
+ * with the new data.</p>
+ * @param {Ext.data.Store} store The new {@link Ext.data.Store} object
+ * @param {Ext.grid.ColumnModel} colModel The new {@link Ext.grid.ColumnModel} object
+ */
+ reconfigure : function(store, colModel){
+ var rendered = this.rendered;
+ if(rendered){
+ if(this.loadMask){
+ this.loadMask.destroy();
+ this.loadMask = new Ext.LoadMask(this.bwrap,
+ Ext.apply({}, {store:store}, this.initialConfig.loadMask));
+ }
+ }
+ if(this.view){
+ this.view.initData(store, colModel);
+ }
+ this.store = store;
+ this.colModel = colModel;
+ if(rendered){
+ this.view.refresh(true);
+ }
+ this.fireEvent('reconfigure', this, store, colModel);
+ },
+
+ // private
+ onDestroy : function(){
+ if (this.deferRowRenderTask && this.deferRowRenderTask.cancel){
+ this.deferRowRenderTask.cancel();
+ }
+ if(this.rendered){
+ Ext.destroy(this.view, this.loadMask);
+ }else if(this.store && this.store.autoDestroy){
+ this.store.destroy();
+ }
+ Ext.destroy(this.colModel, this.selModel);
+ this.store = this.selModel = this.colModel = this.view = this.loadMask = null;
+ Ext.grid.GridPanel.superclass.onDestroy.call(this);
+ },
+
+ // private
+ processEvent : function(name, e){
+ this.view.processEvent(name, e);
+ },
+
+ // private
+ onClick : function(e){
+ this.processEvent('click', e);
+ },
+
+ // private
+ onMouseDown : function(e){
+ this.processEvent('mousedown', e);
+ },
+
+ // private
+ onContextMenu : function(e, t){
+ this.processEvent('contextmenu', e);
+ },
+
+ // private
+ onDblClick : function(e){
+ this.processEvent('dblclick', e);
+ },
+
+ // private
+ walkCells : function(row, col, step, fn, scope){
+ var cm = this.colModel,
+ clen = cm.getColumnCount(),
+ ds = this.store,
+ rlen = ds.getCount(),
+ first = true;
+
+ if(step < 0){
+ if(col < 0){
+ row--;
+ first = false;
+ }
+ while(row >= 0){
+ if(!first){
+ col = clen-1;
+ }
+ first = false;
+ while(col >= 0){
+ if(fn.call(scope || this, row, col, cm) === true){
+ return [row, col];
+ }
+ col--;
+ }
+ row--;
+ }
+ } else {
+ if(col >= clen){
+ row++;
+ first = false;
+ }
+ while(row < rlen){
+ if(!first){
+ col = 0;
+ }
+ first = false;
+ while(col < clen){
+ if(fn.call(scope || this, row, col, cm) === true){
+ return [row, col];
+ }
+ col++;
+ }
+ row++;
+ }
+ }
+ return null;
+ },
+
+ /**
+ * Returns the grid's underlying element.
+ * @return {Element} The element
+ */
+ getGridEl : function(){
+ return this.body;
+ },
+
+ // private for compatibility, overridden by editor grid
+ stopEditing : Ext.emptyFn,
+
+ /**
+ * Returns the grid's selection model configured by the <code>{@link #selModel}</code>
+ * configuration option. If no selection model was configured, this will create
+ * and return a {@link Ext.grid.RowSelectionModel RowSelectionModel}.
+ * @return {SelectionModel}
+ */
+ getSelectionModel : function(){
+ if(!this.selModel){
+ this.selModel = new Ext.grid.RowSelectionModel(
+ this.disableSelection ? {selectRow: Ext.emptyFn} : null);
+ }
+ return this.selModel;
+ },
+
+ /**
+ * Returns the grid's data store.
+ * @return {Ext.data.Store} The store
+ */
+ getStore : function(){
+ return this.store;
+ },
+
+ /**
+ * Returns the grid's ColumnModel.
+ * @return {Ext.grid.ColumnModel} The column model
+ */
+ getColumnModel : function(){
+ return this.colModel;
+ },
+
+ /**
+ * Returns the grid's GridView object.
+ * @return {Ext.grid.GridView} The grid view
+ */
+ getView : function(){
+ if(!this.view){
+ this.view = new Ext.grid.GridView(this.viewConfig);
+ }
+ return this.view;
+ },
+ /**
+ * Called to get grid's drag proxy text, by default returns this.ddText.
+ * @return {String} The text
+ */
+ getDragDropText : function(){
+ var count = this.selModel.getCount();
+ return String.format(this.ddText, count, count == 1 ? '' : 's');
+ }
+
+ /**
+ * @cfg {String/Number} activeItem
+ * @hide
+ */
+ /**
+ * @cfg {Boolean} autoDestroy
+ * @hide
+ */
+ /**
+ * @cfg {Object/String/Function} autoLoad
+ * @hide
+ */
+ /**
+ * @cfg {Boolean} autoWidth
+ * @hide
+ */
+ /**
+ * @cfg {Boolean/Number} bufferResize
+ * @hide
+ */
+ /**
+ * @cfg {String} defaultType
+ * @hide
+ */
+ /**
+ * @cfg {Object} defaults
+ * @hide
+ */
+ /**
+ * @cfg {Boolean} hideBorders
+ * @hide
+ */
+ /**
+ * @cfg {Mixed} items
+ * @hide
+ */
+ /**
+ * @cfg {String} layout
+ * @hide
+ */
+ /**
+ * @cfg {Object} layoutConfig
+ * @hide
+ */
+ /**
+ * @cfg {Boolean} monitorResize
+ * @hide
+ */
+ /**
+ * @property items
+ * @hide
+ */
+ /**
+ * @method add
+ * @hide
+ */
+ /**
+ * @method cascade
+ * @hide
+ */
+ /**
+ * @method doLayout
+ * @hide
+ */
+ /**
+ * @method find
+ * @hide
+ */
+ /**
+ * @method findBy
+ * @hide
+ */
+ /**
+ * @method findById
+ * @hide
+ */
+ /**
+ * @method findByType
+ * @hide
+ */
+ /**
+ * @method getComponent
+ * @hide
+ */
+ /**
+ * @method getLayout
+ * @hide
+ */
+ /**
+ * @method getUpdater
+ * @hide
+ */
+ /**
+ * @method insert
+ * @hide
+ */
+ /**
+ * @method load
+ * @hide
+ */
+ /**
+ * @method remove
+ * @hide
+ */
+ /**
+ * @event add
+ * @hide
+ */
+ /**
+ * @event afterlayout
+ * @hide
+ */
+ /**
+ * @event beforeadd
+ * @hide
+ */
+ /**
+ * @event beforeremove
+ * @hide
+ */
+ /**
+ * @event remove
+ * @hide
+ */
+
+
+
+ /**
+ * @cfg {String} allowDomMove @hide
+ */
+ /**
+ * @cfg {String} autoEl @hide
+ */
+ /**
+ * @cfg {String} applyTo @hide
+ */
+ /**
+ * @cfg {String} autoScroll @hide
+ */
+ /**
+ * @cfg {String} bodyBorder @hide
+ */
+ /**
+ * @cfg {String} bodyStyle @hide
+ */
+ /**
+ * @cfg {String} contentEl @hide
+ */
+ /**
+ * @cfg {String} disabledClass @hide
+ */
+ /**
+ * @cfg {String} elements @hide
+ */
+ /**
+ * @cfg {String} html @hide
+ */
+ /**
+ * @cfg {Boolean} preventBodyReset
+ * @hide
+ */
+ /**
+ * @property disabled
+ * @hide
+ */
+ /**
+ * @method applyToMarkup
+ * @hide
+ */
+ /**
+ * @method enable
+ * @hide
+ */
+ /**
+ * @method disable
+ * @hide
+ */
+ /**
+ * @method setDisabled
+ * @hide
+ */
+});
Ext.reg('grid', Ext.grid.GridPanel);/**
* @class Ext.grid.GridView
* @extends Ext.util.Observable
* @constructor
* @param {Object} config
*/
-Ext.grid.GridView = function(config){
- Ext.apply(this, config);
- // These events are only used internally by the grid components
- this.addEvents(
- /**
- * @event beforerowremoved
- * Internal UI Event. Fired before a row is removed.
- * @param {Ext.grid.GridView} view
- * @param {Number} rowIndex The index of the row to be removed.
- * @param {Ext.data.Record} record The Record to be removed
- */
- "beforerowremoved",
- /**
- * @event beforerowsinserted
- * Internal UI Event. Fired before rows are inserted.
- * @param {Ext.grid.GridView} view
- * @param {Number} firstRow The index of the first row to be inserted.
- * @param {Number} lastRow The index of the last row to be inserted.
- */
- "beforerowsinserted",
- /**
- * @event beforerefresh
- * Internal UI Event. Fired before the view is refreshed.
- * @param {Ext.grid.GridView} view
- */
- "beforerefresh",
- /**
- * @event rowremoved
- * Internal UI Event. Fired after a row is removed.
- * @param {Ext.grid.GridView} view
- * @param {Number} rowIndex The index of the row that was removed.
- * @param {Ext.data.Record} record The Record that was removed
- */
- "rowremoved",
- /**
- * @event rowsinserted
- * Internal UI Event. Fired after rows are inserted.
- * @param {Ext.grid.GridView} view
- * @param {Number} firstRow The index of the first inserted.
- * @param {Number} lastRow The index of the last row inserted.
- */
- "rowsinserted",
- /**
- * @event rowupdated
- * Internal UI Event. Fired after a row has been updated.
- * @param {Ext.grid.GridView} view
- * @param {Number} firstRow The index of the row updated.
- * @param {Ext.data.record} record The Record backing the row updated.
- */
- "rowupdated",
- /**
- * @event refresh
- * Internal UI Event. Fired after the GridView's body has been refreshed.
- * @param {Ext.grid.GridView} view
- */
- "refresh"
- );
- Ext.grid.GridView.superclass.constructor.call(this);
-};
-
-Ext.extend(Ext.grid.GridView, Ext.util.Observable, {
+Ext.grid.GridView = Ext.extend(Ext.util.Observable, {
/**
* Override this function to apply custom CSS classes to rows during rendering. You can also supply custom
* parameters to the row template for the current row to customize how it is rendered using the <b>rowParams</b>
}
return 'x-grid3-row-collapsed';
}
-},
+},
</code></pre>
* @param {Record} record The {@link Ext.data.Record} corresponding to the current row.
* @param {Number} index The row index.
* @method getRowClass
* @return {String} a CSS class name to add to the row.
*/
+
/**
* @cfg {Boolean} enableRowBody True to add a second TR element per row that can be used to provide a row body
* that spans beneath the data row. Use the {@link #getRowClass} method's rowParams config to customize the row body.
*/
+
/**
* @cfg {String} emptyText Default text (html tags are accepted) to display in the grid body when no rows
* are available (defaults to ''). This value will be used to update the <tt>{@link #mainBody}</tt>:
this.mainBody.update('<div class="x-grid-empty">' + this.emptyText + '</div>');
</code></pre>
*/
+
/**
- * @cfg {Boolean} headersDisabled True to disable the grid column headers (defaults to <tt>false</tt>).
+ * @cfg {Boolean} headersDisabled True to disable the grid column headers (defaults to <tt>false</tt>).
* Use the {@link Ext.grid.ColumnModel ColumnModel} <tt>{@link Ext.grid.ColumnModel#menuDisabled menuDisabled}</tt>
* config to disable the <i>menu</i> for individual columns. While this config is true the
* following will be disabled:<div class="mdetail-params"><ul>
* <li>the trigger to reveal the menu.</li>
* </ul></div>
*/
+
/**
* <p>A customized implementation of a {@link Ext.dd.DragZone DragZone} which provides default implementations
* of the template methods of DragZone to enable dragging of the selected rows of a GridPanel.
* @property dragZone
* @type {Ext.grid.GridDragZone}
*/
+
/**
* @cfg {Boolean} deferEmptyText True to defer <tt>{@link #emptyText}</tt> being applied until the store's
* first load (defaults to <tt>true</tt>).
*/
deferEmptyText : true,
+
/**
* @cfg {Number} scrollOffset The amount of space to reserve for the vertical scrollbar
- * (defaults to <tt>19</tt> pixels).
+ * (defaults to <tt>undefined</tt>). If an explicit value isn't specified, this will be automatically
+ * calculated.
*/
- scrollOffset : 19,
+ scrollOffset : undefined,
+
/**
* @cfg {Boolean} autoFill
* Defaults to <tt>false</tt>. Specify <tt>true</tt> to have the column widths re-proportioned
- * when the grid is <b>initially rendered</b>. The
+ * when the grid is <b>initially rendered</b>. The
* {@link Ext.grid.Column#width initially configured width}</tt> of each column will be adjusted
* to fit the grid width and prevent horizontal scrolling. If columns are later resized (manually
* or programmatically), the other columns in the grid will <b>not</b> be resized to fit the grid width.
* See <tt>{@link #forceFit}</tt> also.
*/
autoFill : false,
+
/**
* @cfg {Boolean} forceFit
* Defaults to <tt>false</tt>. Specify <tt>true</tt> to have the column widths re-proportioned
* to fit the grid width. See <tt>{@link #autoFill}</tt> also.
*/
forceFit : false,
+
/**
- * @cfg {Array} sortClasses The CSS classes applied to a header when it is sorted. (defaults to <tt>["sort-asc", "sort-desc"]</tt>)
+ * @cfg {Array} sortClasses The CSS classes applied to a header when it is sorted. (defaults to <tt>['sort-asc', 'sort-desc']</tt>)
*/
- sortClasses : ["sort-asc", "sort-desc"],
+ sortClasses : ['sort-asc', 'sort-desc'],
+
/**
- * @cfg {String} sortAscText The text displayed in the "Sort Ascending" menu item (defaults to <tt>"Sort Ascending"</tt>)
+ * @cfg {String} sortAscText The text displayed in the 'Sort Ascending' menu item (defaults to <tt>'Sort Ascending'</tt>)
*/
- sortAscText : "Sort Ascending",
+ sortAscText : 'Sort Ascending',
+
/**
- * @cfg {String} sortDescText The text displayed in the "Sort Descending" menu item (defaults to <tt>"Sort Descending"</tt>)
+ * @cfg {String} sortDescText The text displayed in the 'Sort Descending' menu item (defaults to <tt>'Sort Descending'</tt>)
*/
- sortDescText : "Sort Descending",
+ sortDescText : 'Sort Descending',
+
/**
- * @cfg {String} columnsText The text displayed in the "Columns" menu item (defaults to <tt>"Columns"</tt>)
+ * @cfg {String} columnsText The text displayed in the 'Columns' menu item (defaults to <tt>'Columns'</tt>)
*/
- columnsText : "Columns",
+ columnsText : 'Columns',
/**
- * @cfg {String} selectedRowClass The CSS class applied to a selected row (defaults to <tt>"x-grid3-row-selected"</tt>). An
+ * @cfg {String} selectedRowClass The CSS class applied to a selected row (defaults to <tt>'x-grid3-row-selected'</tt>). An
* example overriding the default styling:
<pre><code>
.x-grid3-row-selected {background-color: yellow;}
</code></pre>
* @type String
*/
- selectedRowClass : "x-grid3-row-selected",
+ selectedRowClass : 'x-grid3-row-selected',
// private
borderWidth : 2,
*/
rowSelectorDepth : 10,
+ /**
+ * @cfg {Number} rowBodySelectorDepth The number of levels to search for row bodies in event delegation (defaults to <tt>10</tt>)
+ */
+ rowBodySelectorDepth : 10,
+
/**
* @cfg {String} cellSelector The selector used to find cells internally (defaults to <tt>'td.x-grid3-cell'</tt>)
*/
* @cfg {String} rowSelector The selector used to find rows internally (defaults to <tt>'div.x-grid3-row'</tt>)
*/
rowSelector : 'div.x-grid3-row',
-
+
+ /**
+ * @cfg {String} rowBodySelector The selector used to find row bodies internally (defaults to <tt>'div.x-grid3-row'</tt>)
+ */
+ rowBodySelector : 'div.x-grid3-row-body',
+
// private
firstRowCls: 'x-grid3-row-first',
lastRowCls: 'x-grid3-row-last',
rowClsRe: /(?:^|\s+)x-grid3-row-(first|last|alt)(?:\s+|$)/g,
+ constructor : function(config){
+ Ext.apply(this, config);
+ // These events are only used internally by the grid components
+ this.addEvents(
+ /**
+ * @event beforerowremoved
+ * Internal UI Event. Fired before a row is removed.
+ * @param {Ext.grid.GridView} view
+ * @param {Number} rowIndex The index of the row to be removed.
+ * @param {Ext.data.Record} record The Record to be removed
+ */
+ 'beforerowremoved',
+ /**
+ * @event beforerowsinserted
+ * Internal UI Event. Fired before rows are inserted.
+ * @param {Ext.grid.GridView} view
+ * @param {Number} firstRow The index of the first row to be inserted.
+ * @param {Number} lastRow The index of the last row to be inserted.
+ */
+ 'beforerowsinserted',
+ /**
+ * @event beforerefresh
+ * Internal UI Event. Fired before the view is refreshed.
+ * @param {Ext.grid.GridView} view
+ */
+ 'beforerefresh',
+ /**
+ * @event rowremoved
+ * Internal UI Event. Fired after a row is removed.
+ * @param {Ext.grid.GridView} view
+ * @param {Number} rowIndex The index of the row that was removed.
+ * @param {Ext.data.Record} record The Record that was removed
+ */
+ 'rowremoved',
+ /**
+ * @event rowsinserted
+ * Internal UI Event. Fired after rows are inserted.
+ * @param {Ext.grid.GridView} view
+ * @param {Number} firstRow The index of the first inserted.
+ * @param {Number} lastRow The index of the last row inserted.
+ */
+ 'rowsinserted',
+ /**
+ * @event rowupdated
+ * Internal UI Event. Fired after a row has been updated.
+ * @param {Ext.grid.GridView} view
+ * @param {Number} firstRow The index of the row updated.
+ * @param {Ext.data.record} record The Record backing the row updated.
+ */
+ 'rowupdated',
+ /**
+ * @event refresh
+ * Internal UI Event. Fired after the GridView's body has been refreshed.
+ * @param {Ext.grid.GridView} view
+ */
+ 'refresh'
+ );
+ Ext.grid.GridView.superclass.constructor.call(this);
+ },
+
/* -------------------------------- UI Specific ----------------------------- */
// private
var ts = this.templates || {};
if(!ts.master){
ts.master = new Ext.Template(
- '<div class="x-grid3" hidefocus="true">',
- '<div class="x-grid3-viewport">',
- '<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>',
- '<div class="x-grid3-scroller"><div class="x-grid3-body" style="{bstyle}">{body}</div><a href="#" class="x-grid3-focus" tabIndex="-1"></a></div>',
- '</div>',
- '<div class="x-grid3-resize-marker"> </div>',
- '<div class="x-grid3-resize-proxy"> </div>',
- '</div>'
- );
+ '<div class="x-grid3" hidefocus="true">',
+ '<div class="x-grid3-viewport">',
+ '<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>',
+ '<div class="x-grid3-scroller"><div class="x-grid3-body" style="{bstyle}">{body}</div><a href="#" class="x-grid3-focus" tabIndex="-1"></a></div>',
+ '</div>',
+ '<div class="x-grid3-resize-marker"> </div>',
+ '<div class="x-grid3-resize-proxy"> </div>',
+ '</div>'
+ );
}
if(!ts.header){
ts.header = new Ext.Template(
- '<table border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
- '<thead><tr class="x-grid3-hd-row">{cells}</tr></thead>',
- '</table>'
- );
+ '<table border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
+ '<thead><tr class="x-grid3-hd-row">{cells}</tr></thead>',
+ '</table>'
+ );
}
if(!ts.hcell){
ts.hcell = new Ext.Template(
- '<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>' : '',
- '{value}<img class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
- '</div></td>'
- );
+ '<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>' : '',
+ '{value}<img class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
+ '</div></td>'
+ );
}
if(!ts.body){
if(!ts.row){
ts.row = new Ext.Template(
- '<div class="x-grid3-row {alt}" style="{tstyle}"><table class="x-grid3-row-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
- '<tbody><tr>{cells}</tr>',
- (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>' : ''),
- '</tbody></table></div>'
- );
+ '<div class="x-grid3-row {alt}" style="{tstyle}"><table class="x-grid3-row-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
+ '<tbody><tr>{cells}</tr>',
+ (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>' : ''),
+ '</tbody></table></div>'
+ );
}
if(!ts.cell){
for(var k in ts){
var t = ts[k];
- if(t && typeof t.compile == 'function' && !t.compiled){
+ if(t && Ext.isFunction(t.compile) && !t.compiled){
t.disableFormats = true;
t.compile();
}
}
this.templates = ts;
- this.colRe = new RegExp("x-grid3-td-([^\\s]+)", "");
+ this.colRe = new RegExp('x-grid3-td-([^\\s]+)', '');
},
// private
this.mainBody = new E(this.scroller.dom.firstChild);
this.focusEl = new E(this.scroller.dom.childNodes[1]);
- this.focusEl.swallowEvent("click", true);
+ this.focusEl.swallowEvent('click', true);
this.resizeMarker = new E(cs[1]);
this.resizeProxy = new E(cs[2]);
return this.fly(el).findParent(this.cellSelector, this.cellSelectorDepth);
},
-/**
- * <p>Return the index of the grid column which contains the passed element.</p>
- * See also {@link #findRowIndex}
- * @param {Element} el The target element
- * @return The column index, or <b>false</b> if the target element is not within a row of this GridView.
- */
+ /**
+ * <p>Return the index of the grid column which contains the passed HTMLElement.</p>
+ * See also {@link #findRowIndex}
+ * @param {HTMLElement} el The target element
+ * @return {Number} The column index, or <b>false</b> if the target element is not within a row of this GridView.
+ */
findCellIndex : function(el, requiredCls){
var cell = this.findCell(el);
if(cell && (!requiredCls || this.fly(cell).hasClass(requiredCls))){
return this.findCellIndex(el, this.hdCls);
},
-/**
- * Return the HtmlElement representing the grid row which contains the passed element.
- * @param {Element} el The target element
- * @return The row element, or null if the target element is not within a row of this GridView.
- */
+ /**
+ * Return the HtmlElement representing the grid row which contains the passed element.
+ * @param {HTMLElement} el The target HTMLElement
+ * @return {HTMLElement} The row element, or null if the target element is not within a row of this GridView.
+ */
findRow : function(el){
if(!el){
return false;
return this.fly(el).findParent(this.rowSelector, this.rowSelectorDepth);
},
-/**
- * <p>Return the index of the grid row which contains the passed element.</p>
- * See also {@link #findCellIndex}
- * @param {Element} el The target element
- * @return The row index, or <b>false</b> if the target element is not within a row of this GridView.
- */
+ /**
+ * <p>Return the index of the grid row which contains the passed HTMLElement.</p>
+ * See also {@link #findCellIndex}
+ * @param {HTMLElement} el The target HTMLElement
+ * @return {Number} The row index, or <b>false</b> if the target element is not within a row of this GridView.
+ */
findRowIndex : function(el){
var r = this.findRow(el);
return r ? r.rowIndex : false;
},
+ /**
+ * Return the HtmlElement representing the grid row body which contains the passed element.
+ * @param {HTMLElement} el The target HTMLElement
+ * @return {HTMLElement} The row body element, or null if the target element is not within a row body of this GridView.
+ */
+ findRowBody : function(el){
+ if(!el){
+ return false;
+ }
+ return this.fly(el).findParent(this.rowBodySelector, this.rowBodySelectorDepth);
+ },
+
// getter methods for fetching elements dynamically in the grid
-/**
- * Return the <tt><div></tt> HtmlElement which represents a Grid row for the specified index.
- * @param {Number} index The row index
- * @return {HtmlElement} The div element.
- */
+ /**
+ * Return the <tt><div></tt> HtmlElement which represents a Grid row for the specified index.
+ * @param {Number} index The row index
+ * @return {HtmlElement} The div element.
+ */
getRow : function(row){
return this.getRows()[row];
},
-/**
- * Returns the grid's <tt><td></tt> HtmlElement at the specified coordinates.
- * @param {Number} row The row index in which to find the cell.
- * @param {Number} col The column index of the cell.
- * @return {HtmlElement} The td at the specified coordinates.
- */
+ /**
+ * Returns the grid's <tt><td></tt> HtmlElement at the specified coordinates.
+ * @param {Number} row The row index in which to find the cell.
+ * @param {Number} col The column index of the cell.
+ * @return {HtmlElement} The td at the specified coordinates.
+ */
getCell : function(row, col){
return this.getRow(row).getElementsByTagName('td')[col];
},
-/**
- * Return the <tt><td></tt> HtmlElement which represents the Grid's header cell for the specified column index.
- * @param {Number} index The column index
- * @return {HtmlElement} The td element.
- */
+ /**
+ * Return the <tt><td></tt> HtmlElement which represents the Grid's header cell for the specified column index.
+ * @param {Number} index The column index
+ * @return {HtmlElement} The td element.
+ */
getHeaderCell : function(index){
- return this.mainHd.dom.getElementsByTagName('td')[index];
+ return this.mainHd.dom.getElementsByTagName('td')[index];
},
// manipulating elements
Ext.removeNode(this.getRow(row));
this.syncFocusEl(row);
},
-
+
// private
removeRows : function(firstRow, lastRow){
var bd = this.mainBody.dom;
// private
syncScroll : function(){
- this.syncHeaderScroll();
- var mb = this.scroller.dom;
- this.grid.fireEvent("bodyscroll", mb.scrollLeft, mb.scrollTop);
+ this.syncHeaderScroll();
+ var mb = this.scroller.dom;
+ this.grid.fireEvent('bodyscroll', mb.scrollLeft, mb.scrollTop);
},
// private
updateSortIcon : function(col, dir){
var sc = this.sortClasses;
var hds = this.mainHd.select('td').removeClass(sc);
- hds.item(col).addClass(sc[dir == "DESC" ? 1 : 0]);
+ hds.item(col).addClass(sc[dir == 'DESC' ? 1 : 0]);
},
// private
updateAllColumnWidths : function(){
- var tw = this.getTotalWidth(),
+ var tw = this.getTotalWidth(),
clen = this.cm.getColumnCount(),
- ws = [],
+ ws = [],
len,
i;
+
for(i = 0; i < clen; i++){
ws[i] = this.getColumnWidth(i);
}
+
this.innerHd.firstChild.style.width = this.getOffsetWidth();
this.innerHd.firstChild.firstChild.style.width = tw;
this.mainBody.dom.style.width = tw;
+
for(i = 0; i < clen; i++){
var hd = this.getHeaderCell(i);
hd.style.width = ws[i];
this.layout();
},
- // private
- doRender : function(cs, rs, ds, startRow, colCount, stripe){
- var ts = this.templates, ct = ts.cell, rt = ts.row, last = colCount-1;
- var tstyle = 'width:'+this.getTotalWidth()+';';
+ /**
+ * @private
+ * Renders all of the rows to a string buffer and returns the string. This is called internally
+ * by renderRows and performs the actual string building for the rows - it does not inject HTML into the DOM.
+ * @param {Array} columns The column data acquired from getColumnData.
+ * @param {Array} records The array of records to render
+ * @param {Ext.data.Store} store The store to render the rows from
+ * @param {Number} startRow The index of the first row being rendered. Sometimes we only render a subset of
+ * the rows so this is used to maintain logic for striping etc
+ * @param {Number} colCount The total number of columns in the column model
+ * @param {Boolean} stripe True to stripe the rows
+ * @return {String} A string containing the HTML for the rendered rows
+ */
+ doRender : function(columns, records, store, startRow, colCount, stripe) {
+ var templates = this.templates,
+ cellTemplate = templates.cell,
+ rowTemplate = templates.row,
+ last = colCount - 1;
+
+ var tstyle = 'width:' + this.getTotalWidth() + ';';
+
// buffers
- var buf = [], cb, c, p = {}, rp = {tstyle: tstyle}, r;
- for(var j = 0, len = rs.length; j < len; j++){
- r = rs[j]; cb = [];
- var rowIndex = (j+startRow);
- for(var i = 0; i < colCount; i++){
- c = cs[i];
- p.id = c.id;
- p.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
- p.attr = p.cellAttr = "";
- p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
- p.style = c.style;
- if(Ext.isEmpty(p.value)){
- p.value = " ";
+ var rowBuffer = [],
+ colBuffer = [],
+ rowParams = {tstyle: tstyle},
+ meta = {},
+ column,
+ record;
+
+ //build up each row's HTML
+ for (var j = 0, len = records.length; j < len; j++) {
+ record = records[j];
+ colBuffer = [];
+
+ var rowIndex = j + startRow;
+
+ //build up each column's HTML
+ for (var i = 0; i < colCount; i++) {
+ column = columns[i];
+
+ meta.id = column.id;
+ meta.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
+ meta.attr = meta.cellAttr = '';
+ meta.style = column.style;
+ meta.value = column.renderer.call(column.scope, record.data[column.name], meta, record, rowIndex, i, store);
+
+ if (Ext.isEmpty(meta.value)) {
+ meta.value = ' ';
}
- if(this.markDirty && r.dirty && typeof r.modified[c.name] !== 'undefined'){
- p.css += ' x-grid3-dirty-cell';
+
+ if (this.markDirty && record.dirty && Ext.isDefined(record.modified[column.name])) {
+ meta.css += ' x-grid3-dirty-cell';
}
- cb[cb.length] = ct.apply(p);
+
+ colBuffer[colBuffer.length] = cellTemplate.apply(meta);
}
+
+ //set up row striping and row dirtiness CSS classes
var alt = [];
- if(stripe && ((rowIndex+1) % 2 === 0)){
- alt[0] = "x-grid3-row-alt";
+
+ if (stripe && ((rowIndex + 1) % 2 === 0)) {
+ alt[0] = 'x-grid3-row-alt';
}
- if(r.dirty){
- alt[1] = " x-grid3-dirty-row";
+
+ if (record.dirty) {
+ alt[1] = ' x-grid3-dirty-row';
}
- rp.cols = colCount;
- if(this.getRowClass){
- alt[2] = this.getRowClass(r, rowIndex, rp, ds);
+
+ rowParams.cols = colCount;
+
+ if (this.getRowClass) {
+ alt[2] = this.getRowClass(record, rowIndex, rowParams, store);
}
- rp.alt = alt.join(" ");
- rp.cells = cb.join("");
- buf[buf.length] = rt.apply(rp);
+
+ rowParams.alt = alt.join(' ');
+ rowParams.cells = colBuffer.join('');
+
+ rowBuffer[rowBuffer.length] = rowTemplate.apply(rowParams);
}
- return buf.join("");
+
+ return rowBuffer.join('');
},
// private
- processRows : function(startRow, skipStripe){
- if(!this.ds || this.ds.getCount() < 1){
+ processRows : function(startRow, skipStripe) {
+ if (!this.ds || this.ds.getCount() < 1) {
return;
}
- var rows = this.getRows();
+
+ var rows = this.getRows(),
+ len = rows.length,
+ i, r;
+
skipStripe = skipStripe || !this.grid.stripeRows;
- startRow = startRow || 0;
- Ext.each(rows, function(row, idx){
- row.rowIndex = idx;
- row.className = row.className.replace(this.rowClsRe, ' ');
- if (!skipStripe && (idx + 1) % 2 === 0) {
- row.className += ' x-grid3-row-alt';
+ startRow = startRow || 0;
+
+ for (i = 0; i<len; i++) {
+ r = rows[i];
+ if (r) {
+ r.rowIndex = i;
+ if (!skipStripe) {
+ r.className = r.className.replace(this.rowClsRe, ' ');
+ if ((i + 1) % 2 === 0){
+ r.className += ' x-grid3-row-alt';
+ }
+ }
}
- });
+ }
+
// add first/last-row classes
- if(startRow === 0){
+ if (startRow === 0) {
Ext.fly(rows[0]).addClass(this.firstRowCls);
}
+
Ext.fly(rows[rows.length - 1]).addClass(this.lastRowCls);
},
if(this.deferEmptyText !== true){
this.applyEmptyText();
}
+ this.grid.fireEvent('viewready', this.grid);
},
- // private
- renderUI : function(){
-
- var header = this.renderHeaders();
- var body = this.templates.body.apply({rows:' '});
-
+ /**
+ * @private
+ * Renders each of the UI elements in turn. This is called internally, once, by this.render. It does not
+ * render rows from the store, just the surrounding UI elements. It also sets up listeners on the UI elements
+ * and sets up options like column menus, moving and resizing.
+ */
+ renderUI : function() {
+ var templates = this.templates,
+ header = this.renderHeaders(),
+ body = templates.body.apply({rows:' '});
- var html = this.templates.master.apply({
- body: body,
+ var html = templates.master.apply({
+ body : body,
header: header,
- ostyle: 'width:'+this.getOffsetWidth()+';',
- bstyle: 'width:'+this.getTotalWidth()+';'
+ ostyle: 'width:' + this.getOffsetWidth() + ';',
+ bstyle: 'width:' + this.getTotalWidth() + ';'
});
var g = this.grid;
this.initElements();
// get mousedowns early
- Ext.fly(this.innerHd).on("click", this.handleHdDown, this);
+ Ext.fly(this.innerHd).on('click', this.handleHdDown, this);
+
this.mainHd.on({
- scope: this,
+ scope : this,
mouseover: this.handleHdOver,
- mouseout: this.handleHdOut,
+ mouseout : this.handleHdOut,
mousemove: this.handleHdMove
});
this.scroller.on('scroll', this.syncScroll, this);
- if(g.enableColumnResize !== false){
+ if (g.enableColumnResize !== false) {
this.splitZone = new Ext.grid.GridView.SplitDragZone(g, this.mainHd.dom);
}
- if(g.enableColumnMove){
+ if (g.enableColumnMove) {
this.columnDrag = new Ext.grid.GridView.ColumnDragZone(g, this.innerHd);
this.columnDrop = new Ext.grid.HeaderDropZone(g, this.mainHd.dom);
}
- if(g.enableHdMenu !== false){
- this.hmenu = new Ext.menu.Menu({id: g.id + "-hctx"});
+ if (g.enableHdMenu !== false) {
+ this.hmenu = new Ext.menu.Menu({id: g.id + '-hctx'});
this.hmenu.add(
- {itemId:"asc", text: this.sortAscText, cls: "xg-hmenu-sort-asc"},
- {itemId:"desc", text: this.sortDescText, cls: "xg-hmenu-sort-desc"}
+ {itemId:'asc', text: this.sortAscText, cls: 'xg-hmenu-sort-asc'},
+ {itemId:'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'}
);
- if(g.enableColumnHide !== false){
- this.colMenu = new Ext.menu.Menu({id:g.id + "-hcols-menu"});
+
+ if (g.enableColumnHide !== false) {
+ this.colMenu = new Ext.menu.Menu({id:g.id + '-hcols-menu'});
this.colMenu.on({
- scope: this,
+ scope : this,
beforeshow: this.beforeColMenuShow,
- itemclick: this.handleHdMenuClick
+ itemclick : this.handleHdMenuClick
});
this.hmenu.add('-', {
- itemId:"columns",
+ itemId:'columns',
hideOnClick: false,
text: this.columnsText,
menu: this.colMenu,
iconCls: 'x-cols-icon'
});
}
- this.hmenu.on("itemclick", this.handleHdMenuClick, this);
+
+ this.hmenu.on('itemclick', this.handleHdMenuClick, this);
}
- if(g.trackMouseOver){
+ if (g.trackMouseOver) {
this.mainBody.on({
- scope: this,
+ scope : this,
mouseover: this.onRowOver,
- mouseout: this.onRowOut
+ mouseout : this.onRowOut
});
}
- if(g.enableDragDrop || g.enableDrag){
+ if (g.enableDragDrop || g.enableDrag) {
this.dragZone = new Ext.grid.GridDragZone(g, {
ddGroup : g.ddGroup || 'GridDD'
});
}
this.updateHeaderSortState();
+ },
+ // private
+ processEvent : function(name, e) {
+ var t = e.getTarget(),
+ g = this.grid,
+ header = this.findHeaderIndex(t);
+ g.fireEvent(name, e);
+ if (header !== false) {
+ g.fireEvent('header' + name, g, header, e);
+ } else {
+ var row = this.findRowIndex(t),
+ cell,
+ body;
+ if (row !== false) {
+ g.fireEvent('row' + name, g, row, e);
+ cell = this.findCellIndex(t);
+ if (cell !== false) {
+ g.fireEvent('cell' + name, g, row, cell, e);
+ } else {
+ body = this.findRowBody(t);
+ if (body) {
+ g.fireEvent('rowbody' + name, g, row, e);
+ }
+ }
+ } else {
+ g.fireEvent('container' + name, g, e);
+ }
+ }
},
// private
- layout : function(){
+ layout : function() {
if(!this.mainBody){
return; // not rendered
}
if(!g.hideHeaders && (vw < 20 || csize.height < 20)){ // display: none?
return;
}
-
+
if(g.autoHeight){
this.scroller.dom.style.overflow = 'visible';
if(Ext.isWebKit){
getColumnId : function(index){
return this.cm.getColumnId(index);
},
-
- // private
+
+ // private
getOffsetWidth : function() {
- return (this.cm.getTotalWidth() + this.scrollOffset) + 'px';
+ return (this.cm.getTotalWidth() + this.getScrollOffset()) + 'px';
},
- // private
- renderHeaders : function(){
- var cm = this.cm,
- ts = this.templates,
- ct = ts.hcell,
- cb = [],
- p = {},
- len = cm.getColumnCount(),
+ getScrollOffset: function(){
+ return Ext.num(this.scrollOffset, Ext.getScrollBarWidth());
+ },
+
+ /**
+ * @private
+ * Renders the header row using the 'header' template. Does not inject the HTML into the DOM, just
+ * returns a string.
+ * @return {String} Rendered header row
+ */
+ renderHeaders : function() {
+ var cm = this.cm,
+ ts = this.templates,
+ ct = ts.hcell,
+ cb = [],
+ p = {},
+ len = cm.getColumnCount(),
last = len - 1;
-
- for(var i = 0; i < len; i++){
+
+ for (var i = 0; i < len; i++) {
p.id = cm.getColumnId(i);
- p.value = cm.getColumnHeader(i) || "";
+ p.value = cm.getColumnHeader(i) || '';
p.style = this.getColumnStyle(i, true);
p.tooltip = this.getColumnTooltip(i);
p.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
- if(cm.config[i].align == 'right'){
+
+ if (cm.config[i].align == 'right') {
p.istyle = 'padding-right:16px';
} else {
delete p.istyle;
}
cb[cb.length] = ct.apply(p);
}
- return ts.header.apply({cells: cb.join(""), tstyle:'width:'+this.getTotalWidth()+';'});
+ return ts.header.apply({cells: cb.join(''), tstyle:'width:'+this.getTotalWidth()+';'});
},
// private
return 'title="'+tt+'"';
}
}
- return "";
+ return '';
},
// private
},
resolveCell : function(row, col, hscroll){
- if(typeof row != "number"){
+ if(!Ext.isNumber(row)){
row = row.rowIndex;
}
if(!this.ds){
var xy = row;
if(!Ext.isArray(xy)){
row = Math.min(row, Math.max(0, this.getRows().length-1));
+ if (isNaN(row)) {
+ return;
+ }
xy = this.getResolvedXY(this.resolveCell(row, col, hscroll));
}
this.focusEl.setXY(xy||this.scroller.getXY());
return;
}
- var rowEl = resolved.row,
+ var rowEl = resolved.row,
cellEl = resolved.cell,
c = this.scroller.dom,
ctop = 0,
- p = rowEl,
+ p = rowEl,
stop = this.el.dom;
-
+
while(p && p != stop){
ctop += p.offsetTop;
p = p.offsetParent;
}
+
ctop -= this.mainHd.dom.offsetHeight;
+ stop = parseInt(c.scrollTop, 10);
var cbot = ctop + rowEl.offsetHeight,
ch = c.clientHeight,
sbot = stop + ch;
-
- stop = parseInt(c.scrollTop, 10);
-
+
if(ctop < stop){
c.scrollTop = ctop;
},
// private
- insertRows : function(dm, firstRow, lastRow, isUpdate){
+ insertRows : function(dm, firstRow, lastRow, isUpdate) {
var last = dm.getCount() - 1;
- if(!isUpdate && firstRow === 0 && lastRow >= last){
- this.refresh();
- }else{
- if(!isUpdate){
- this.fireEvent("beforerowsinserted", this, firstRow, lastRow);
+ if( !isUpdate && firstRow === 0 && lastRow >= last) {
+ this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
+ this.refresh();
+ this.fireEvent('rowsinserted', this, firstRow, lastRow);
+ } else {
+ if (!isUpdate) {
+ this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
}
var html = this.renderRows(firstRow, lastRow),
before = this.getRow(firstRow);
- if(before){
+ if (before) {
if(firstRow === 0){
Ext.fly(this.getRow(0)).removeClass(this.firstRowCls);
}
Ext.DomHelper.insertHtml('beforeBegin', before, html);
- }else{
+ } else {
var r = this.getRow(last - 1);
if(r){
Ext.fly(r).removeClass(this.lastRowCls);
}
Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html);
}
- if(!isUpdate){
- this.fireEvent("rowsinserted", this, firstRow, lastRow);
+ if (!isUpdate) {
+ this.fireEvent('rowsinserted', this, firstRow, lastRow);
this.processRows(firstRow);
- }else if(firstRow === 0 || firstRow >= last){
+ } else if (firstRow === 0 || firstRow >= last) {
//ensure first/last row is kept after an update.
Ext.fly(this.getRow(firstRow)).addClass(firstRow === 0 ? this.firstRowCls : this.lastRowCls);
}
if(dm.getRowCount()<1){
this.refresh();
}else{
- this.fireEvent("beforerowsdeleted", this, firstRow, lastRow);
+ this.fireEvent('beforerowsdeleted', this, firstRow, lastRow);
this.removeRows(firstRow, lastRow);
this.processRows(firstRow);
- this.fireEvent("rowsdeleted", this, firstRow, lastRow);
+ this.fireEvent('rowsdeleted', this, firstRow, lastRow);
}
},
// private
getColumnWidth : function(col){
var w = this.cm.getColumnWidth(col);
- if(typeof w == 'number'){
- return (Ext.isBorderBox ? w : (w-this.borderWidth > 0 ? w-this.borderWidth:0)) + 'px';
+ if(Ext.isNumber(w)){
+ return (Ext.isBorderBox || (Ext.isWebKit && !Ext.isSafari2) ? w : (w - this.borderWidth > 0 ? w - this.borderWidth : 0)) + 'px';
}
return w;
},
fitColumns : function(preventRefresh, onlyExpand, omitColumn){
var cm = this.cm, i;
var tw = cm.getTotalWidth(false);
- var aw = this.grid.getGridEl().getWidth(true)-this.scrollOffset;
+ var aw = this.grid.getGridEl().getWidth(true)-this.getScrollOffset();
if(aw < 20){ // not initialized, so don't screw up the default widths
return;
}
var vc = cm.getColumnCount(true);
- var ac = vc-(typeof omitColumn == 'number' ? 1 : 0);
+ var ac = vc-(Ext.isNumber(omitColumn) ? 1 : 0);
if(ac === 0){
ac = 1;
omitColumn = undefined;
var g = this.grid, cm = this.cm;
if(!this.userResized && g.autoExpandColumn){
var tw = cm.getTotalWidth(false);
- var aw = this.grid.getGridEl().getWidth(true)-this.scrollOffset;
+ var aw = this.grid.getGridEl().getWidth(true)-this.getScrollOffset();
if(tw != aw){
var ci = cm.getIndexById(g.autoExpandColumn);
var currentWidth = cm.getColumnWidth(ci);
}
},
- // private
+ /**
+ * @private
+ * Returns an array of column configurations - one for each column
+ * @return {Array} Array of column config objects. This includes the column name, renderer, id style and renderer
+ */
getColumnData : function(){
// build a map for all the columns
- var cs = [], cm = this.cm, colCount = cm.getColumnCount();
- for(var i = 0; i < colCount; i++){
+ var cs = [],
+ cm = this.cm,
+ colCount = cm.getColumnCount();
+
+ for (var i = 0; i < colCount; i++) {
var name = cm.getDataIndex(i);
+
cs[i] = {
- name : (typeof name == 'undefined' ? this.ds.fields.get(i).name : name),
- renderer : cm.getRenderer(i),
- id : cm.getColumnId(i),
- style : this.getColumnStyle(i)
+ name : (!Ext.isDefined(name) ? this.ds.fields.get(i).name : name),
+ renderer: cm.getRenderer(i),
+ scope : cm.getRendererScope(i),
+ id : cm.getColumnId(i),
+ style : this.getColumnStyle(i)
};
}
+
return cs;
},
var colCount = cm.getColumnCount();
if(ds.getCount() < 1){
- return "";
+ return '';
}
var cs = this.getColumnData();
startRow = startRow || 0;
- endRow = typeof endRow == "undefined"? ds.getCount()-1 : endRow;
+ endRow = !Ext.isDefined(endRow) ? ds.getCount()-1 : endRow;
// records to render
var rs = ds.getRange(startRow, endRow);
// private
refreshRow : function(record){
var ds = this.ds, index;
- if(typeof record == 'number'){
+ if(Ext.isNumber(record)){
index = record;
record = ds.getAt(index);
if(!record){
this.insertRows(ds, index, index, true);
this.getRow(index).rowIndex = index;
this.onRemove(ds, record, index+1, true);
- this.fireEvent("rowupdated", this, index, record);
+ this.fireEvent('rowupdated', this, index, record);
},
/**
* @param {Boolean} headersToo (optional) True to also refresh the headers
*/
refresh : function(headersToo){
- this.fireEvent("beforerefresh", this);
+ this.fireEvent('beforerefresh', this);
this.grid.stopEditing(true);
var result = this.renderBody();
this.processRows(0, true);
this.layout();
this.applyEmptyText();
- this.fireEvent("refresh", this);
+ this.fireEvent('refresh', this);
},
- // private
+ /**
+ * @private
+ * Displays the configured emptyText if there are currently no rows to display
+ */
applyEmptyText : function(){
if(this.emptyText && !this.hasRows()){
this.mainBody.update('<div class="x-grid-empty">' + this.emptyText + '</div>');
}
},
- // private
+ /**
+ * @private
+ * Adds sorting classes to the column headers based on the bound store's sortInfo. Fires the 'sortchange' event
+ * if the sorting has changed since this function was last run.
+ */
updateHeaderSortState : function(){
var state = this.ds.getSortState();
- if(!state){
+ if (!state) {
return;
}
- if(!this.sortState || (this.sortState.field != state.field || this.sortState.direction != state.direction)){
+
+ if (!this.sortState || (this.sortState.field != state.field || this.sortState.direction != state.direction)) {
this.grid.fireEvent('sortchange', this.grid, state);
}
+
this.sortState = state;
+
var sortColumn = this.cm.findColumnIndex(state.field);
- if(sortColumn != -1){
+ if (sortColumn != -1){
var sortDir = state.direction;
this.updateSortIcon(sortColumn, sortDir);
}
},
+ /**
+ * @private
+ * Removes any sorting indicator classes from the column headers
+ */
+ clearHeaderSortState : function(){
+ if (!this.sortState) {
+ return;
+ }
+ this.grid.fireEvent('sortchange', this.grid, null);
+ this.mainHd.select('td').removeClass(this.sortClasses);
+ delete this.sortState;
+ },
+
// private
destroy : function(){
+ if (this.scrollToTopTask && this.scrollToTopTask.cancel){
+ this.scrollToTopTask.cancel();
+ }
if(this.colMenu){
Ext.menu.MenuMgr.unregister(this.colMenu);
this.colMenu.destroy();
this.hmenu.destroy();
delete this.hmenu;
}
+
+ this.initData(null, null);
+ this.purgeListeners();
+ Ext.fly(this.innerHd).un("click", this.handleHdDown, this);
+
if(this.grid.enableColumnMove){
- var dds = Ext.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id];
- if(dds){
- for(var dd in dds){
- if(!dds[dd].config.isTarget && dds[dd].dragElId){
- var elid = dds[dd].dragElId;
- dds[dd].unreg();
- Ext.get(elid).remove();
- } else if(dds[dd].config.isTarget){
- dds[dd].proxyTop.remove();
- dds[dd].proxyBottom.remove();
- dds[dd].unreg();
- }
- if(Ext.dd.DDM.locationCache[dd]){
- delete Ext.dd.DDM.locationCache[dd];
- }
- }
- delete Ext.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id];
+ Ext.destroy(
+ this.columnDrag.el,
+ this.columnDrag.proxy.ghost,
+ this.columnDrag.proxy.el,
+ this.columnDrop.el,
+ this.columnDrop.proxyTop,
+ this.columnDrop.proxyBottom,
+ this.columnDrag.dragData.ddel,
+ this.columnDrag.dragData.header
+ );
+ if (this.columnDrag.proxy.anim) {
+ Ext.destroy(this.columnDrag.proxy.anim);
}
+ delete this.columnDrag.proxy.ghost;
+ delete this.columnDrag.dragData.ddel;
+ delete this.columnDrag.dragData.header;
+ this.columnDrag.destroy();
+ delete Ext.dd.DDM.locationCache[this.columnDrag.id];
+ delete this.columnDrag._domRef;
+
+ delete this.columnDrop.proxyTop;
+ delete this.columnDrop.proxyBottom;
+ this.columnDrop.destroy();
+ delete Ext.dd.DDM.locationCache["gridHeader" + this.grid.getGridEl().id];
+ delete this.columnDrop._domRef;
+ delete Ext.dd.DDM.ids[this.columnDrop.ddGroup];
}
- if(this.dragZone){
- this.dragZone.unreg();
+ if (this.splitZone){ // enableColumnResize
+ this.splitZone.destroy();
+ delete this.splitZone._domRef;
+ delete Ext.dd.DDM.ids["gridSplitters" + this.grid.getGridEl().id];
}
-
+
Ext.fly(this.innerHd).removeAllListeners();
Ext.removeNode(this.innerHd);
-
- Ext.destroy(this.resizeMarker, this.resizeProxy, this.focusEl, this.mainBody,
- this.scroller, this.mainHd, this.mainWrap, this.dragZone,
- this.splitZone, this.columnDrag, this.columnDrop);
+ delete this.innerHd;
+
+ Ext.destroy(
+ this.el,
+ this.mainWrap,
+ this.mainHd,
+ this.scroller,
+ this.mainBody,
+ this.focusEl,
+ this.resizeMarker,
+ this.resizeProxy,
+ this.activeHdBtn,
+ this.dragZone,
+ this.splitZone,
+ this._flyweight
+ );
+
+ delete this.grid.container;
+
+ if(this.dragZone){
+ this.dragZone.destroy();
+ }
+
+ Ext.dd.DDM.currentTarget = null;
+ delete Ext.dd.DDM.locationCache[this.grid.getGridEl().id];
- this.initData(null, null);
Ext.EventManager.removeResizeListener(this.onWindowResize, this);
- this.purgeListeners();
},
// private
if(this.autoFill){
var ct = this.grid.ownerCt;
if (ct && ct.getLayout()){
- ct.on('afterlayout', function(){
+ ct.on('afterlayout', function(){
this.fitColumns(true, true);
- this.updateHeaders();
- }, this, {single: true});
- }else{
- this.fitColumns(true, true);
+ this.updateHeaders();
+ }, this, {single: true});
+ }else{
+ this.fitColumns(true, true);
}
}else if(this.forceFit){
this.fitColumns(true, false);
// private
initData : function(ds, cm){
if(this.ds){
- this.ds.un("load", this.onLoad, this);
- this.ds.un("datachanged", this.onDataChange, this);
- this.ds.un("add", this.onAdd, this);
- this.ds.un("remove", this.onRemove, this);
- this.ds.un("update", this.onUpdate, this);
- this.ds.un("clear", this.onClear, this);
+ this.ds.un('load', this.onLoad, this);
+ this.ds.un('datachanged', this.onDataChange, this);
+ this.ds.un('add', this.onAdd, this);
+ this.ds.un('remove', this.onRemove, this);
+ this.ds.un('update', this.onUpdate, this);
+ this.ds.un('clear', this.onClear, this);
if(this.ds !== ds && this.ds.autoDestroy){
this.ds.destroy();
}
this.ds = ds;
if(this.cm){
- this.cm.un("configchange", this.onColConfigChange, this);
- this.cm.un("widthchange", this.onColWidthChange, this);
- this.cm.un("headerchange", this.onHeaderChange, this);
- this.cm.un("hiddenchange", this.onHiddenChange, this);
- this.cm.un("columnmoved", this.onColumnMove, this);
+ this.cm.un('configchange', this.onColConfigChange, this);
+ this.cm.un('widthchange', this.onColWidthChange, this);
+ this.cm.un('headerchange', this.onHeaderChange, this);
+ this.cm.un('hiddenchange', this.onHiddenChange, this);
+ this.cm.un('columnmoved', this.onColumnMove, this);
}
if(cm){
delete this.lastViewWidth;
// private
onRemove : function(ds, record, index, isUpdate){
if(isUpdate !== true){
- this.fireEvent("beforerowremoved", this, index, record);
+ this.fireEvent('beforerowremoved', this, index, record);
}
this.removeRow(index);
if(isUpdate !== true){
this.processRows(index);
this.applyEmptyText();
- this.fireEvent("rowremoved", this, index, record);
+ this.fireEvent('rowremoved', this, index, record);
}
},
// private
onLoad : function(){
- this.scrollToTop();
+ if (Ext.isGecko){
+ if (!this.scrollToTopTask) {
+ this.scrollToTopTask = new Ext.util.DelayedTask(this.scrollToTop, this);
+ }
+ this.scrollToTopTask.delay(1);
+ }else{
+ this.scrollToTop();
+ }
},
// private
/* -------------------- UI Events and Handlers ------------------------------ */
// private
initUI : function(grid){
- grid.on("headerclick", this.onHeaderClick, this);
+ grid.on('headerclick', this.onHeaderClick, this);
},
// private
onRowOver : function(e, t){
var row;
if((row = this.findRowIndex(t)) !== false){
- this.addRowClass(row, "x-grid3-row-over");
+ this.addRowClass(row, 'x-grid3-row-over');
}
},
onRowOut : function(e, t){
var row;
if((row = this.findRowIndex(t)) !== false && !e.within(this.getRow(row), true)){
- this.removeRowClass(row, "x-grid3-row-over");
+ this.removeRowClass(row, 'x-grid3-row-over');
}
},
onCellSelect : function(row, col){
var cell = this.getCell(row, col);
if(cell){
- this.fly(cell).addClass("x-grid3-cell-selected");
+ this.fly(cell).addClass('x-grid3-cell-selected');
}
},
onCellDeselect : function(row, col){
var cell = this.getCell(row, col);
if(cell){
- this.fly(cell).removeClass("x-grid3-cell-selected");
+ this.fly(cell).removeClass('x-grid3-cell-selected');
}
},
this.syncHeaderScroll();
}
- this.grid.fireEvent("columnresize", i, w);
+ this.grid.fireEvent('columnresize', i, w);
},
// private
handleHdMenuClick : function(item){
- var index = this.hdCtxIndex;
- var cm = this.cm, ds = this.ds;
- switch(item.itemId){
- case "asc":
- ds.sort(cm.getDataIndex(index), "ASC");
+ var index = this.hdCtxIndex,
+ cm = this.cm,
+ ds = this.ds,
+ id = item.getItemId();
+ switch(id){
+ case 'asc':
+ ds.sort(cm.getDataIndex(index), 'ASC');
break;
- case "desc":
- ds.sort(cm.getDataIndex(index), "DESC");
+ case 'desc':
+ ds.sort(cm.getDataIndex(index), 'DESC');
break;
default:
- index = cm.getIndexById(item.itemId.substr(4));
+ index = cm.getIndexById(id.substr(4));
if(index != -1){
if(item.checked && cm.getColumnsBy(this.isHideableColumn, this).length <= 1){
this.onDenyColumnHide();
// private
isHideableColumn : function(c){
- return !c.hidden && !c.fixed;
+ return !c.hidden;
},
// private
var cm = this.cm, colCount = cm.getColumnCount();
this.colMenu.removeAll();
for(var i = 0; i < colCount; i++){
- if(cm.config[i].fixed !== true && cm.config[i].hideable !== false){
+ if(cm.config[i].hideable !== false){
this.colMenu.add(new Ext.menu.CheckItem({
- itemId: "col-"+cm.getColumnId(i),
+ itemId: 'col-'+cm.getColumnId(i),
text: cm.getColumnHeader(i),
checked: !cm.isHidden(i),
hideOnClick:false,
var index = this.getCellIndex(hd);
this.hdCtxIndex = index;
var ms = this.hmenu.items, cm = this.cm;
- ms.get("asc").setDisabled(!cm.isSortable(index));
- ms.get("desc").setDisabled(!cm.isSortable(index));
- this.hmenu.on("hide", function(){
+ ms.get('asc').setDisabled(!cm.isSortable(index));
+ ms.get('desc').setDisabled(!cm.isSortable(index));
+ this.hmenu.on('hide', function(){
Ext.fly(hd).removeClass('x-grid3-hd-menu-open');
}, this, {single:true});
- this.hmenu.show(t, "tl-bl?");
+ this.hmenu.show(t, 'tl-bl?');
}
},
handleHdOver : function(e, t){
var hd = this.findHeaderCell(t);
if(hd && !this.headersDisabled){
- this.activeHd = hd;
+ this.activeHdRef = t;
this.activeHdIndex = this.getCellIndex(hd);
var fly = this.fly(hd);
this.activeHdRegion = fly.getRegion();
if(!this.cm.isMenuDisabled(this.activeHdIndex)){
- fly.addClass("x-grid3-hd-over");
+ fly.addClass('x-grid3-hd-over');
this.activeHdBtn = fly.child('.x-grid3-hd-btn');
if(this.activeHdBtn){
this.activeHdBtn.dom.style.height = (hd.firstChild.offsetHeight-1)+'px';
// private
handleHdMove : function(e, t){
- if(this.activeHd && !this.headersDisabled){
- var hw = this.splitHandleWidth || 5;
- var r = this.activeHdRegion;
- var x = e.getPageX();
- var ss = this.activeHd.style;
- if(x - r.left <= hw && this.cm.isResizable(this.activeHdIndex-1)){
- ss.cursor = Ext.isAir ? 'move' : Ext.isWebKit ? 'e-resize' : 'col-resize'; // col-resize not always supported
- }else if(r.right - x <= (!this.activeHdBtn ? hw : 2) && this.cm.isResizable(this.activeHdIndex)){
- ss.cursor = Ext.isAir ? 'move' : Ext.isWebKit ? 'w-resize' : 'col-resize';
- }else{
- ss.cursor = '';
+ var hd = this.findHeaderCell(this.activeHdRef);
+ if(hd && !this.headersDisabled){
+ var hw = this.splitHandleWidth || 5,
+ r = this.activeHdRegion,
+ x = e.getPageX(),
+ ss = hd.style,
+ cur = '';
+ if(this.grid.enableColumnResize !== false){
+ if(x - r.left <= hw && this.cm.isResizable(this.activeHdIndex-1)){
+ cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'e-resize' : 'col-resize'; // col-resize not always supported
+ }else if(r.right - x <= (!this.activeHdBtn ? hw : 2) && this.cm.isResizable(this.activeHdIndex)){
+ cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'w-resize' : 'col-resize';
+ }
}
+ ss.cursor = cur;
}
},
handleHdOut : function(e, t){
var hd = this.findHeaderCell(t);
if(hd && (!Ext.isIE || !e.within(hd, true))){
- this.activeHd = null;
- this.fly(hd).removeClass("x-grid3-hd-over");
+ this.activeHdRef = null;
+ this.fly(hd).removeClass('x-grid3-hd-over');
hd.style.cursor = '';
}
},
// private
// This is a support class used internally by the Grid components
-Ext.grid.GridView.SplitDragZone = function(grid, hd){
- this.grid = grid;
- this.view = grid.getView();
- this.marker = this.view.resizeMarker;
- this.proxy = this.view.resizeProxy;
- Ext.grid.GridView.SplitDragZone.superclass.constructor.call(this, hd,
- "gridSplitters" + this.grid.getGridEl().id, {
- dragElId : Ext.id(this.proxy.dom), resizeFrame:false
- });
- this.scroll = false;
- this.hw = this.view.splitHandleWidth || 5;
-};
-Ext.extend(Ext.grid.GridView.SplitDragZone, Ext.dd.DDProxy, {
+Ext.grid.GridView.SplitDragZone = Ext.extend(Ext.dd.DDProxy, {
+
+ constructor: function(grid, hd){
+ this.grid = grid;
+ this.view = grid.getView();
+ this.marker = this.view.resizeMarker;
+ this.proxy = this.view.resizeProxy;
+ Ext.grid.GridView.SplitDragZone.superclass.constructor.call(this, hd,
+ 'gridSplitters' + this.grid.getGridEl().id, {
+ dragElId : Ext.id(this.proxy.dom), resizeFrame:false
+ });
+ this.scroll = false;
+ this.hw = this.view.splitHandleWidth || 5;
+ },
b4StartDrag : function(x, y){
+ this.dragHeadersDisabled = this.view.headersDisabled;
this.view.headersDisabled = true;
var h = this.view.mainWrap.getHeight();
this.marker.setHeight(h);
this.marker.show();
this.marker.alignTo(this.view.getHeaderCell(this.cellIndex), 'tl-tl', [-2, 0]);
this.proxy.setHeight(h);
- var w = this.cm.getColumnWidth(this.cellIndex);
- var minw = Math.max(w-this.grid.minColumnWidth, 0);
+ var w = this.cm.getColumnWidth(this.cellIndex),
+ minw = Math.max(w-this.grid.minColumnWidth, 0);
this.resetConstraints();
this.setXConstraint(minw, 1000);
this.setYConstraint(0, 0);
Ext.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
},
+ allowHeaderDrag : function(e){
+ return true;
+ },
handleMouseDown : function(e){
var t = this.view.findHeaderCell(e.getTarget());
- if(t){
- var xy = this.view.fly(t).getXY(), x = xy[0], y = xy[1];
- var exy = e.getXY(), ex = exy[0];
- var w = t.offsetWidth, adjust = false;
+ if(t && this.allowHeaderDrag(e)){
+ var xy = this.view.fly(t).getXY(),
+ x = xy[0],
+ y = xy[1],
+ exy = e.getXY(), ex = exy[0],
+ w = t.offsetWidth, adjust = false;
+
if((ex - x) <= this.hw){
adjust = -1;
}else if((x+w) - ex <= this.hw){
endDrag : function(e){
this.marker.hide();
- var v = this.view;
- var endX = Math.max(this.minX, e.getPageX());
- var diff = endX - this.startPos;
+ var v = this.view,
+ endX = Math.max(this.minX, e.getPageX()),
+ diff = endX - this.startPos,
+ disabled = this.dragHeadersDisabled;
+
v.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
setTimeout(function(){
- v.headersDisabled = false;
+ v.headersDisabled = disabled;
}, 50);
},
this.setDelta(0,0);
}
});
-// private\r
-// This is a support class used internally by the Grid components\r
-Ext.grid.HeaderDragZone = function(grid, hd, hd2){\r
- this.grid = grid;\r
- this.view = grid.getView();\r
- this.ddGroup = "gridHeader" + this.grid.getGridEl().id;\r
- Ext.grid.HeaderDragZone.superclass.constructor.call(this, hd);\r
- if(hd2){\r
- this.setHandleElId(Ext.id(hd));\r
- this.setOuterHandleElId(Ext.id(hd2));\r
- }\r
- this.scroll = false;\r
-};\r
-Ext.extend(Ext.grid.HeaderDragZone, Ext.dd.DragZone, {\r
- maxDragWidth: 120,\r
- getDragData : function(e){\r
- var t = Ext.lib.Event.getTarget(e);\r
- var h = this.view.findHeaderCell(t);\r
- if(h){\r
- return {ddel: h.firstChild, header:h};\r
- }\r
- return false;\r
- },\r
-\r
- onInitDrag : function(e){\r
- this.view.headersDisabled = true;\r
- var clone = this.dragData.ddel.cloneNode(true);\r
- clone.id = Ext.id();\r
- clone.style.width = Math.min(this.dragData.header.offsetWidth,this.maxDragWidth) + "px";\r
- this.proxy.update(clone);\r
- return true;\r
- },\r
-\r
- afterValidDrop : function(){\r
- var v = this.view;\r
- setTimeout(function(){\r
- v.headersDisabled = false;\r
- }, 50);\r
- },\r
-\r
- afterInvalidDrop : function(){\r
- var v = this.view;\r
- setTimeout(function(){\r
- v.headersDisabled = false;\r
- }, 50);\r
- }\r
-});\r
-\r
-// private\r
-// This is a support class used internally by the Grid components\r
-Ext.grid.HeaderDropZone = function(grid, hd, hd2){\r
- this.grid = grid;\r
- this.view = grid.getView();\r
- // split the proxies so they don't interfere with mouse events\r
- this.proxyTop = Ext.DomHelper.append(document.body, {\r
- cls:"col-move-top", html:" "\r
- }, true);\r
- this.proxyBottom = Ext.DomHelper.append(document.body, {\r
- cls:"col-move-bottom", html:" "\r
- }, true);\r
- this.proxyTop.hide = this.proxyBottom.hide = function(){\r
- this.setLeftTop(-100,-100);\r
- this.setStyle("visibility", "hidden");\r
- };\r
- this.ddGroup = "gridHeader" + this.grid.getGridEl().id;\r
- // temporarily disabled\r
- //Ext.dd.ScrollManager.register(this.view.scroller.dom);\r
- Ext.grid.HeaderDropZone.superclass.constructor.call(this, grid.getGridEl().dom);\r
-};\r
-Ext.extend(Ext.grid.HeaderDropZone, Ext.dd.DropZone, {\r
- proxyOffsets : [-4, -9],\r
- fly: Ext.Element.fly,\r
-\r
- getTargetFromEvent : function(e){\r
- var t = Ext.lib.Event.getTarget(e);\r
- var cindex = this.view.findCellIndex(t);\r
- if(cindex !== false){\r
- return this.view.getHeaderCell(cindex);\r
- }\r
- },\r
-\r
- nextVisible : function(h){\r
- var v = this.view, cm = this.grid.colModel;\r
- h = h.nextSibling;\r
- while(h){\r
- if(!cm.isHidden(v.getCellIndex(h))){\r
- return h;\r
- }\r
- h = h.nextSibling;\r
- }\r
- return null;\r
- },\r
-\r
- prevVisible : function(h){\r
- var v = this.view, cm = this.grid.colModel;\r
- h = h.prevSibling;\r
- while(h){\r
- if(!cm.isHidden(v.getCellIndex(h))){\r
- return h;\r
- }\r
- h = h.prevSibling;\r
- }\r
- return null;\r
- },\r
-\r
- positionIndicator : function(h, n, e){\r
- var x = Ext.lib.Event.getPageX(e);\r
- var r = Ext.lib.Dom.getRegion(n.firstChild);\r
- var px, pt, py = r.top + this.proxyOffsets[1];\r
- if((r.right - x) <= (r.right-r.left)/2){\r
- px = r.right+this.view.borderWidth;\r
- pt = "after";\r
- }else{\r
- px = r.left;\r
- pt = "before";\r
- }\r
-\r
- if(this.grid.colModel.isFixed(this.view.getCellIndex(n))){\r
- return false;\r
- }\r
-\r
- px += this.proxyOffsets[0];\r
- this.proxyTop.setLeftTop(px, py);\r
- this.proxyTop.show();\r
- if(!this.bottomOffset){\r
- this.bottomOffset = this.view.mainHd.getHeight();\r
- }\r
- this.proxyBottom.setLeftTop(px, py+this.proxyTop.dom.offsetHeight+this.bottomOffset);\r
- this.proxyBottom.show();\r
- return pt;\r
- },\r
-\r
- onNodeEnter : function(n, dd, e, data){\r
- if(data.header != n){\r
- this.positionIndicator(data.header, n, e);\r
- }\r
- },\r
-\r
- onNodeOver : function(n, dd, e, data){\r
- var result = false;\r
- if(data.header != n){\r
- result = this.positionIndicator(data.header, n, e);\r
- }\r
- if(!result){\r
- this.proxyTop.hide();\r
- this.proxyBottom.hide();\r
- }\r
- return result ? this.dropAllowed : this.dropNotAllowed;\r
- },\r
-\r
- onNodeOut : function(n, dd, e, data){\r
- this.proxyTop.hide();\r
- this.proxyBottom.hide();\r
- },\r
-\r
- onNodeDrop : function(n, dd, e, data){\r
- var h = data.header;\r
- if(h != n){\r
- var cm = this.grid.colModel;\r
- var x = Ext.lib.Event.getPageX(e);\r
- var r = Ext.lib.Dom.getRegion(n.firstChild);\r
- var pt = (r.right - x) <= ((r.right-r.left)/2) ? "after" : "before";\r
- var oldIndex = this.view.getCellIndex(h);\r
- var newIndex = this.view.getCellIndex(n);\r
- if(pt == "after"){\r
- newIndex++;\r
- }\r
- if(oldIndex < newIndex){\r
- newIndex--;\r
- }\r
- cm.moveColumn(oldIndex, newIndex);\r
- this.grid.fireEvent("columnmove", oldIndex, newIndex);\r
- return true;\r
- }\r
- return false;\r
- }\r
-});\r
-\r
-\r
-Ext.grid.GridView.ColumnDragZone = function(grid, hd){\r
- Ext.grid.GridView.ColumnDragZone.superclass.constructor.call(this, grid, hd, null);\r
- this.proxy.el.addClass('x-grid3-col-dd');\r
-};\r
-\r
-Ext.extend(Ext.grid.GridView.ColumnDragZone, Ext.grid.HeaderDragZone, {\r
- handleMouseDown : function(e){\r
-\r
- },\r
-\r
- callHandleMouseDown : function(e){\r
- Ext.grid.GridView.ColumnDragZone.superclass.handleMouseDown.call(this, e);\r
- }\r
+// private
+// This is a support class used internally by the Grid components
+Ext.grid.HeaderDragZone = Ext.extend(Ext.dd.DragZone, {
+ maxDragWidth: 120,
+
+ constructor : function(grid, hd, hd2){
+ this.grid = grid;
+ this.view = grid.getView();
+ this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
+ Ext.grid.HeaderDragZone.superclass.constructor.call(this, hd);
+ if(hd2){
+ this.setHandleElId(Ext.id(hd));
+ this.setOuterHandleElId(Ext.id(hd2));
+ }
+ this.scroll = false;
+ },
+
+ getDragData : function(e){
+ var t = Ext.lib.Event.getTarget(e),
+ h = this.view.findHeaderCell(t);
+ if(h){
+ return {ddel: h.firstChild, header:h};
+ }
+ return false;
+ },
+
+ onInitDrag : function(e){
+ // keep the value here so we can restore it;
+ this.dragHeadersDisabled = this.view.headersDisabled;
+ this.view.headersDisabled = true;
+ var clone = this.dragData.ddel.cloneNode(true);
+ clone.id = Ext.id();
+ clone.style.width = Math.min(this.dragData.header.offsetWidth,this.maxDragWidth) + "px";
+ this.proxy.update(clone);
+ return true;
+ },
+
+ afterValidDrop : function(){
+ this.completeDrop();
+ },
+
+ afterInvalidDrop : function(){
+ this.completeDrop();
+ },
+
+ completeDrop: function(){
+ var v = this.view,
+ disabled = this.dragHeadersDisabled;
+ setTimeout(function(){
+ v.headersDisabled = disabled;
+ }, 50);
+ }
+});
+
+// private
+// This is a support class used internally by the Grid components
+Ext.grid.HeaderDropZone = Ext.extend(Ext.dd.DropZone, {
+ proxyOffsets : [-4, -9],
+ fly: Ext.Element.fly,
+
+ constructor : function(grid, hd, hd2){
+ this.grid = grid;
+ this.view = grid.getView();
+ // split the proxies so they don't interfere with mouse events
+ this.proxyTop = Ext.DomHelper.append(document.body, {
+ cls:"col-move-top", html:" "
+ }, true);
+ this.proxyBottom = Ext.DomHelper.append(document.body, {
+ cls:"col-move-bottom", html:" "
+ }, true);
+ this.proxyTop.hide = this.proxyBottom.hide = function(){
+ this.setLeftTop(-100,-100);
+ this.setStyle("visibility", "hidden");
+ };
+ this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
+ // temporarily disabled
+ //Ext.dd.ScrollManager.register(this.view.scroller.dom);
+ Ext.grid.HeaderDropZone.superclass.constructor.call(this, grid.getGridEl().dom);
+ },
+
+ getTargetFromEvent : function(e){
+ var t = Ext.lib.Event.getTarget(e),
+ cindex = this.view.findCellIndex(t);
+ if(cindex !== false){
+ return this.view.getHeaderCell(cindex);
+ }
+ },
+
+ nextVisible : function(h){
+ var v = this.view, cm = this.grid.colModel;
+ h = h.nextSibling;
+ while(h){
+ if(!cm.isHidden(v.getCellIndex(h))){
+ return h;
+ }
+ h = h.nextSibling;
+ }
+ return null;
+ },
+
+ prevVisible : function(h){
+ var v = this.view, cm = this.grid.colModel;
+ h = h.prevSibling;
+ while(h){
+ if(!cm.isHidden(v.getCellIndex(h))){
+ return h;
+ }
+ h = h.prevSibling;
+ }
+ return null;
+ },
+
+ positionIndicator : function(h, n, e){
+ var x = Ext.lib.Event.getPageX(e),
+ r = Ext.lib.Dom.getRegion(n.firstChild),
+ px,
+ pt,
+ py = r.top + this.proxyOffsets[1];
+ if((r.right - x) <= (r.right-r.left)/2){
+ px = r.right+this.view.borderWidth;
+ pt = "after";
+ }else{
+ px = r.left;
+ pt = "before";
+ }
+
+ if(this.grid.colModel.isFixed(this.view.getCellIndex(n))){
+ return false;
+ }
+
+ px += this.proxyOffsets[0];
+ this.proxyTop.setLeftTop(px, py);
+ this.proxyTop.show();
+ if(!this.bottomOffset){
+ this.bottomOffset = this.view.mainHd.getHeight();
+ }
+ this.proxyBottom.setLeftTop(px, py+this.proxyTop.dom.offsetHeight+this.bottomOffset);
+ this.proxyBottom.show();
+ return pt;
+ },
+
+ onNodeEnter : function(n, dd, e, data){
+ if(data.header != n){
+ this.positionIndicator(data.header, n, e);
+ }
+ },
+
+ onNodeOver : function(n, dd, e, data){
+ var result = false;
+ if(data.header != n){
+ result = this.positionIndicator(data.header, n, e);
+ }
+ if(!result){
+ this.proxyTop.hide();
+ this.proxyBottom.hide();
+ }
+ return result ? this.dropAllowed : this.dropNotAllowed;
+ },
+
+ onNodeOut : function(n, dd, e, data){
+ this.proxyTop.hide();
+ this.proxyBottom.hide();
+ },
+
+ onNodeDrop : function(n, dd, e, data){
+ var h = data.header;
+ if(h != n){
+ var cm = this.grid.colModel,
+ x = Ext.lib.Event.getPageX(e),
+ r = Ext.lib.Dom.getRegion(n.firstChild),
+ pt = (r.right - x) <= ((r.right-r.left)/2) ? "after" : "before",
+ oldIndex = this.view.getCellIndex(h),
+ newIndex = this.view.getCellIndex(n);
+ if(pt == "after"){
+ newIndex++;
+ }
+ if(oldIndex < newIndex){
+ newIndex--;
+ }
+ cm.moveColumn(oldIndex, newIndex);
+ return true;
+ }
+ return false;
+ }
+});
+
+Ext.grid.GridView.ColumnDragZone = Ext.extend(Ext.grid.HeaderDragZone, {
+
+ constructor : function(grid, hd){
+ Ext.grid.GridView.ColumnDragZone.superclass.constructor.call(this, grid, hd, null);
+ this.proxy.el.addClass('x-grid3-col-dd');
+ },
+
+ handleMouseDown : function(e){
+ },
+
+ callHandleMouseDown : function(e){
+ Ext.grid.GridView.ColumnDragZone.superclass.handleMouseDown.call(this, e);
+ }
});// private
// This is a support class used internally by the Grid components
-Ext.grid.SplitDragZone = function(grid, hd, hd2){
- this.grid = grid;
- this.view = grid.getView();
- this.proxy = this.view.resizeProxy;
- Ext.grid.SplitDragZone.superclass.constructor.call(this, hd,
- "gridSplitters" + this.grid.getGridEl().id, {
- dragElId : Ext.id(this.proxy.dom), resizeFrame:false
- });
- this.setHandleElId(Ext.id(hd));
- this.setOuterHandleElId(Ext.id(hd2));
- this.scroll = false;
-};
-Ext.extend(Ext.grid.SplitDragZone, Ext.dd.DDProxy, {
+Ext.grid.SplitDragZone = Ext.extend(Ext.dd.DDProxy, {
fly: Ext.Element.fly,
+
+ constructor : function(grid, hd, hd2){
+ this.grid = grid;
+ this.view = grid.getView();
+ this.proxy = this.view.resizeProxy;
+ Ext.grid.SplitDragZone.superclass.constructor.call(this, hd,
+ "gridSplitters" + this.grid.getGridEl().id, {
+ dragElId : Ext.id(this.proxy.dom), resizeFrame:false
+ });
+ this.setHandleElId(Ext.id(hd));
+ this.setOuterHandleElId(Ext.id(hd2));
+ this.scroll = false;
+ },
b4StartDrag : function(x, y){
this.view.headersDisabled = true;
* {@link Ext.grid.Column} column configuration object within the specified Array defines the initial
* order of the column display. A Column's display may be initially hidden using the
* <tt>{@link Ext.grid.Column#hidden hidden}</tt></b> config property (and then shown using the column
- * header menu). Field's that are not included in the ColumnModel will not be displayable at all.</p>
+ * header menu). Fields that are not included in the ColumnModel will not be displayable at all.</p>
* <p>How each column in the grid correlates (maps) to the {@link Ext.data.Record} field in the
* {@link Ext.data.Store Store} the column draws its data from is configured through the
* <b><tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt></b>. If the
* @param {Mixed} config Specify either an Array of {@link Ext.grid.Column} configuration objects or specify
* a configuration Object (see introductory section discussion utilizing Initialization Method 2 above).
*/
-Ext.grid.ColumnModel = function(config){
- /**
- * An Array of {@link Ext.grid.Column Column definition} objects representing the configuration
- * of this ColumnModel. See {@link Ext.grid.Column} for the configuration properties that may
- * be specified.
- * @property config
- * @type Array
- */
- if(config.columns){
- Ext.apply(this, config);
- this.setConfig(config.columns, true);
- }else{
- this.setConfig(config, true);
- }
- this.addEvents(
- /**
- * @event widthchange
- * Fires when the width of a column is programmaticially changed using
- * <code>{@link #setColumnWidth}</code>.
- * Note internal resizing suppresses the event from firing. See also
- * {@link Ext.grid.GridPanel}.<code>{@link #columnresize}</code>.
- * @param {ColumnModel} this
- * @param {Number} columnIndex The column index
- * @param {Number} newWidth The new width
- */
- "widthchange",
- /**
- * @event headerchange
- * Fires when the text of a header changes.
- * @param {ColumnModel} this
- * @param {Number} columnIndex The column index
- * @param {String} newText The new header text
- */
- "headerchange",
- /**
- * @event hiddenchange
- * Fires when a column is hidden or "unhidden".
- * @param {ColumnModel} this
- * @param {Number} columnIndex The column index
- * @param {Boolean} hidden true if hidden, false otherwise
- */
- "hiddenchange",
- /**
- * @event columnmoved
- * Fires when a column is moved.
- * @param {ColumnModel} this
- * @param {Number} oldIndex
- * @param {Number} newIndex
- */
- "columnmoved",
- /**
- * @event configchange
- * Fires when the configuration is changed
- * @param {ColumnModel} this
- */
- "configchange"
- );
- Ext.grid.ColumnModel.superclass.constructor.call(this);
-};
-Ext.extend(Ext.grid.ColumnModel, Ext.util.Observable, {
+Ext.grid.ColumnModel = Ext.extend(Ext.util.Observable, {
/**
* @cfg {Number} defaultWidth (optional) The width of columns which have no <tt>{@link #width}</tt>
* specified (defaults to <tt>100</tt>). This property shall preferably be configured through the
* individual {@link Ext.grid.Column column} configs will supersede these <tt><b>{@link #defaults}</b></tt>.
*/
+ constructor : function(config){
+ /**
+ * An Array of {@link Ext.grid.Column Column definition} objects representing the configuration
+ * of this ColumnModel. See {@link Ext.grid.Column} for the configuration properties that may
+ * be specified.
+ * @property config
+ * @type Array
+ */
+ if(config.columns){
+ Ext.apply(this, config);
+ this.setConfig(config.columns, true);
+ }else{
+ this.setConfig(config, true);
+ }
+ this.addEvents(
+ /**
+ * @event widthchange
+ * Fires when the width of a column is programmaticially changed using
+ * <code>{@link #setColumnWidth}</code>.
+ * Note internal resizing suppresses the event from firing. See also
+ * {@link Ext.grid.GridPanel}.<code>{@link #columnresize}</code>.
+ * @param {ColumnModel} this
+ * @param {Number} columnIndex The column index
+ * @param {Number} newWidth The new width
+ */
+ "widthchange",
+ /**
+ * @event headerchange
+ * Fires when the text of a header changes.
+ * @param {ColumnModel} this
+ * @param {Number} columnIndex The column index
+ * @param {String} newText The new header text
+ */
+ "headerchange",
+ /**
+ * @event hiddenchange
+ * Fires when a column is hidden or "unhidden".
+ * @param {ColumnModel} this
+ * @param {Number} columnIndex The column index
+ * @param {Boolean} hidden true if hidden, false otherwise
+ */
+ "hiddenchange",
+ /**
+ * @event columnmoved
+ * Fires when a column is moved.
+ * @param {ColumnModel} this
+ * @param {Number} oldIndex
+ * @param {Number} newIndex
+ */
+ "columnmoved",
+ /**
+ * @event configchange
+ * Fires when the configuration is changed
+ * @param {ColumnModel} this
+ */
+ "configchange"
+ );
+ Ext.grid.ColumnModel.superclass.constructor.call(this);
+ },
+
/**
* Returns the id of the column at the specified index.
* @param {Number} index The column index
delete this.totalWidth;
for(i = 0, len = this.config.length; i < len; i++){
c = this.config[i];
- if(c.editor){
- c.editor.destroy();
+ if(c.setEditor){
+ //check here, in case we have a special column like a CheckboxSelectionModel
+ c.setEditor(null);
}
}
}
this.config = config;
this.lookup = {};
- // if no id, create one
+
for(i = 0, len = config.length; i < len; i++){
c = Ext.applyIf(config[i], this.defaults);
+ // if no id, create one using column's ordinal position
+ if(Ext.isEmpty(c.id)){
+ c.id = i;
+ }
if(!c.isColumn){
- var cls = Ext.grid.Column.types[c.xtype || 'gridcolumn'];
- c = new cls(c);
+ var Cls = Ext.grid.Column.types[c.xtype || 'gridcolumn'];
+ c = new Cls(c);
config[i] = c;
}
this.lookup[c.id] = c;
return c.hidden;
});
</code></pre>
- * @param {Function} fn
- * @param {Object} scope (optional)
+ * @param {Function} fn A function which, when passed a {@link Ext.grid.Column Column} object, must
+ * return <code>true</code> if the column is to be included in the returned Array.
+ * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function
+ * is executed. Defaults to this ColumnModel.
* @return {Array} result
*/
getColumnsBy : function(fn, scope){
* @return {Boolean}
*/
isSortable : function(col){
- return this.config[col].sortable;
+ return !!this.config[col].sortable;
},
/**
return this.config[col].renderer;
},
+ getRendererScope : function(col){
+ return this.config[col].scope;
+ },
+
/**
* Sets the rendering (formatting) function for a column. See {@link Ext.util.Format} for some
* default formatting functions.
* @return {Boolean}
*/
isCellEditable : function(colIndex, rowIndex){
- return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false;
+ var c = this.config[colIndex],
+ ed = c.editable;
+
+ //force boolean
+ return !!(ed || (!Ext.isDefined(ed) && c.editor));
},
/**
this.config[col].editable = editable;
},
-
/**
- * Returns true if the column is hidden.
+ * Returns <tt>true</tt> if the column is <code>{@link Ext.grid.Column#hidden hidden}</code>,
+ * <tt>false</tt> otherwise.
* @param {Number} colIndex The column index
* @return {Boolean}
*/
isHidden : function(colIndex){
- return this.config[colIndex].hidden;
+ return !!this.config[colIndex].hidden; // ensure returns boolean
},
-
/**
- * Returns true if the column width cannot be changed
+ * Returns <tt>true</tt> if the column is <code>{@link Ext.grid.Column#fixed fixed}</code>,
+ * <tt>false</tt> otherwise.
+ * @param {Number} colIndex The column index
+ * @return {Boolean}
*/
isFixed : function(colIndex){
- return this.config[colIndex].fixed;
+ return !!this.config[colIndex].fixed;
},
/**
},
/**
- * Sets the editor for a column and destroys the prior editor.
- * @param {Number} col The column index
- * @param {Object} editor The editor object
+ * Sets the editor for a column and destroys the prior editor.
+ * @param {Number} col The column index
+ * @param {Object} editor The editor object
+ */
+ setEditor : function(col, editor){
+ this.config[col].setEditor(editor);
+ },
+
+ /**
+ * Destroys this column model by purging any event listeners, and removing any editors.
+ */
+ destroy : function(){
+ var c;
+ for(var i = 0, len = this.config.length; i < len; i++){
+ c = this.config[i];
+ if(c.setEditor){
+ c.setEditor(null);
+ }
+ }
+ this.purgeListeners();
+ }
+});
+
+// private
+Ext.grid.ColumnModel.defaultRenderer = function(value){
+ if(typeof value == "string" && value.length < 1){
+ return " ";
+ }
+ return value;
+};/**
+ * @class Ext.grid.AbstractSelectionModel
+ * @extends Ext.util.Observable
+ * Abstract base class for grid SelectionModels. It provides the interface that should be
+ * implemented by descendant classes. This class should not be directly instantiated.
+ * @constructor
+ */
+Ext.grid.AbstractSelectionModel = Ext.extend(Ext.util.Observable, {
+ /**
+ * The GridPanel for which this SelectionModel is handling selection. Read-only.
+ * @type Object
+ * @property grid
+ */
+
+ constructor : function(){
+ this.locked = false;
+ Ext.grid.AbstractSelectionModel.superclass.constructor.call(this);
+ },
+
+ /** @ignore Called by the grid automatically. Do not call directly. */
+ init : function(grid){
+ this.grid = grid;
+ if(this.lockOnInit){
+ delete this.lockOnInit;
+ this.locked = false;
+ this.lock();
+ }
+ this.initEvents();
+ },
+
+ /**
+ * Locks the selections.
*/
- setEditor : function(col, editor){
- Ext.destroy(this.config[col].editor);
- this.config[col].editor = editor;
+ lock : function(){
+ if(!this.locked){
+ this.locked = true;
+ // If the grid has been set, then the view is already initialized.
+ var g = this.grid;
+ if(g){
+ g.getView().on({
+ scope: this,
+ beforerefresh: this.sortUnLock,
+ refresh: this.sortLock
+ });
+ }else{
+ this.lockOnInit = true;
+ }
+ }
+ },
+
+ // set the lock states before and after a view refresh
+ sortLock : function() {
+ this.locked = true;
+ },
+
+ // set the lock states before and after a view refresh
+ sortUnLock : function() {
+ this.locked = false;
},
/**
- * Destroys this column model by purging any event listeners, and removing any editors.
+ * Unlocks the selections.
*/
- destroy : function(){
- for(var i = 0, c = this.config, len = c.length; i < len; i++){
- Ext.destroy(c[i].editor);
+ unlock : function(){
+ if(this.locked){
+ this.locked = false;
+ var g = this.grid,
+ gv;
+
+ // If the grid has been set, then the view is already initialized.
+ if(g){
+ gv = g.getView();
+ gv.un('beforerefresh', this.sortUnLock, this);
+ gv.un('refresh', this.sortLock, this);
+ }else{
+ delete this.lockOnInit;
+ }
}
- this.purgeListeners();
- }
-});
+ },
-// private
-Ext.grid.ColumnModel.defaultRenderer = function(value){
- if(typeof value == "string" && value.length < 1){
- return " ";
+ /**
+ * Returns true if the selections are locked.
+ * @return {Boolean}
+ */
+ isLocked : function(){
+ return this.locked;
+ },
+
+ destroy: function(){
+ this.unlock();
+ this.purgeListeners();
}
- return value;
-};/**\r
- * @class Ext.grid.AbstractSelectionModel\r
- * @extends Ext.util.Observable\r
- * Abstract base class for grid SelectionModels. It provides the interface that should be\r
- * implemented by descendant classes. This class should not be directly instantiated.\r
- * @constructor\r
- */\r
-Ext.grid.AbstractSelectionModel = function(){\r
- this.locked = false;\r
- Ext.grid.AbstractSelectionModel.superclass.constructor.call(this);\r
-};\r
-\r
-Ext.extend(Ext.grid.AbstractSelectionModel, Ext.util.Observable, {\r
- /**\r
- * The GridPanel for which this SelectionModel is handling selection. Read-only.\r
- * @type Object\r
- * @property grid\r
- */\r
-\r
- /** @ignore Called by the grid automatically. Do not call directly. */\r
- init : function(grid){\r
- this.grid = grid;\r
- this.initEvents();\r
- },\r
-\r
- /**\r
- * Locks the selections.\r
- */\r
- lock : function(){\r
- this.locked = true;\r
- },\r
-\r
- /**\r
- * Unlocks the selections.\r
- */\r
- unlock : function(){\r
- this.locked = false;\r
- },\r
-\r
- /**\r
- * Returns true if the selections are locked.\r
- * @return {Boolean}\r
- */\r
- isLocked : function(){\r
- return this.locked;\r
- },\r
- \r
- destroy: function(){\r
- this.purgeListeners();\r
- }\r
});/**
* @class Ext.grid.RowSelectionModel
* @extends Ext.grid.AbstractSelectionModel
* @constructor
* @param {Object} config
*/
-Ext.grid.RowSelectionModel = function(config){
- Ext.apply(this, config);
- this.selections = new Ext.util.MixedCollection(false, function(o){
- return o.id;
- });
-
- this.last = false;
- this.lastActive = false;
-
- this.addEvents(
- /**
- * @event selectionchange
- * Fires when the selection changes
- * @param {SelectionModel} this
- */
- "selectionchange",
- /**
- * @event beforerowselect
- * Fires before a row is selected, return false to cancel the selection.
- * @param {SelectionModel} this
- * @param {Number} rowIndex The index to be selected
- * @param {Boolean} keepExisting False if other selections will be cleared
- * @param {Record} record The record to be selected
- */
- "beforerowselect",
- /**
- * @event rowselect
- * Fires when a row is selected.
- * @param {SelectionModel} this
- * @param {Number} rowIndex The selected index
- * @param {Ext.data.Record} r The selected record
- */
- "rowselect",
- /**
- * @event rowdeselect
- * Fires when a row is deselected. To prevent deselection
- * {@link Ext.grid.AbstractSelectionModel#lock lock the selections}.
- * @param {SelectionModel} this
- * @param {Number} rowIndex
- * @param {Record} record
- */
- "rowdeselect"
- );
-
- Ext.grid.RowSelectionModel.superclass.constructor.call(this);
-};
-
-Ext.extend(Ext.grid.RowSelectionModel, Ext.grid.AbstractSelectionModel, {
+Ext.grid.RowSelectionModel = Ext.extend(Ext.grid.AbstractSelectionModel, {
/**
* @cfg {Boolean} singleSelect
* <tt>true</tt> to allow selection of only one row at a time (defaults to <tt>false</tt>
* allowing multiple selections)
*/
singleSelect : false,
+
+ constructor : function(config){
+ Ext.apply(this, config);
+ this.selections = new Ext.util.MixedCollection(false, function(o){
+ return o.id;
+ });
+
+ this.last = false;
+ this.lastActive = false;
+
+ this.addEvents(
+ /**
+ * @event selectionchange
+ * Fires when the selection changes
+ * @param {SelectionModel} this
+ */
+ 'selectionchange',
+ /**
+ * @event beforerowselect
+ * Fires before a row is selected, return false to cancel the selection.
+ * @param {SelectionModel} this
+ * @param {Number} rowIndex The index to be selected
+ * @param {Boolean} keepExisting False if other selections will be cleared
+ * @param {Record} record The record to be selected
+ */
+ 'beforerowselect',
+ /**
+ * @event rowselect
+ * Fires when a row is selected.
+ * @param {SelectionModel} this
+ * @param {Number} rowIndex The selected index
+ * @param {Ext.data.Record} r The selected record
+ */
+ 'rowselect',
+ /**
+ * @event rowdeselect
+ * Fires when a row is deselected. To prevent deselection
+ * {@link Ext.grid.AbstractSelectionModel#lock lock the selections}.
+ * @param {SelectionModel} this
+ * @param {Number} rowIndex
+ * @param {Record} record
+ */
+ 'rowdeselect'
+ );
+ Ext.grid.RowSelectionModel.superclass.constructor.call(this);
+ },
/**
* @cfg {Boolean} moveEditorOnEnter
initEvents : function(){
if(!this.grid.enableDragDrop && !this.grid.enableDrag){
- this.grid.on("rowmousedown", this.handleMouseDown, this);
- }else{ // allow click to work like normal
- this.grid.on("rowclick", function(grid, rowIndex, e) {
- if(e.button === 0 && !e.shiftKey && !e.ctrlKey) {
- this.selectRow(rowIndex, false);
- grid.view.focusRow(rowIndex);
- }
- }, this);
+ this.grid.on('rowmousedown', this.handleMouseDown, this);
}
this.rowNav = new Ext.KeyNav(this.grid.getGridEl(), {
- "up" : function(e){
+ 'up' : function(e){
if(!e.shiftKey || this.singleSelect){
this.selectPrevious(false);
}else if(this.last !== false && this.lastActive !== false){
this.selectFirstRow();
}
},
- "down" : function(e){
+ 'down' : function(e){
if(!e.shiftKey || this.singleSelect){
this.selectNext(false);
}else if(this.last !== false && this.lastActive !== false){
scope: this
});
- var view = this.grid.view;
- view.on("refresh", this.onRefresh, this);
- view.on("rowupdated", this.onRowUpdated, this);
- view.on("rowremoved", this.onRemove, this);
+ this.grid.getView().on({
+ scope: this,
+ refresh: this.onRefresh,
+ rowupdated: this.onRowUpdated,
+ rowremoved: this.onRemove
+ });
},
// private
}
}
if(s.length != this.selections.getCount()){
- this.fireEvent("selectionchange", this);
+ this.fireEvent('selectionchange', this);
}
},
* Calls the passed function with each selection. If the function returns
* <tt>false</tt>, iteration is stopped and this function returns
* <tt>false</tt>. Otherwise it returns <tt>true</tt>.
- * @param {Function} fn
- * @param {Object} scope (optional)
+ * @param {Function} fn The function to call upon each iteration. It is passed the selected {@link Ext.data.Record Record}.
+ * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this RowSelectionModel.
* @return {Boolean} true if all selections were iterated
*/
each : function(fn, scope){
* @return {Boolean}
*/
isSelected : function(index){
- var r = typeof index == "number" ? this.grid.store.getAt(index) : index;
+ var r = Ext.isNumber(index) ? this.grid.store.getAt(index) : index;
return (r && this.selections.key(r.id) ? true : false);
},
return;
}
var r = this.grid.store.getAt(index);
- if(r && this.fireEvent("beforerowselect", this, index, keepExisting, r) !== false){
+ if(r && this.fireEvent('beforerowselect', this, index, keepExisting, r) !== false){
if(!keepExisting || this.singleSelect){
this.clearSelections();
}
if(!preventViewNotify){
this.grid.getView().onRowSelect(index);
}
- this.fireEvent("rowselect", this, index, r);
- this.fireEvent("selectionchange", this);
+ this.fireEvent('rowselect', this, index, r);
+ this.fireEvent('selectionchange', this);
}
},
if(!preventViewNotify){
this.grid.getView().onRowDeselect(index);
}
- this.fireEvent("rowdeselect", this, index, r);
- this.fireEvent("selectionchange", this);
+ this.fireEvent('rowdeselect', this, index, r);
+ this.fireEvent('selectionchange', this);
}
},
// private
onEditorKey : function(field, e){
- var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
+ var k = e.getKey(),
+ newCell,
+ g = this.grid,
+ last = g.lastEdit,
+ ed = g.activeEditor,
+ ae, last, r, c;
var shift = e.shiftKey;
if(k == e.TAB){
e.stopEvent();
newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
}
}else if(k == e.ENTER){
- e.stopEvent();
- ed.completeEdit();
if(this.moveEditorOnEnter !== false){
if(shift){
- newCell = g.walkCells(ed.row - 1, ed.col, -1, this.acceptsNav, this);
+ newCell = g.walkCells(last.row - 1, last.col, -1, this.acceptsNav, this);
}else{
- newCell = g.walkCells(ed.row + 1, ed.col, 1, this.acceptsNav, this);
+ newCell = g.walkCells(last.row + 1, last.col, 1, this.acceptsNav, this);
}
}
- }else if(k == e.ESC){
- ed.cancelEdit();
}
if(newCell){
- g.startEditing(newCell[0], newCell[1]);
+ r = newCell[0];
+ c = newCell[1];
+
+ if(last.row != r){
+ this.selectRow(r); // *** highlight newly-selected cell and update selection
+ }
+
+ if(g.isEditor && g.editing){ // *** handle tabbing while editorgrid is in edit mode
+ ae = g.activeEditor;
+ if(ae && ae.field.triggerBlur){
+ // *** if activeEditor is a TriggerField, explicitly call its triggerBlur() method
+ ae.field.triggerBlur();
+ }
+ }
+ g.startEditing(r, c);
}
},
- destroy: function(){
+ destroy : function(){
if(this.rowNav){
this.rowNav.disable();
this.rowNav = null;
}
Ext.grid.RowSelectionModel.superclass.destroy.call(this);
}
-});/**\r
- * @class Ext.grid.Column\r
- * <p>This class encapsulates column configuration data to be used in the initialization of a\r
- * {@link Ext.grid.ColumnModel ColumnModel}.</p>\r
- * <p>While subclasses are provided to render data in different ways, this class renders a passed\r
- * data field unchanged and is usually used for textual columns.</p>\r
- */\r
-Ext.grid.Column = function(config){\r
- Ext.apply(this, config);\r
-\r
- if(typeof this.renderer == 'string'){\r
- this.renderer = Ext.util.Format[this.renderer];\r
- } else if(Ext.isObject(this.renderer)){\r
- this.scope = this.renderer.scope;\r
- this.renderer = this.renderer.fn;\r
- }\r
- this.renderer = this.renderer.createDelegate(this.scope || config);\r
-\r
- if(this.id === undefined){\r
- this.id = ++Ext.grid.Column.AUTO_ID;\r
- }\r
- if(this.editor){\r
- this.editor = Ext.create(this.editor, 'textfield');\r
- }\r
-};\r
-\r
-Ext.grid.Column.AUTO_ID = 0;\r
-\r
-Ext.grid.Column.prototype = {\r
- /**\r
- * @cfg {Boolean} editable Optional. Defaults to <tt>true</tt>, enabling the configured\r
- * <tt>{@link #editor}</tt>. Set to <tt>false</tt> to initially disable editing on this column.\r
- * The initial configuration may be dynamically altered using\r
- * {@link Ext.grid.ColumnModel}.{@link Ext.grid.ColumnModel#setEditable setEditable()}.\r
- */\r
- /**\r
- * @cfg {String} id Optional. A name which identifies this column (defaults to the column's initial\r
- * ordinal position.) The <tt>id</tt> is used to create a CSS <b>class</b> name which is applied to all\r
- * table cells (including headers) in that column (in this context the <tt>id</tt> does not need to be\r
- * unique). The class name takes the form of <pre>x-grid3-td-<b>id</b></pre>\r
- * Header cells will also receive this class name, but will also have the class <pre>x-grid3-hd</pre>\r
- * So, to target header cells, use CSS selectors such as:<pre>.x-grid3-hd-row .x-grid3-td-<b>id</b></pre>\r
- * The {@link Ext.grid.GridPanel#autoExpandColumn} grid config option references the column via this\r
- * unique identifier.\r
- */\r
- /**\r
- * @cfg {String} header Optional. The header text to be used as innerHTML\r
- * (html tags are accepted) to display in the Grid view. <b>Note</b>: to\r
- * have a clickable header with no text displayed use <tt>' '</tt>.\r
- */\r
- /**\r
- * @cfg {Boolean} groupable Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option\r
- * may be used to disable the header menu item to group by the column selected. Defaults to <tt>true</tt>,\r
- * which enables the header menu group option. Set to <tt>false</tt> to disable (but still show) the\r
- * group option in the header menu for the column. See also <code>{@link #groupName}</code>.\r
- */\r
- /**\r
- * @cfg {String} groupName Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option\r
- * may be used to specify the text with which to prefix the group field value in the group header line.\r
- * See also {@link #groupRenderer} and\r
- * {@link Ext.grid.GroupingView}.{@link Ext.grid.GroupingView#showGroupName showGroupName}.\r
- */\r
- /**\r
- * @cfg {Function} groupRenderer <p>Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option\r
- * may be used to specify the function used to format the grouping field value for display in the group\r
- * {@link #groupName header}. If a <tt><b>groupRenderer</b></tt> is not specified, the configured\r
- * <tt><b>{@link #renderer}</b></tt> will be called; if a <tt><b>{@link #renderer}</b></tt> is also not specified\r
- * the new value of the group field will be used.</p>\r
- * <p>The called function (either the <tt><b>groupRenderer</b></tt> or <tt><b>{@link #renderer}</b></tt>) will be\r
- * passed the following parameters:\r
- * <div class="mdetail-params"><ul>\r
- * <li><b>v</b> : Object<p class="sub-desc">The new value of the group field.</p></li>\r
- * <li><b>unused</b> : undefined<p class="sub-desc">Unused parameter.</p></li>\r
- * <li><b>r</b> : Ext.data.Record<p class="sub-desc">The Record providing the data\r
- * for the row which caused group change.</p></li>\r
- * <li><b>rowIndex</b> : Number<p class="sub-desc">The row index of the Record which caused group change.</p></li>\r
- * <li><b>colIndex</b> : Number<p class="sub-desc">The column index of the group field.</p></li>\r
- * <li><b>ds</b> : Ext.data.Store<p class="sub-desc">The Store which is providing the data Model.</p></li>\r
- * </ul></div></p>\r
- * <p>The function should return a string value.</p>\r
- */\r
- /**\r
- * @cfg {String} emptyGroupText Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option\r
- * may be used to specify the text to display when there is an empty group value. Defaults to the\r
- * {@link Ext.grid.GroupingView}.{@link Ext.grid.GroupingView#emptyGroupText emptyGroupText}.\r
- */\r
- /**\r
- * @cfg {String} dataIndex <p><b>Required</b>. The name of the field in the\r
- * grid's {@link Ext.data.Store}'s {@link Ext.data.Record} definition from\r
- * which to draw the column's value.</p>\r
- */\r
- /**\r
- * @cfg {Number} width\r
- * Optional. The initial width in pixels of the column.\r
- * The width of each column can also be affected if any of the following are configured:\r
- * <div class="mdetail-params"><ul>\r
- * <li>{@link Ext.grid.GridPanel}.<tt>{@link Ext.grid.GridPanel#autoExpandColumn autoExpandColumn}</tt></li>\r
- * <li>{@link Ext.grid.GridView}.<tt>{@link Ext.grid.GridView#forceFit forceFit}</tt>\r
- * <div class="sub-desc">\r
- * <p>By specifying <tt>forceFit:true</tt>, {@link #fixed non-fixed width} columns will be\r
- * re-proportioned (based on the relative initial widths) to fill the width of the grid so\r
- * that no horizontal scrollbar is shown.</p>\r
- * </div></li>\r
- * <li>{@link Ext.grid.GridView}.<tt>{@link Ext.grid.GridView#autoFill autoFill}</tt></li>\r
- * <li>{@link Ext.grid.GridPanel}.<tt>{@link Ext.grid.GridPanel#minColumnWidth minColumnWidth}</tt></li>\r
- * <br><p><b>Note</b>: when the width of each column is determined, a space on the right side\r
- * is reserved for the vertical scrollbar. The\r
- * {@link Ext.grid.GridView}.<tt>{@link Ext.grid.GridView#scrollOffset scrollOffset}</tt>\r
- * can be modified to reduce or eliminate the reserved offset.</p>\r
- */\r
- /**\r
- * @cfg {Boolean} sortable Optional. <tt>true</tt> if sorting is to be allowed on this column.\r
- * Defaults to the value of the {@link #defaultSortable} property.\r
- * Whether local/remote sorting is used is specified in {@link Ext.data.Store#remoteSort}.\r
- */\r
- /**\r
- * @cfg {Boolean} fixed Optional. <tt>true</tt> if the column width cannot be changed. Defaults to <tt>false</tt>.\r
- */\r
- /**\r
- * @cfg {Boolean} resizable Optional. <tt>false</tt> to disable column resizing. Defaults to <tt>true</tt>.\r
- */\r
- /**\r
- * @cfg {Boolean} menuDisabled Optional. <tt>true</tt> to disable the column menu. Defaults to <tt>false</tt>.\r
- */\r
- /**\r
- * @cfg {Boolean} hidden Optional. <tt>true</tt> to hide the column. Defaults to <tt>false</tt>.\r
- */\r
- /**\r
- * @cfg {String} tooltip Optional. A text string to use as the column header's tooltip. If Quicktips\r
- * are enabled, this value will be used as the text of the quick tip, otherwise it will be set as the\r
- * header's HTML title attribute. Defaults to ''.\r
- */\r
- /**\r
- * @cfg {Mixed} renderer\r
- * <p>For an alternative to specifying a renderer see <code>{@link #xtype}</code></p>\r
- * <p>Optional. A renderer is an 'interceptor' method which can be used transform data (value,\r
- * appearance, etc.) before it is rendered). This may be specified in either of three ways:\r
- * <div class="mdetail-params"><ul>\r
- * <li>A renderer function used to return HTML markup for a cell given the cell's data value.</li>\r
- * <li>A string which references a property name of the {@link Ext.util.Format} class which\r
- * provides a renderer function.</li>\r
- * <li>An object specifying both the renderer function, and its execution scope (<tt><b>this</b></tt>\r
- * reference) e.g.:<pre style="margin-left:1.2em"><code>\r
-{\r
- fn: this.gridRenderer,\r
- scope: this\r
-}\r
-</code></pre></li></ul></div>\r
- * If not specified, the default renderer uses the raw data value.</p>\r
- * <p>For information about the renderer function (passed parameters, etc.), see\r
- * {@link Ext.grid.ColumnModel#setRenderer}. An example of specifying renderer function inline:</p><pre><code>\r
-var companyColumn = {\r
- header: 'Company Name',\r
- dataIndex: 'company',\r
- renderer: function(value, metaData, record, rowIndex, colIndex, store) {\r
- // provide the logic depending on business rules\r
- // name of your own choosing to manipulate the cell depending upon\r
- // the data in the underlying Record object.\r
- if (value == 'whatever') {\r
- //metaData.css : String : A CSS class name to add to the TD element of the cell.\r
- //metaData.attr : String : An html attribute definition string to apply to\r
- // the data container element within the table\r
- // cell (e.g. 'style="color:red;"').\r
- metaData.css = 'name-of-css-class-you-will-define';\r
- }\r
- return value;\r
- }\r
-}\r
- * </code></pre>\r
- * See also {@link #scope}.\r
- */\r
- /**\r
- * @cfg {String} xtype Optional. A String which references a predefined {@link Ext.grid.Column} subclass\r
- * type which is preconfigured with an appropriate <code>{@link #renderer}</code> to be easily\r
- * configured into a ColumnModel. The predefined {@link Ext.grid.Column} subclass types are:\r
- * <div class="mdetail-params"><ul>\r
- * <li><b><tt>gridcolumn</tt></b> : {@link Ext.grid.Column} (<b>Default</b>)<p class="sub-desc"></p></li>\r
- * <li><b><tt>booleancolumn</tt></b> : {@link Ext.grid.BooleanColumn}<p class="sub-desc"></p></li>\r
- * <li><b><tt>numbercolumn</tt></b> : {@link Ext.grid.NumberColumn}<p class="sub-desc"></p></li>\r
- * <li><b><tt>datecolumn</tt></b> : {@link Ext.grid.DateColumn}<p class="sub-desc"></p></li>\r
- * <li><b><tt>templatecolumn</tt></b> : {@link Ext.grid.TemplateColumn}<p class="sub-desc"></p></li>\r
- * </ul></div>\r
- * <p>Configuration properties for the specified <code>xtype</code> may be specified with\r
- * the Column configuration properties, for example:</p>\r
- * <pre><code>\r
-var grid = new Ext.grid.GridPanel({\r
- ...\r
- columns: [{\r
- header: 'Last Updated',\r
- dataIndex: 'lastChange',\r
- width: 85,\r
- sortable: true,\r
- //renderer: Ext.util.Format.dateRenderer('m/d/Y'),\r
- xtype: 'datecolumn', // use xtype instead of renderer\r
- format: 'M/d/Y' // configuration property for {@link Ext.grid.DateColumn}\r
- }, {\r
- ...\r
- }]\r
-});\r
- * </code></pre>\r
- */\r
- /**\r
- * @cfg {Object} scope Optional. The scope (<tt><b>this</b></tt> reference) in which to execute the\r
- * renderer. Defaults to the Column configuration object.\r
- */\r
- /**\r
- * @cfg {String} align Optional. Set the CSS text-align property of the column. Defaults to undefined.\r
- */\r
- /**\r
- * @cfg {String} css Optional. An inline style definition string which is applied to all table cells in the column\r
- * (excluding headers). Defaults to undefined.\r
- */\r
- /**\r
- * @cfg {Boolean} hideable Optional. Specify as <tt>false</tt> to prevent the user from hiding this column\r
- * (defaults to true). To disallow column hiding globally for all columns in the grid, use\r
- * {@link Ext.grid.GridPanel#enableColumnHide} instead.\r
- */\r
- /**\r
- * @cfg {Ext.form.Field} editor Optional. The {@link Ext.form.Field} to use when editing values in this column\r
- * if editing is supported by the grid. See <tt>{@link #editable}</tt> also.\r
- */\r
-\r
- // private. Used by ColumnModel to avoid reprocessing\r
- isColumn : true,\r
- /**\r
- * Optional. A function which returns displayable data when passed the following parameters:\r
- * <div class="mdetail-params"><ul>\r
- * <li><b>value</b> : Object<p class="sub-desc">The data value for the cell.</p></li>\r
- * <li><b>metadata</b> : Object<p class="sub-desc">An object in which you may set the following attributes:<ul>\r
- * <li><b>css</b> : String<p class="sub-desc">A CSS class name to add to the cell's TD element.</p></li>\r
- * <li><b>attr</b> : String<p class="sub-desc">An HTML attribute definition string to apply to the data container\r
- * element <i>within</i> the table cell (e.g. 'style="color:red;"').</p></li></ul></p></li>\r
- * <li><b>record</b> : Ext.data.record<p class="sub-desc">The {@link Ext.data.Record} from which the data was\r
- * extracted.</p></li>\r
- * <li><b>rowIndex</b> : Number<p class="sub-desc">Row index</p></li>\r
- * <li><b>colIndex</b> : Number<p class="sub-desc">Column index</p></li>\r
- * <li><b>store</b> : Ext.data.Store<p class="sub-desc">The {@link Ext.data.Store} object from which the Record\r
- * was extracted.</p></li>\r
- * </ul></div>\r
- * @property renderer\r
- * @type Function\r
- */\r
- renderer : function(value){\r
- if(typeof value == 'string' && value.length < 1){\r
- return ' ';\r
- }\r
- return value;\r
- },\r
-\r
- // private\r
- getEditor: function(rowIndex){\r
- return this.editable !== false ? this.editor : null;\r
- },\r
-\r
- /**\r
- * Returns the {@link Ext.Editor editor} defined for this column that was created to wrap the {@link Ext.form.Field Field}\r
- * used to edit the cell.\r
- * @param {Number} rowIndex The row index\r
- * @return {Ext.Editor}\r
- */\r
- getCellEditor: function(rowIndex){\r
- var editor = this.getEditor(rowIndex);\r
- if(editor){\r
- if(!editor.startEdit){\r
- if(!editor.gridEditor){\r
- editor.gridEditor = new Ext.grid.GridEditor(editor);\r
- }\r
- return editor.gridEditor;\r
- }else if(editor.startEdit){\r
- return editor;\r
- }\r
- }\r
- return null;\r
- }\r
-};\r
-\r
-/**\r
- * @class Ext.grid.BooleanColumn\r
- * @extends Ext.grid.Column\r
- * <p>A Column definition class which renders boolean data fields. See the {@link Ext.grid.ColumnModel#xtype xtype}\r
- * config option of {@link Ext.grid.ColumnModel} for more details.</p>\r
- */\r
-Ext.grid.BooleanColumn = Ext.extend(Ext.grid.Column, {\r
- /**\r
- * @cfg {String} trueText\r
- * The string returned by the renderer when the column value is not falsey (defaults to <tt>'true'</tt>).\r
- */\r
- trueText: 'true',\r
- /**\r
- * @cfg {String} falseText\r
- * The string returned by the renderer when the column value is falsey (but not undefined) (defaults to\r
- * <tt>'false'</tt>).\r
- */\r
- falseText: 'false',\r
- /**\r
- * @cfg {String} undefinedText\r
- * The string returned by the renderer when the column value is undefined (defaults to <tt>' '</tt>).\r
- */\r
- undefinedText: ' ',\r
-\r
- constructor: function(cfg){\r
- Ext.grid.BooleanColumn.superclass.constructor.call(this, cfg);\r
- var t = this.trueText, f = this.falseText, u = this.undefinedText;\r
- this.renderer = function(v){\r
- if(v === undefined){\r
- return u;\r
- }\r
- if(!v || v === 'false'){\r
- return f;\r
- }\r
- return t;\r
- };\r
- }\r
-});\r
-\r
-/**\r
- * @class Ext.grid.NumberColumn\r
- * @extends Ext.grid.Column\r
- * <p>A Column definition class which renders a numeric data field according to a {@link #format} string. See the\r
- * {@link Ext.grid.ColumnModel#xtype xtype} config option of {@link Ext.grid.ColumnModel} for more details.</p>\r
- */\r
-Ext.grid.NumberColumn = Ext.extend(Ext.grid.Column, {\r
- /**\r
- * @cfg {String} format\r
- * A formatting string as used by {@link Ext.util.Format#number} to format a numeric value for this Column\r
- * (defaults to <tt>'0,000.00'</tt>).\r
- */\r
- format : '0,000.00',\r
- constructor: function(cfg){\r
- Ext.grid.NumberColumn.superclass.constructor.call(this, cfg);\r
- this.renderer = Ext.util.Format.numberRenderer(this.format);\r
- }\r
-});\r
-\r
-/**\r
- * @class Ext.grid.DateColumn\r
- * @extends Ext.grid.Column\r
- * <p>A Column definition class which renders a passed date according to the default locale, or a configured\r
- * {@link #format}. See the {@link Ext.grid.ColumnModel#xtype xtype} config option of {@link Ext.grid.ColumnModel}\r
- * for more details.</p>\r
- */\r
-Ext.grid.DateColumn = Ext.extend(Ext.grid.Column, {\r
- /**\r
- * @cfg {String} format\r
- * A formatting string as used by {@link Date#format} to format a Date for this Column\r
- * (defaults to <tt>'m/d/Y'</tt>).\r
- */\r
- format : 'm/d/Y',\r
- constructor: function(cfg){\r
- Ext.grid.DateColumn.superclass.constructor.call(this, cfg);\r
- this.renderer = Ext.util.Format.dateRenderer(this.format);\r
- }\r
-});\r
-\r
-/**\r
- * @class Ext.grid.TemplateColumn\r
- * @extends Ext.grid.Column\r
- * <p>A Column definition class which renders a value by processing a {@link Ext.data.Record Record}'s\r
- * {@link Ext.data.Record#data data} using a {@link #tpl configured} {@link Ext.XTemplate XTemplate}.\r
- * See the {@link Ext.grid.ColumnModel#xtype xtype} config option of {@link Ext.grid.ColumnModel} for more\r
- * details.</p>\r
- */\r
-Ext.grid.TemplateColumn = Ext.extend(Ext.grid.Column, {\r
- /**\r
- * @cfg {String/XTemplate} tpl\r
- * An {@link Ext.XTemplate XTemplate}, or an XTemplate <i>definition string</i> to use to process a\r
- * {@link Ext.data.Record Record}'s {@link Ext.data.Record#data data} to produce a column's rendered value.\r
- */\r
- constructor: function(cfg){\r
- Ext.grid.TemplateColumn.superclass.constructor.call(this, cfg);\r
- var tpl = typeof Ext.isObject(this.tpl) ? this.tpl : new Ext.XTemplate(this.tpl);\r
- this.renderer = function(value, p, r){\r
- return tpl.apply(r.data);\r
- };\r
- this.tpl = tpl;\r
- }\r
-});\r
-\r
-/*\r
- * @property types\r
- * @type Object\r
- * @member Ext.grid.Column\r
- * @static\r
- * <p>An object containing predefined Column classes keyed by a mnemonic code which may be referenced\r
- * by the {@link Ext.grid.ColumnModel#xtype xtype} config option of ColumnModel.</p>\r
- * <p>This contains the following properties</p><div class="mdesc-details"><ul>\r
- * <li>gridcolumn : <b>{@link Ext.grid.Column Column constructor}</b></li>\r
- * <li>booleancolumn : <b>{@link Ext.grid.BooleanColumn BooleanColumn constructor}</b></li>\r
- * <li>numbercolumn : <b>{@link Ext.grid.NumberColumn NumberColumn constructor}</b></li>\r
- * <li>datecolumn : <b>{@link Ext.grid.DateColumn DateColumn constructor}</b></li>\r
- * <li>templatecolumn : <b>{@link Ext.grid.TemplateColumn TemplateColumn constructor}</b></li>\r
- * </ul></div>\r
- */\r
-Ext.grid.Column.types = {\r
- gridcolumn : Ext.grid.Column,\r
- booleancolumn: Ext.grid.BooleanColumn,\r
- numbercolumn: Ext.grid.NumberColumn,\r
- datecolumn: Ext.grid.DateColumn,\r
- templatecolumn: Ext.grid.TemplateColumn\r
+});/**
+ * @class Ext.grid.Column
+ * <p>This class encapsulates column configuration data to be used in the initialization of a
+ * {@link Ext.grid.ColumnModel ColumnModel}.</p>
+ * <p>While subclasses are provided to render data in different ways, this class renders a passed
+ * data field unchanged and is usually used for textual columns.</p>
+ */
+Ext.grid.Column = Ext.extend(Object, {
+ /**
+ * @cfg {Boolean} editable Optional. Defaults to <tt>true</tt>, enabling the configured
+ * <tt>{@link #editor}</tt>. Set to <tt>false</tt> to initially disable editing on this column.
+ * The initial configuration may be dynamically altered using
+ * {@link Ext.grid.ColumnModel}.{@link Ext.grid.ColumnModel#setEditable setEditable()}.
+ */
+ /**
+ * @cfg {String} id Optional. A name which identifies this column (defaults to the column's initial
+ * ordinal position.) The <tt>id</tt> is used to create a CSS <b>class</b> name which is applied to all
+ * table cells (including headers) in that column (in this context the <tt>id</tt> does not need to be
+ * unique). The class name takes the form of <pre>x-grid3-td-<b>id</b></pre>
+ * Header cells will also receive this class name, but will also have the class <pre>x-grid3-hd</pre>
+ * So, to target header cells, use CSS selectors such as:<pre>.x-grid3-hd-row .x-grid3-td-<b>id</b></pre>
+ * The {@link Ext.grid.GridPanel#autoExpandColumn} grid config option references the column via this
+ * unique identifier.
+ */
+ /**
+ * @cfg {String} header Optional. The header text to be used as innerHTML
+ * (html tags are accepted) to display in the Grid view. <b>Note</b>: to
+ * have a clickable header with no text displayed use <tt>' '</tt>.
+ */
+ /**
+ * @cfg {Boolean} groupable Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option
+ * may be used to disable the header menu item to group by the column selected. Defaults to <tt>true</tt>,
+ * which enables the header menu group option. Set to <tt>false</tt> to disable (but still show) the
+ * group option in the header menu for the column. See also <code>{@link #groupName}</code>.
+ */
+ /**
+ * @cfg {String} groupName Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option
+ * may be used to specify the text with which to prefix the group field value in the group header line.
+ * See also {@link #groupRenderer} and
+ * {@link Ext.grid.GroupingView}.{@link Ext.grid.GroupingView#showGroupName showGroupName}.
+ */
+ /**
+ * @cfg {Function} groupRenderer <p>Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option
+ * may be used to specify the function used to format the grouping field value for display in the group
+ * {@link #groupName header}. If a <tt><b>groupRenderer</b></tt> is not specified, the configured
+ * <tt><b>{@link #renderer}</b></tt> will be called; if a <tt><b>{@link #renderer}</b></tt> is also not specified
+ * the new value of the group field will be used.</p>
+ * <p>The called function (either the <tt><b>groupRenderer</b></tt> or <tt><b>{@link #renderer}</b></tt>) will be
+ * passed the following parameters:
+ * <div class="mdetail-params"><ul>
+ * <li><b>v</b> : Object<p class="sub-desc">The new value of the group field.</p></li>
+ * <li><b>unused</b> : undefined<p class="sub-desc">Unused parameter.</p></li>
+ * <li><b>r</b> : Ext.data.Record<p class="sub-desc">The Record providing the data
+ * for the row which caused group change.</p></li>
+ * <li><b>rowIndex</b> : Number<p class="sub-desc">The row index of the Record which caused group change.</p></li>
+ * <li><b>colIndex</b> : Number<p class="sub-desc">The column index of the group field.</p></li>
+ * <li><b>ds</b> : Ext.data.Store<p class="sub-desc">The Store which is providing the data Model.</p></li>
+ * </ul></div></p>
+ * <p>The function should return a string value.</p>
+ */
+ /**
+ * @cfg {String} emptyGroupText Optional. If the grid is being rendered by an {@link Ext.grid.GroupingView}, this option
+ * may be used to specify the text to display when there is an empty group value. Defaults to the
+ * {@link Ext.grid.GroupingView}.{@link Ext.grid.GroupingView#emptyGroupText emptyGroupText}.
+ */
+ /**
+ * @cfg {String} dataIndex <p><b>Required</b>. The name of the field in the
+ * grid's {@link Ext.data.Store}'s {@link Ext.data.Record} definition from
+ * which to draw the column's value.</p>
+ */
+ /**
+ * @cfg {Number} width
+ * Optional. The initial width in pixels of the column.
+ * The width of each column can also be affected if any of the following are configured:
+ * <div class="mdetail-params"><ul>
+ * <li>{@link Ext.grid.GridPanel}.<tt>{@link Ext.grid.GridPanel#autoExpandColumn autoExpandColumn}</tt></li>
+ * <li>{@link Ext.grid.GridView}.<tt>{@link Ext.grid.GridView#forceFit forceFit}</tt>
+ * <div class="sub-desc">
+ * <p>By specifying <tt>forceFit:true</tt>, {@link #fixed non-fixed width} columns will be
+ * re-proportioned (based on the relative initial widths) to fill the width of the grid so
+ * that no horizontal scrollbar is shown.</p>
+ * </div></li>
+ * <li>{@link Ext.grid.GridView}.<tt>{@link Ext.grid.GridView#autoFill autoFill}</tt></li>
+ * <li>{@link Ext.grid.GridPanel}.<tt>{@link Ext.grid.GridPanel#minColumnWidth minColumnWidth}</tt></li>
+ * <br><p><b>Note</b>: when the width of each column is determined, a space on the right side
+ * is reserved for the vertical scrollbar. The
+ * {@link Ext.grid.GridView}.<tt>{@link Ext.grid.GridView#scrollOffset scrollOffset}</tt>
+ * can be modified to reduce or eliminate the reserved offset.</p>
+ */
+ /**
+ * @cfg {Boolean} sortable Optional. <tt>true</tt> if sorting is to be allowed on this column.
+ * Defaults to the value of the <code>{@link Ext.grid.ColumnModel#defaultSortable}</code> property.
+ * Whether local/remote sorting is used is specified in <code>{@link Ext.data.Store#remoteSort}</code>.
+ */
+ /**
+ * @cfg {Boolean} fixed Optional. <tt>true</tt> if the column width cannot be changed. Defaults to <tt>false</tt>.
+ */
+ /**
+ * @cfg {Boolean} resizable Optional. <tt>false</tt> to disable column resizing. Defaults to <tt>true</tt>.
+ */
+ /**
+ * @cfg {Boolean} menuDisabled Optional. <tt>true</tt> to disable the column menu. Defaults to <tt>false</tt>.
+ */
+ /**
+ * @cfg {Boolean} hidden
+ * Optional. <tt>true</tt> to initially hide this column. Defaults to <tt>false</tt>.
+ * A hidden column {@link Ext.grid.GridPanel#enableColumnHide may be shown via the header row menu}.
+ * If a column is never to be shown, simply do not include this column in the Column Model at all.
+ */
+ /**
+ * @cfg {String} tooltip Optional. A text string to use as the column header's tooltip. If Quicktips
+ * are enabled, this value will be used as the text of the quick tip, otherwise it will be set as the
+ * header's HTML title attribute. Defaults to ''.
+ */
+ /**
+ * @cfg {Mixed} renderer
+ * <p>For an alternative to specifying a renderer see <code>{@link #xtype}</code></p>
+ * <p>Optional. A renderer is an 'interceptor' method which can be used transform data (value,
+ * appearance, etc.) before it is rendered). This may be specified in either of three ways:
+ * <div class="mdetail-params"><ul>
+ * <li>A renderer function used to return HTML markup for a cell given the cell's data value.</li>
+ * <li>A string which references a property name of the {@link Ext.util.Format} class which
+ * provides a renderer function.</li>
+ * <li>An object specifying both the renderer function, and its execution scope (<tt><b>this</b></tt>
+ * reference) e.g.:<pre style="margin-left:1.2em"><code>
+{
+ fn: this.gridRenderer,
+ scope: this
+}
+</code></pre></li></ul></div>
+ * If not specified, the default renderer uses the raw data value.</p>
+ * <p>For information about the renderer function (passed parameters, etc.), see
+ * {@link Ext.grid.ColumnModel#setRenderer}. An example of specifying renderer function inline:</p><pre><code>
+var companyColumn = {
+ header: 'Company Name',
+ dataIndex: 'company',
+ renderer: function(value, metaData, record, rowIndex, colIndex, store) {
+ // provide the logic depending on business rules
+ // name of your own choosing to manipulate the cell depending upon
+ // the data in the underlying Record object.
+ if (value == 'whatever') {
+ //metaData.css : String : A CSS class name to add to the TD element of the cell.
+ //metaData.attr : String : An html attribute definition string to apply to
+ // the data container element within the table
+ // cell (e.g. 'style="color:red;"').
+ metaData.css = 'name-of-css-class-you-will-define';
+ }
+ return value;
+ }
+}
+ * </code></pre>
+ * See also {@link #scope}.
+ */
+ /**
+ * @cfg {String} xtype Optional. A String which references a predefined {@link Ext.grid.Column} subclass
+ * type which is preconfigured with an appropriate <code>{@link #renderer}</code> to be easily
+ * configured into a ColumnModel. The predefined {@link Ext.grid.Column} subclass types are:
+ * <div class="mdetail-params"><ul>
+ * <li><b><tt>gridcolumn</tt></b> : {@link Ext.grid.Column} (<b>Default</b>)<p class="sub-desc"></p></li>
+ * <li><b><tt>booleancolumn</tt></b> : {@link Ext.grid.BooleanColumn}<p class="sub-desc"></p></li>
+ * <li><b><tt>numbercolumn</tt></b> : {@link Ext.grid.NumberColumn}<p class="sub-desc"></p></li>
+ * <li><b><tt>datecolumn</tt></b> : {@link Ext.grid.DateColumn}<p class="sub-desc"></p></li>
+ * <li><b><tt>templatecolumn</tt></b> : {@link Ext.grid.TemplateColumn}<p class="sub-desc"></p></li>
+ * </ul></div>
+ * <p>Configuration properties for the specified <code>xtype</code> may be specified with
+ * the Column configuration properties, for example:</p>
+ * <pre><code>
+var grid = new Ext.grid.GridPanel({
+ ...
+ columns: [{
+ header: 'Last Updated',
+ dataIndex: 'lastChange',
+ width: 85,
+ sortable: true,
+ //renderer: Ext.util.Format.dateRenderer('m/d/Y'),
+ xtype: 'datecolumn', // use xtype instead of renderer
+ format: 'M/d/Y' // configuration property for {@link Ext.grid.DateColumn}
+ }, {
+ ...
+ }]
+});
+ * </code></pre>
+ */
+ /**
+ * @cfg {Object} scope Optional. The scope (<tt><b>this</b></tt> reference) in which to execute the
+ * renderer. Defaults to the Column configuration object.
+ */
+ /**
+ * @cfg {String} align Optional. Set the CSS text-align property of the column. Defaults to undefined.
+ */
+ /**
+ * @cfg {String} css Optional. An inline style definition string which is applied to all table cells in the column
+ * (excluding headers). Defaults to undefined.
+ */
+ /**
+ * @cfg {Boolean} hideable Optional. Specify as <tt>false</tt> to prevent the user from hiding this column
+ * (defaults to true). To disallow column hiding globally for all columns in the grid, use
+ * {@link Ext.grid.GridPanel#enableColumnHide} instead.
+ */
+ /**
+ * @cfg {Ext.form.Field} editor Optional. The {@link Ext.form.Field} to use when editing values in this column
+ * if editing is supported by the grid. See <tt>{@link #editable}</tt> also.
+ */
+
+ /**
+ * @private
+ * @cfg {Boolean} isColumn
+ * Used by ColumnModel setConfig method to avoid reprocessing a Column
+ * if <code>isColumn</code> is not set ColumnModel will recreate a new Ext.grid.Column
+ * Defaults to true.
+ */
+ isColumn : true,
+
+ constructor : function(config){
+ Ext.apply(this, config);
+
+ if(Ext.isString(this.renderer)){
+ this.renderer = Ext.util.Format[this.renderer];
+ }else if(Ext.isObject(this.renderer)){
+ this.scope = this.renderer.scope;
+ this.renderer = this.renderer.fn;
+ }
+ if(!this.scope){
+ this.scope = this;
+ }
+
+ var ed = this.editor;
+ delete this.editor;
+ this.setEditor(ed);
+ },
+
+ /**
+ * Optional. A function which returns displayable data when passed the following parameters:
+ * <div class="mdetail-params"><ul>
+ * <li><b>value</b> : Object<p class="sub-desc">The data value for the cell.</p></li>
+ * <li><b>metadata</b> : Object<p class="sub-desc">An object in which you may set the following attributes:<ul>
+ * <li><b>css</b> : String<p class="sub-desc">A CSS class name to add to the cell's TD element.</p></li>
+ * <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 (e.g. 'style="color:red;"').</p></li></ul></p></li>
+ * <li><b>record</b> : Ext.data.record<p class="sub-desc">The {@link Ext.data.Record} from which the data was
+ * extracted.</p></li>
+ * <li><b>rowIndex</b> : Number<p class="sub-desc">Row index</p></li>
+ * <li><b>colIndex</b> : Number<p class="sub-desc">Column index</p></li>
+ * <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></div>
+ * @property renderer
+ * @type Function
+ */
+ renderer : function(value){
+ if(Ext.isString(value) && value.length < 1){
+ return ' ';
+ }
+ return value;
+ },
+
+ // private
+ getEditor: function(rowIndex){
+ return this.editable !== false ? this.editor : null;
+ },
+
+ /**
+ * Sets a new editor for this column.
+ * @param {Ext.Editor/Ext.form.Field} editor The editor to set
+ */
+ setEditor : function(editor){
+ var ed = this.editor;
+ if(ed){
+ if(ed.gridEditor){
+ ed.gridEditor.destroy();
+ delete ed.gridEditor;
+ }else{
+ ed.destroy();
+ }
+ }
+ this.editor = null;
+ if(editor){
+ //not an instance, create it
+ if(!editor.isXType){
+ editor = Ext.create(editor, 'textfield');
+ }
+ this.editor = editor;
+ }
+ },
+
+ /**
+ * Returns the {@link Ext.Editor editor} defined for this column that was created to wrap the {@link Ext.form.Field Field}
+ * used to edit the cell.
+ * @param {Number} rowIndex The row index
+ * @return {Ext.Editor}
+ */
+ getCellEditor: function(rowIndex){
+ var ed = this.getEditor(rowIndex);
+ if(ed){
+ if(!ed.startEdit){
+ if(!ed.gridEditor){
+ ed.gridEditor = new Ext.grid.GridEditor(ed);
+ }
+ ed = ed.gridEditor;
+ }
+ }
+ return ed;
+ }
+});
+
+/**
+ * @class Ext.grid.BooleanColumn
+ * @extends Ext.grid.Column
+ * <p>A Column definition class which renders boolean data fields. See the {@link Ext.grid.Column#xtype xtype}
+ * config option of {@link Ext.grid.Column} for more details.</p>
+ */
+Ext.grid.BooleanColumn = Ext.extend(Ext.grid.Column, {
+ /**
+ * @cfg {String} trueText
+ * The string returned by the renderer when the column value is not falsey (defaults to <tt>'true'</tt>).
+ */
+ trueText: 'true',
+ /**
+ * @cfg {String} falseText
+ * The string returned by the renderer when the column value is falsey (but not undefined) (defaults to
+ * <tt>'false'</tt>).
+ */
+ falseText: 'false',
+ /**
+ * @cfg {String} undefinedText
+ * The string returned by the renderer when the column value is undefined (defaults to <tt>' '</tt>).
+ */
+ undefinedText: ' ',
+
+ constructor: function(cfg){
+ Ext.grid.BooleanColumn.superclass.constructor.call(this, cfg);
+ var t = this.trueText, f = this.falseText, u = this.undefinedText;
+ this.renderer = function(v){
+ if(v === undefined){
+ return u;
+ }
+ if(!v || v === 'false'){
+ return f;
+ }
+ return t;
+ };
+ }
+});
+
+/**
+ * @class Ext.grid.NumberColumn
+ * @extends Ext.grid.Column
+ * <p>A Column definition class which renders a numeric data field according to a {@link #format} string. See the
+ * {@link Ext.grid.Column#xtype xtype} config option of {@link Ext.grid.Column} for more details.</p>
+ */
+Ext.grid.NumberColumn = Ext.extend(Ext.grid.Column, {
+ /**
+ * @cfg {String} format
+ * A formatting string as used by {@link Ext.util.Format#number} to format a numeric value for this Column
+ * (defaults to <tt>'0,000.00'</tt>).
+ */
+ format : '0,000.00',
+ constructor: function(cfg){
+ Ext.grid.NumberColumn.superclass.constructor.call(this, cfg);
+ this.renderer = Ext.util.Format.numberRenderer(this.format);
+ }
+});
+
+/**
+ * @class Ext.grid.DateColumn
+ * @extends Ext.grid.Column
+ * <p>A Column definition class which renders a passed date according to the default locale, or a configured
+ * {@link #format}. See the {@link Ext.grid.Column#xtype xtype} config option of {@link Ext.grid.Column}
+ * for more details.</p>
+ */
+Ext.grid.DateColumn = Ext.extend(Ext.grid.Column, {
+ /**
+ * @cfg {String} format
+ * A formatting string as used by {@link Date#format} to format a Date for this Column
+ * (defaults to <tt>'m/d/Y'</tt>).
+ */
+ format : 'm/d/Y',
+ constructor: function(cfg){
+ Ext.grid.DateColumn.superclass.constructor.call(this, cfg);
+ this.renderer = Ext.util.Format.dateRenderer(this.format);
+ }
+});
+
+/**
+ * @class Ext.grid.TemplateColumn
+ * @extends Ext.grid.Column
+ * <p>A Column definition class which renders a value by processing a {@link Ext.data.Record Record}'s
+ * {@link Ext.data.Record#data data} using a {@link #tpl configured} {@link Ext.XTemplate XTemplate}.
+ * See the {@link Ext.grid.Column#xtype xtype} config option of {@link Ext.grid.Column} for more
+ * details.</p>
+ */
+Ext.grid.TemplateColumn = Ext.extend(Ext.grid.Column, {
+ /**
+ * @cfg {String/XTemplate} tpl
+ * An {@link Ext.XTemplate XTemplate}, or an XTemplate <i>definition string</i> to use to process a
+ * {@link Ext.data.Record Record}'s {@link Ext.data.Record#data data} to produce a column's rendered value.
+ */
+ constructor: function(cfg){
+ Ext.grid.TemplateColumn.superclass.constructor.call(this, cfg);
+ var tpl = (!Ext.isPrimitive(this.tpl) && this.tpl.compile) ? this.tpl : new Ext.XTemplate(this.tpl);
+ this.renderer = function(value, p, r){
+ return tpl.apply(r.data);
+ };
+ this.tpl = tpl;
+ }
+});
+
+/*
+ * @property types
+ * @type Object
+ * @member Ext.grid.Column
+ * @static
+ * <p>An object containing predefined Column classes keyed by a mnemonic code which may be referenced
+ * by the {@link Ext.grid.ColumnModel#xtype xtype} config option of ColumnModel.</p>
+ * <p>This contains the following properties</p><div class="mdesc-details"><ul>
+ * <li>gridcolumn : <b>{@link Ext.grid.Column Column constructor}</b></li>
+ * <li>booleancolumn : <b>{@link Ext.grid.BooleanColumn BooleanColumn constructor}</b></li>
+ * <li>numbercolumn : <b>{@link Ext.grid.NumberColumn NumberColumn constructor}</b></li>
+ * <li>datecolumn : <b>{@link Ext.grid.DateColumn DateColumn constructor}</b></li>
+ * <li>templatecolumn : <b>{@link Ext.grid.TemplateColumn TemplateColumn constructor}</b></li>
+ * </ul></div>
+ */
+Ext.grid.Column.types = {
+ gridcolumn : Ext.grid.Column,
+ booleancolumn: Ext.grid.BooleanColumn,
+ numbercolumn: Ext.grid.NumberColumn,
+ datecolumn: Ext.grid.DateColumn,
+ templatecolumn: Ext.grid.TemplateColumn
};/**
* @class Ext.grid.RowNumberer
* This is a utility class that can be passed into a {@link Ext.grid.ColumnModel} as a column config that provides
* @constructor
* @param {Object} config The configuration options
*/
-Ext.grid.RowNumberer = function(config){
- Ext.apply(this, config);
- if(this.rowspan){
- this.renderer = this.renderer.createDelegate(this);
- }
-};
-
-Ext.grid.RowNumberer.prototype = {
+Ext.grid.RowNumberer = Ext.extend(Object, {
/**
* @cfg {String} header Any valid text or HTML fragment to display in the header cell for the row
* number column (defaults to '').
* @hide
*/
sortable: false,
+
+ constructor : function(config){
+ Ext.apply(this, config);
+ if(this.rowspan){
+ this.renderer = this.renderer.createDelegate(this);
+ }
+ },
// private
fixed:true,
+ hideable: false,
menuDisabled:true,
dataIndex: '',
id: 'numberer',
}
return rowIndex+1;
}
-};/**\r
- * @class Ext.grid.CheckboxSelectionModel\r
- * @extends Ext.grid.RowSelectionModel\r
- * A custom selection model that renders a column of checkboxes that can be toggled to select or deselect rows.\r
- * @constructor\r
- * @param {Object} config The configuration options\r
- */\r
-Ext.grid.CheckboxSelectionModel = Ext.extend(Ext.grid.RowSelectionModel, {\r
-\r
- /**\r
- * @cfg {Boolean} checkOnly <tt>true</tt> if rows can only be selected by clicking on the\r
- * checkbox column (defaults to <tt>false</tt>).\r
- */\r
- /**\r
- * @cfg {String} header Any valid text or HTML fragment to display in the header cell for the\r
- * checkbox column. Defaults to:<pre><code>\r
- * '<div class="x-grid3-hd-checker">&#160;</div>'</tt>\r
- * </code></pre>\r
- * The default CSS class of <tt>'x-grid3-hd-checker'</tt> displays a checkbox in the header\r
- * and provides support for automatic check all/none behavior on header click. This string\r
- * can be replaced by any valid HTML fragment, including a simple text string (e.g.,\r
- * <tt>'Select Rows'</tt>), but the automatic check all/none behavior will only work if the\r
- * <tt>'x-grid3-hd-checker'</tt> class is supplied.\r
- */\r
- header: '<div class="x-grid3-hd-checker"> </div>',\r
- /**\r
- * @cfg {Number} width The default width in pixels of the checkbox column (defaults to <tt>20</tt>).\r
- */\r
- width: 20,\r
- /**\r
- * @cfg {Boolean} sortable <tt>true</tt> if the checkbox column is sortable (defaults to\r
- * <tt>false</tt>).\r
- */\r
- sortable: false,\r
-\r
- // private\r
- menuDisabled:true,\r
- fixed:true,\r
- dataIndex: '',\r
- id: 'checker',\r
-\r
- constructor: function(){\r
- Ext.grid.CheckboxSelectionModel.superclass.constructor.apply(this, arguments);\r
-\r
- if(this.checkOnly){\r
- this.handleMouseDown = Ext.emptyFn;\r
- }\r
- },\r
-\r
- // private\r
- initEvents : function(){\r
- Ext.grid.CheckboxSelectionModel.superclass.initEvents.call(this);\r
- this.grid.on('render', function(){\r
- var view = this.grid.getView();\r
- view.mainBody.on('mousedown', this.onMouseDown, this);\r
- Ext.fly(view.innerHd).on('mousedown', this.onHdMouseDown, this);\r
-\r
- }, this);\r
- },\r
-\r
- // private\r
- onMouseDown : function(e, t){\r
- if(e.button === 0 && t.className == 'x-grid3-row-checker'){ // Only fire if left-click\r
- e.stopEvent();\r
- var row = e.getTarget('.x-grid3-row');\r
- if(row){\r
- var index = row.rowIndex;\r
- if(this.isSelected(index)){\r
- this.deselectRow(index);\r
- }else{\r
- this.selectRow(index, true);\r
- }\r
- }\r
- }\r
- },\r
-\r
- // private\r
- onHdMouseDown : function(e, t){\r
- if(t.className == 'x-grid3-hd-checker'){\r
- e.stopEvent();\r
- var hd = Ext.fly(t.parentNode);\r
- var isChecked = hd.hasClass('x-grid3-hd-checker-on');\r
- if(isChecked){\r
- hd.removeClass('x-grid3-hd-checker-on');\r
- this.clearSelections();\r
- }else{\r
- hd.addClass('x-grid3-hd-checker-on');\r
- this.selectAll();\r
- }\r
- }\r
- },\r
-\r
- // private\r
- renderer : function(v, p, record){\r
- return '<div class="x-grid3-row-checker"> </div>';\r
- }\r
+});/**
+ * @class Ext.grid.CheckboxSelectionModel
+ * @extends Ext.grid.RowSelectionModel
+ * A custom selection model that renders a column of checkboxes that can be toggled to select or deselect rows.
+ * @constructor
+ * @param {Object} config The configuration options
+ */
+Ext.grid.CheckboxSelectionModel = Ext.extend(Ext.grid.RowSelectionModel, {
+
+ /**
+ * @cfg {Boolean} checkOnly <tt>true</tt> if rows can only be selected by clicking on the
+ * checkbox column (defaults to <tt>false</tt>).
+ */
+ /**
+ * @cfg {String} header Any valid text or HTML fragment to display in the header cell for the
+ * checkbox column. Defaults to:<pre><code>
+ * '<div class="x-grid3-hd-checker">&#160;</div>'</tt>
+ * </code></pre>
+ * The default CSS class of <tt>'x-grid3-hd-checker'</tt> displays a checkbox in the header
+ * and provides support for automatic check all/none behavior on header click. This string
+ * can be replaced by any valid HTML fragment, including a simple text string (e.g.,
+ * <tt>'Select Rows'</tt>), but the automatic check all/none behavior will only work if the
+ * <tt>'x-grid3-hd-checker'</tt> class is supplied.
+ */
+ header : '<div class="x-grid3-hd-checker"> </div>',
+ /**
+ * @cfg {Number} width The default width in pixels of the checkbox column (defaults to <tt>20</tt>).
+ */
+ width : 20,
+ /**
+ * @cfg {Boolean} sortable <tt>true</tt> if the checkbox column is sortable (defaults to
+ * <tt>false</tt>).
+ */
+ sortable : false,
+
+ // private
+ menuDisabled : true,
+ fixed : true,
+ hideable: false,
+ dataIndex : '',
+ id : 'checker',
+
+ constructor : function(){
+ Ext.grid.CheckboxSelectionModel.superclass.constructor.apply(this, arguments);
+
+ if(this.checkOnly){
+ this.handleMouseDown = Ext.emptyFn;
+ }
+ },
+
+ // private
+ initEvents : function(){
+ Ext.grid.CheckboxSelectionModel.superclass.initEvents.call(this);
+ this.grid.on('render', function(){
+ var view = this.grid.getView();
+ view.mainBody.on('mousedown', this.onMouseDown, this);
+ Ext.fly(view.innerHd).on('mousedown', this.onHdMouseDown, this);
+
+ }, this);
+ },
+
+ // If handleMouseDown was called from another event (enableDragDrop), set a flag so
+ // onMouseDown does not process it a second time
+ handleMouseDown : function() {
+ Ext.grid.CheckboxSelectionModel.superclass.handleMouseDown.apply(this, arguments);
+ this.mouseHandled = true;
+ },
+
+ // private
+ onMouseDown : function(e, t){
+ if(e.button === 0 && t.className == 'x-grid3-row-checker'){ // Only fire if left-click
+ e.stopEvent();
+ var row = e.getTarget('.x-grid3-row');
+
+ // mouseHandled flag check for a duplicate selection (handleMouseDown) call
+ if(!this.mouseHandled && row){
+ var index = row.rowIndex;
+ if(this.isSelected(index)){
+ this.deselectRow(index);
+ }else{
+ this.selectRow(index, true);
+ this.grid.getView().focusRow(index);
+ }
+ }
+ }
+ this.mouseHandled = false;
+ },
+
+ // private
+ onHdMouseDown : function(e, t){
+ if(t.className == 'x-grid3-hd-checker'){
+ e.stopEvent();
+ var hd = Ext.fly(t.parentNode);
+ var isChecked = hd.hasClass('x-grid3-hd-checker-on');
+ if(isChecked){
+ hd.removeClass('x-grid3-hd-checker-on');
+ this.clearSelections();
+ }else{
+ hd.addClass('x-grid3-hd-checker-on');
+ this.selectAll();
+ }
+ }
+ },
+
+ // private
+ renderer : function(v, p, record){
+ return '<div class="x-grid3-row-checker"> </div>';
+ }
});
\ No newline at end of file