X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/3789b528d8dd8aad4558e38e22d775bcab1cbd36..refs/heads/master:/docs/source/Container2.html diff --git a/docs/source/Container2.html b/docs/source/Container2.html index 812ac75f..d54c25b1 100644 --- a/docs/source/Container2.html +++ b/docs/source/Container2.html @@ -3,8 +3,8 @@
/** * @class Ext.grid.header.Container * @extends Ext.container.Container - * @private * * Container which holds headers and is docked at the top or bottom of a TablePanel. * The HeaderContainer drives resizing/moving/hiding of columns within the TableView. * As headers are hidden, moved or resized the headercontainer is responsible for * triggering changes within the view. - * - * @xtype headercontainer */ Ext.define('Ext.grid.header.Container', { extend: 'Ext.container.Container', @@ -89,10 +86,10 @@ Ext.define('Ext.grid.header.Container', { * items for every header. */ sortable: true, - + initComponent: function() { var me = this; - + me.headerCounter = 0; me.plugins = me.plugins || []; @@ -106,7 +103,7 @@ Ext.define('Ext.grid.header.Container', { me.reorderer = Ext.create('Ext.grid.plugin.HeaderReorderer'); if (!me.enableColumnResize) { me.resizer.disable(); - } + } if (!me.enableColumnMove) { me.reorderer.disable(); } @@ -201,6 +198,61 @@ Ext.define('Ext.grid.header.Container', { Ext.destroy(this.resizer, this.reorderer); this.callParent(); }, + + applyDefaults: function(config){ + /* + * Ensure header.Container defaults don't get applied to a RowNumberer + * if an xtype is supplied. This isn't an ideal solution however it's + * much more likely that a RowNumberer with no options will be created, + * wanting to use the defaults specified on the class as opposed to + * those setup on the Container. + */ + if (config && !config.isComponent && config.xtype == 'rownumberer') { + return config; + } + return this.callParent([config]); + }, + + applyColumnsState: function(columns) { + if (!columns || !columns.length) { + return; + } + + var me = this, + i = 0, + index, + col; + + Ext.each(columns, function (columnState) { + col = me.down('gridcolumn[headerId=' + columnState.id + ']'); + if (col) { + index = me.items.indexOf(col); + if (i !== index) { + me.moveHeader(index, i); + } + + if (col.applyColumnState) { + col.applyColumnState(columnState); + } + ++i; + } + }); + }, + + getColumnsState: function () { + var me = this, + columns = [], + state; + + me.items.each(function (col) { + state = col.getColumnState && col.getColumnState(); + if (state) { + columns.push(state); + } + }); + + return columns; + }, // Invalidate column cache on add // We cannot refresh the View on every add because this method is called @@ -208,8 +260,17 @@ Ext.define('Ext.grid.header.Container', { onAdd: function(c) { var me = this; if (!c.headerId) { - c.headerId = 'h' + (++me.headerCounter); + c.headerId = c.initialConfig.id || ('h' + (++me.headerCounter)); } + //<debug warn> + if (Ext.global.console && Ext.global.console.warn) { + if (!me._usedIDs) me._usedIDs = {}; + if (me._usedIDs[c.headerId]) { + Ext.global.console.warn(this.$className, 'attempted to reuse an existing id', c.headerId); + } + me._usedIDs[c.headerId] = true; + } + //</debug> me.callParent(arguments); me.purgeCache(); }, @@ -242,18 +303,36 @@ Ext.define('Ext.grid.header.Container', { if (!this.isHeader) { var me = this, topHeaders = me.query('>gridcolumn:not([hidden])'), - viewEl; + viewEl, + firstHeaderEl, + lastHeaderEl; me.callParent(arguments); if (topHeaders.length) { - topHeaders[0].el.radioCls(me.firstHeaderCls); - topHeaders[topHeaders.length - 1].el.radioCls(me.lastHeaderCls); + firstHeaderEl = topHeaders[0].el; + if (firstHeaderEl !== me.pastFirstHeaderEl) { + if (me.pastFirstHeaderEl) { + me.pastFirstHeaderEl.removeCls(me.firstHeaderCls); + } + firstHeaderEl.addCls(me.firstHeaderCls); + me.pastFirstHeaderEl = firstHeaderEl; + } + + lastHeaderEl = topHeaders[topHeaders.length - 1].el; + if (lastHeaderEl !== me.pastLastHeaderEl) { + if (me.pastLastHeaderEl) { + me.pastLastHeaderEl.removeCls(me.lastHeaderCls); + } + lastHeaderEl.addCls(me.lastHeaderCls); + me.pastLastHeaderEl = lastHeaderEl; + } } } + }, - onHeaderShow: function(header) { + onHeaderShow: function(header, preventLayout) { // Pass up to the GridSection var me = this, gridSection = me.ownerCt, @@ -304,7 +383,20 @@ Ext.define('Ext.grid.header.Container', { me.fireEvent('columnshow', me, header); // The header's own hide suppresses cascading layouts, so lay the headers out now - me.doLayout(); + if (preventLayout !== true) { + me.doLayout(); + } + }, + + doComponentLayout: function(){ + var me = this; + if (me.view && me.view.saveScrollState) { + me.view.saveScrollState(); + } + me.callParent(arguments); + if (me.view && me.view.restoreScrollState) { + me.view.restoreScrollState(); + } }, onHeaderHide: function(header, suppressLayout) { @@ -366,6 +458,10 @@ Ext.define('Ext.grid.header.Container', { for (i = 0; i < len; i++) { itemToDisable = itemsToDisable[i]; if (!Ext.Array.contains(me.disabledMenuItems, itemToDisable)) { + + // If we only want to disable check change: it might be a disabled item, so enable it prior to + // setting its correct disablement level. + itemToDisable.disabled = false; itemToDisable[itemToDisable.menu ? 'disableCheckChange' : 'disable'](); me.disabledMenuItems.push(itemToDisable); } @@ -392,7 +488,6 @@ Ext.define('Ext.grid.header.Container', { if (this.view && this.view.rendered) { this.view.onHeaderResize(header, w, suppressFocus); } - this.fireEvent('columnresize', this, header, w); }, onHeaderClick: function(header, e, t) { @@ -446,6 +541,7 @@ Ext.define('Ext.grid.header.Container', { var me = this; // Delete column cache - column order has changed. delete me.gridDataColumns; + delete me.hideableColumns; // Menu changes when columns are moved. It will be recreated. if (me.menu) { @@ -458,7 +554,7 @@ Ext.define('Ext.grid.header.Container', { var me = this, gridSection = me.ownerCt; - if (gridSection) { + if (gridSection && gridSection.onHeaderMove) { gridSection.onHeaderMove(me, header, fromIdx, toIdx); } me.fireEvent("columnmove", me, header, fromIdx, toIdx); @@ -473,6 +569,7 @@ Ext.define('Ext.grid.header.Container', { if (!me.menu) { me.menu = Ext.create('Ext.menu.Menu', { + hideOnParentHide: false, // Persists when owning ColumnHeader is hidden items: me.getMenuItems(), listeners: { deactivate: me.onMenuDeactivate, @@ -492,27 +589,31 @@ Ext.define('Ext.grid.header.Container', { */ getMenuItems: function() { var me = this, - menuItems = [{ - itemId: 'columnItem', - text: me.columnsText, - cls: Ext.baseCSSPrefix + 'cols-icon', - menu: me.getColumnMenu(me) - }]; + menuItems = [], + hideableColumns = me.enableColumnHide ? me.getColumnMenu(me) : null; if (me.sortable) { - menuItems.unshift({ + menuItems = [{ itemId: 'ascItem', text: me.sortAscText, - cls: 'xg-hmenu-sort-asc', + cls: Ext.baseCSSPrefix + 'hmenu-sort-asc', handler: me.onSortAscClick, scope: me },{ itemId: 'descItem', text: me.sortDescText, - cls: 'xg-hmenu-sort-desc', + cls: Ext.baseCSSPrefix + 'hmenu-sort-desc', handler: me.onSortDescClick, scope: me - },'-'); + }]; + } + if (hideableColumns && hideableColumns.length) { + menuItems.push('-', { + itemId: 'columnItem', + text: me.columnsText, + cls: Ext.baseCSSPrefix + 'cols-icon', + menu: hideableColumns + }); } return menuItems; }, @@ -590,14 +691,27 @@ Ext.define('Ext.grid.header.Container', { headers = this.getGridColumns(flushCache), headersLn = headers.length, i = 0, - header; + header, + width; for (; i < headersLn; i++) { header = headers[i]; + + if (header.hidden || header.up('headercontainer[hidden=true]')) { + width = 0; + } else { + width = header.getDesiredWidth(); + // IE6 and IE7 bug. + // Setting the width of the first TD does not work - ends up with a 1 pixel discrepancy. + // We need to increment the passed with in this case. + if ((i === 0) && (Ext.isIE6 || Ext.isIE7)) { + width += 1; + } + } cols.push({ dataIndex: header.dataIndex, align: header.align, - width: header.hidden ? 0 : header.getDesiredWidth(), + width: width, id: header.id, cls: header.tdCls, columnId: header.getItemId() @@ -657,7 +771,7 @@ Ext.define('Ext.grid.header.Container', { }, /** - * Returns an array of the <b>visible<b> columns in the grid. This goes down to the lowest column header + * Returns an array of the <b>visible</b> columns in the grid. This goes down to the lowest column header * level, and does not return <i>grouped</i> headers which contain sub headers. * @param {Boolean} refreshCache If omitted, the cached set of columns will be returned. Pass true to refresh the cache. * @returns {Array} @@ -689,6 +803,21 @@ Ext.define('Ext.grid.header.Container', { return result; }, + /** + * @private + * For use by column headers in determining whether there are any hideable columns when deciding whether or not + * the header menu should be disabled. + */ + getHideableColumns: function(refreshCache) { + var me = this, + result = refreshCache ? null : me.hideableColumns; + + if (!result) { + result = me.hideableColumns = me.query('[hideable]'); + } + return result; + }, + /** * Get the index of a leaf level header regardless of what the nesting * structure is. @@ -739,7 +868,7 @@ Ext.define('Ext.grid.header.Container', { if (typeof renderer === "string") { header.renderer = renderer = Ext.util.Format[renderer]; } - + if (typeof renderer === "function") { value = renderer.call( header.scope || this.ownerCt, @@ -763,8 +892,8 @@ Ext.define('Ext.grid.header.Container', { delete metaData.css; } // </debug> - - obj[headerId+'-modified'] = record.modified[header.dataIndex] ? Ext.baseCSSPrefix + 'grid-dirty-cell' : Ext.baseCSSPrefix + 'grid-clean-cell'; + + obj[headerId+'-modified'] = record.isModified(header.dataIndex) ? Ext.baseCSSPrefix + 'grid-dirty-cell' : ''; obj[headerId+'-tdCls'] = metaData.tdCls; obj[headerId+'-tdAttr'] = metaData.tdAttr; obj[headerId+'-style'] = metaData.style;