Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / source / widgets / grid / ColumnModel.js
diff --git a/source/widgets/grid/ColumnModel.js b/source/widgets/grid/ColumnModel.js
deleted file mode 100644 (file)
index 9664c5a..0000000
+++ /dev/null
@@ -1,590 +0,0 @@
-/*\r
- * Ext JS Library 2.2.1\r
- * Copyright(c) 2006-2009, Ext JS, LLC.\r
- * licensing@extjs.com\r
- * \r
- * http://extjs.com/license\r
- */\r
-\r
-/**\r
- * @class Ext.grid.ColumnModel\r
- * @extends Ext.util.Observable\r
- * This is the default implementation of a ColumnModel used by the Grid. This class is initialized\r
- * with an Array of column config objects.\r
- * <br><br>\r
- * An individual column's config object defines the header string, the {@link Ext.data.Record}\r
- * field the column draws its data from, an optional rendering function to provide customized\r
- * data formatting, and the ability to apply a CSS class to all cells in a column through its\r
- * {@link #id} config option.<br>\r
- * <br>Usage:<br>\r
-<pre><code>\r
- var colModel = new Ext.grid.ColumnModel([\r
-    { header: "Ticker", width: 60, sortable: true},\r
-    { header: "Company Name", width: 150, sortable: true},\r
-    { header: "Market Cap.", width: 100, sortable: true},\r
-    { header: "$ Sales", width: 100, sortable: true, renderer: money},\r
-    { header: "Employees", width: 100, sortable: true, resizable: false}\r
- ]);\r
- </code></pre>\r
- * <p>\r
- * The config options <b>defined by</b> this class are options which may appear in each\r
- * individual column definition. In order to use configuration options from the superclass,\r
- * specify the column configuration Array in the <tt><b>columns<b><tt> config property. eg:<pre><code>\r
- var colModel = new Ext.grid.ColumnModel({\r
-    listeners: {\r
-        widthchange: function(cm, colIndex, width) {\r
-            saveConfig(colIndex, width);\r
-        }\r
-    },\r
-    columns: [\r
-        { header: "Ticker", width: 60, sortable: true},\r
-        { header: "Company Name", width: 150, sortable: true},\r
-        { header: "Market Cap.", width: 100, sortable: true},\r
-        { header: "$ Sales", width: 100, sortable: true, renderer: money},\r
-        { header: "Employees", width: 100, sortable: true, resizable: false}\r
-     ]\r
-});\r
- </code></pre>\r
- * @constructor\r
- * @param {Object} config An Array of column config objects. See this class's\r
- * config objects for details.\r
-*/\r
-Ext.grid.ColumnModel = function(config){\r
-    /**\r
-     * The width of columns which have no width specified (defaults to 100)\r
-     * @type Number\r
-     */\r
-    this.defaultWidth = 100;\r
-\r
-    /**\r
-     * Default sortable of columns which have no sortable specified (defaults to false)\r
-     * @type Boolean\r
-     */\r
-    this.defaultSortable = false;\r
-\r
-    /**\r
-     * The config passed into the constructor\r
-     * @property {Array} config\r
-     */\r
-    if(config.columns){\r
-        Ext.apply(this, config);\r
-        this.setConfig(config.columns, true);\r
-    }else{\r
-        this.setConfig(config, true);\r
-    }\r
-    this.addEvents(\r
-        /**\r
-         * @event widthchange\r
-         * Fires when the width of a column changes.\r
-         * @param {ColumnModel} this\r
-         * @param {Number} columnIndex The column index\r
-         * @param {Number} newWidth The new width\r
-         */\r
-        "widthchange",\r
-        /**\r
-         * @event headerchange\r
-         * Fires when the text of a header changes.\r
-         * @param {ColumnModel} this\r
-         * @param {Number} columnIndex The column index\r
-         * @param {String} newText The new header text\r
-         */\r
-        "headerchange",\r
-        /**\r
-         * @event hiddenchange\r
-         * Fires when a column is hidden or "unhidden".\r
-         * @param {ColumnModel} this\r
-         * @param {Number} columnIndex The column index\r
-         * @param {Boolean} hidden true if hidden, false otherwise\r
-         */\r
-        "hiddenchange",\r
-        /**\r
-         * @event columnmoved\r
-         * Fires when a column is moved.\r
-         * @param {ColumnModel} this\r
-         * @param {Number} oldIndex\r
-         * @param {Number} newIndex\r
-         */\r
-        "columnmoved",\r
-        // deprecated - to be removed\r
-        "columnlockchange",\r
-        /**\r
-         * @event configchange\r
-         * Fires when the configuration is changed\r
-         * @param {ColumnModel} this\r
-         */\r
-        "configchange"\r
-    );\r
-    Ext.grid.ColumnModel.superclass.constructor.call(this);\r
-};\r
-Ext.extend(Ext.grid.ColumnModel, Ext.util.Observable, {\r
-    /**\r
-     * @cfg {String} id (optional) Defaults to the column's initial ordinal position.\r
-     * A name which identifies this column. The id is used to create a CSS class name which\r
-     * is applied to all table cells (including headers) in that column. The class name\r
-     * takes the form of <pre>x-grid3-td-<b>id</b></pre>\r
-     * <br><br>\r
-     * Header cells will also recieve this class name, but will also have the class <pr>x-grid3-hd</pre>,\r
-     * so to target header cells, use CSS selectors such as:<pre>.x-grid3-hd.x-grid3-td-<b>id</b></pre>\r
-     * The {@link Ext.grid.GridPanel#autoExpandColumn} grid config option references the column\r
-     * via this identifier.\r
-     */\r
-    /**\r
-     * @cfg {String} header The header text to display in the Grid view.\r
-     */\r
-    /**\r
-     * @cfg {String} dataIndex (optional) The name of the field in the grid's {@link Ext.data.Store}'s\r
-     * {@link Ext.data.Record} definition from which to draw the column's value. If not\r
-     * specified, the column's index is used as an index into the Record's data Array.\r
-     */\r
-    /**\r
-     * @cfg {Number} width (optional) The initial width in pixels of the column. This is ignored if the\r
-     * Grid's {@link Ext.grid.GridView view} is configured with {@link Ext.grid.GridView#forceFit forceFit} true.\r
-     */\r
-    /**\r
-     * @cfg {Boolean} sortable (optional) True 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) True if the column width cannot be changed.  Defaults to false.\r
-     */\r
-    /**\r
-     * @cfg {Boolean} resizable (optional) False to disable column resizing. Defaults to true.\r
-     */\r
-    /**\r
-     * @cfg {Boolean} menuDisabled (optional) True to disable the column menu. Defaults to false.\r
-     */\r
-    /**\r
-     * @cfg {Boolean} hidden (optional) True to hide the column. Defaults to false.\r
-     */\r
-    /**\r
-     * @cfg {String} tooltip (optional) A text string to use as the column header's tooltip.  If Quicktips are enabled, this\r
-     * value will be used as the text of the quick tip, otherwise it will be set as the header's HTML title attribute.\r
-     * Defaults to ''.\r
-     */\r
-    /**\r
-     * @cfg {Function} renderer (optional) A function used to generate HTML markup for a cell\r
-     * given the cell's data value. See {@link #setRenderer}. If not specified, the\r
-     * default renderer uses the raw data value.\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) Set custom CSS for all table cells in the column (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 if\r
-     * editing is supported by the grid.\r
-     */\r
-\r
-    /**\r
-     * Returns the id of the column at the specified index.\r
-     * @param {Number} index The column index\r
-     * @return {String} the id\r
-     */\r
-    getColumnId : function(index){\r
-        return this.config[index].id;\r
-    },\r
-\r
-    /**\r
-     * <p>Reconfigures this column model according to the passed Array of column definition objects. For a description of\r
-     * the individual properties of a column definition object, see the <a href="#Ext.grid.ColumnModel-configs">Config Options</a>.</p>\r
-     * <p>Causes the {@link #configchange} event to be fired. A {@link Ext.grid.GridPanel GridPanel} using\r
-     * this ColumnModel will listen for this event and refresh its UI automatically.</p>\r
-     * @param {Array} config Array of Column definition objects.\r
-     */\r
-    setConfig : function(config, initial){\r
-        if(!initial){ // cleanup\r
-            delete this.totalWidth;\r
-            for(var i = 0, len = this.config.length; i < len; i++){\r
-                var c = this.config[i];\r
-                if(c.editor){\r
-                    c.editor.destroy();\r
-                }\r
-            }\r
-        }\r
-        this.config = config;\r
-        this.lookup = {};\r
-        // if no id, create one\r
-        for(var i = 0, len = config.length; i < len; i++){\r
-            var c = config[i];\r
-            if(typeof c.renderer == "string"){\r
-                c.renderer = Ext.util.Format[c.renderer];\r
-            }\r
-            if(typeof c.id == "undefined"){\r
-                c.id = i;\r
-            }\r
-            if(c.editor && c.editor.isFormField){\r
-                c.editor = new Ext.grid.GridEditor(c.editor);\r
-            }\r
-            this.lookup[c.id] = c;\r
-        }\r
-        if(!initial){\r
-            this.fireEvent('configchange', this);\r
-        }\r
-    },\r
-\r
-    /**\r
-     * Returns the column for a specified id.\r
-     * @param {String} id The column id\r
-     * @return {Object} the column\r
-     */\r
-    getColumnById : function(id){\r
-        return this.lookup[id];\r
-    },\r
-\r
-    /**\r
-     * Returns the index for a specified column id.\r
-     * @param {String} id The column id\r
-     * @return {Number} the index, or -1 if not found\r
-     */\r
-    getIndexById : function(id){\r
-        for(var i = 0, len = this.config.length; i < len; i++){\r
-            if(this.config[i].id == id){\r
-                return i;\r
-            }\r
-        }\r
-        return -1;\r
-    },\r
-\r
-    /**\r
-     * Moves a column from one position to another.\r
-     * @param {Number} oldIndex The index of the column to move.\r
-     * @param {Number} newIndex The position at which to reinsert the coolumn.\r
-     */\r
-    moveColumn : function(oldIndex, newIndex){\r
-        var c = this.config[oldIndex];\r
-        this.config.splice(oldIndex, 1);\r
-        this.config.splice(newIndex, 0, c);\r
-        this.dataMap = null;\r
-        this.fireEvent("columnmoved", this, oldIndex, newIndex);\r
-    },\r
-\r
-    // deprecated - to be removed\r
-    isLocked : function(colIndex){\r
-        return this.config[colIndex].locked === true;\r
-    },\r
-\r
-    // deprecated - to be removed\r
-    setLocked : function(colIndex, value, suppressEvent){\r
-        if(this.isLocked(colIndex) == value){\r
-            return;\r
-        }\r
-        this.config[colIndex].locked = value;\r
-        if(!suppressEvent){\r
-            this.fireEvent("columnlockchange", this, colIndex, value);\r
-        }\r
-    },\r
-\r
-    // deprecated - to be removed\r
-    getTotalLockedWidth : function(){\r
-        var totalWidth = 0;\r
-        for(var i = 0; i < this.config.length; i++){\r
-            if(this.isLocked(i) && !this.isHidden(i)){\r
-                this.totalWidth += this.getColumnWidth(i);\r
-            }\r
-        }\r
-        return totalWidth;\r
-    },\r
-\r
-    // deprecated - to be removed\r
-    getLockedCount : function(){\r
-        for(var i = 0, len = this.config.length; i < len; i++){\r
-            if(!this.isLocked(i)){\r
-                return i;\r
-            }\r
-        }\r
-    },\r
-\r
-    /**\r
-     * Returns the number of columns.\r
-     * @param {Boolean} visibleOnly Optional. Pass as true to only include visible columns.\r
-     * @return {Number}\r
-     */\r
-    getColumnCount : function(visibleOnly){\r
-        if(visibleOnly === true){\r
-            var c = 0;\r
-            for(var i = 0, len = this.config.length; i < len; i++){\r
-                if(!this.isHidden(i)){\r
-                    c++;\r
-                }\r
-            }\r
-            return c;\r
-        }\r
-        return this.config.length;\r
-    },\r
-\r
-    /**\r
-     * Returns the column configs that return true by the passed function that is called with (columnConfig, index)\r
-     * @param {Function} fn\r
-     * @param {Object} scope (optional)\r
-     * @return {Array} result\r
-     */\r
-    getColumnsBy : function(fn, scope){\r
-        var r = [];\r
-        for(var i = 0, len = this.config.length; i < len; i++){\r
-            var c = this.config[i];\r
-            if(fn.call(scope||this, c, i) === true){\r
-                r[r.length] = c;\r
-            }\r
-        }\r
-        return r;\r
-    },\r
-\r
-    /**\r
-     * Returns true if the specified column is sortable.\r
-     * @param {Number} col The column index\r
-     * @return {Boolean}\r
-     */\r
-    isSortable : function(col){\r
-        if(typeof this.config[col].sortable == "undefined"){\r
-            return this.defaultSortable;\r
-        }\r
-        return this.config[col].sortable;\r
-    },\r
-\r
-    /**\r
-     * Returns true if the specified column menu is disabled.\r
-     * @param {Number} col The column index\r
-     * @return {Boolean}\r
-     */\r
-    isMenuDisabled : function(col){\r
-        return !!this.config[col].menuDisabled;\r
-    },\r
-\r
-    /**\r
-     * Returns the rendering (formatting) function defined for the column.\r
-     * @param {Number} col The column index.\r
-     * @return {Function} The function used to render the cell. See {@link #setRenderer}.\r
-     */\r
-    getRenderer : function(col){\r
-        if(!this.config[col].renderer){\r
-            return Ext.grid.ColumnModel.defaultRenderer;\r
-        }\r
-        return this.config[col].renderer;\r
-    },\r
-\r
-    /**\r
-     * Sets the rendering (formatting) function for a column.  See {@link Ext.util.Format} for some\r
-     * default formatting functions.\r
-     * @param {Number} col The column index\r
-     * @param {Function} fn The function to use to process the cell's raw data\r
-     * to return HTML markup for the grid view. The render function is called with\r
-     * the following parameters:<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 element <i>within</i> the table cell\r
-     * (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 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 was extracted.</p></li></ul>\r
-     */\r
-    setRenderer : function(col, fn){\r
-        this.config[col].renderer = fn;\r
-    },\r
-\r
-    /**\r
-     * Returns the width for the specified column.\r
-     * @param {Number} col The column index\r
-     * @return {Number}\r
-     */\r
-    getColumnWidth : function(col){\r
-        return this.config[col].width || this.defaultWidth;\r
-    },\r
-\r
-    /**\r
-     * Sets the width for a column.\r
-     * @param {Number} col The column index\r
-     * @param {Number} width The new width\r
-     */\r
-    setColumnWidth : function(col, width, suppressEvent){\r
-        this.config[col].width = width;\r
-        this.totalWidth = null;\r
-        if(!suppressEvent){\r
-             this.fireEvent("widthchange", this, col, width);\r
-        }\r
-    },\r
-\r
-    /**\r
-     * Returns the total width of all columns.\r
-     * @param {Boolean} includeHidden True to include hidden column widths\r
-     * @return {Number}\r
-     */\r
-    getTotalWidth : function(includeHidden){\r
-        if(!this.totalWidth){\r
-            this.totalWidth = 0;\r
-            for(var i = 0, len = this.config.length; i < len; i++){\r
-                if(includeHidden || !this.isHidden(i)){\r
-                    this.totalWidth += this.getColumnWidth(i);\r
-                }\r
-            }\r
-        }\r
-        return this.totalWidth;\r
-    },\r
-\r
-    /**\r
-     * Returns the header for the specified column.\r
-     * @param {Number} col The column index\r
-     * @return {String}\r
-     */\r
-    getColumnHeader : function(col){\r
-        return this.config[col].header;\r
-    },\r
-\r
-    /**\r
-     * Sets the header for a column.\r
-     * @param {Number} col The column index\r
-     * @param {String} header The new header\r
-     */\r
-    setColumnHeader : function(col, header){\r
-        this.config[col].header = header;\r
-        this.fireEvent("headerchange", this, col, header);\r
-    },\r
-\r
-    /**\r
-     * Returns the tooltip for the specified column.\r
-     * @param {Number} col The column index\r
-     * @return {String}\r
-     */\r
-    getColumnTooltip : function(col){\r
-            return this.config[col].tooltip;\r
-    },\r
-    /**\r
-     * Sets the tooltip for a column.\r
-     * @param {Number} col The column index\r
-     * @param {String} tooltip The new tooltip\r
-     */\r
-    setColumnTooltip : function(col, tooltip){\r
-            this.config[col].tooltip = tooltip;\r
-    },\r
-\r
-    /**\r
-     * Returns the dataIndex for the specified column.\r
-     * @param {Number} col The column index\r
-     * @return {String} The column's dataIndex\r
-     */\r
-    getDataIndex : function(col){\r
-        return this.config[col].dataIndex;\r
-    },\r
-\r
-    /**\r
-     * Sets the dataIndex for a column.\r
-     * @param {Number} col The column index\r
-     * @param {String} dataIndex The new dataIndex\r
-     */\r
-    setDataIndex : function(col, dataIndex){\r
-        this.config[col].dataIndex = dataIndex;\r
-    },\r
-\r
-    /**\r
-     * Finds the index of the first matching column for the given dataIndex.\r
-     * @param {String} col The dataIndex to find\r
-     * @return {Number} The column index, or -1 if no match was found\r
-     */\r
-    findColumnIndex : function(dataIndex){\r
-        var c = this.config;\r
-        for(var i = 0, len = c.length; i < len; i++){\r
-            if(c[i].dataIndex == dataIndex){\r
-                return i;\r
-            }\r
-        }\r
-        return -1;\r
-    },\r
-\r
-    /**\r
-     * Returns true if the cell is editable.\r
-     * @param {Number} colIndex The column index\r
-     * @param {Number} rowIndex The row index\r
-     * @return {Boolean}\r
-     */\r
-    isCellEditable : function(colIndex, rowIndex){\r
-        return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false;\r
-    },\r
-\r
-    /**\r
-     * Returns the editor defined for the cell/column.\r
-     * @param {Number} colIndex The column index\r
-     * @param {Number} rowIndex The row index\r
-     * @return {Ext.Editor} The {@link Ext.Editor Editor} that was created to wrap \r
-     * the {@link Ext.form.Field Field} used to edit the cell.\r
-     */\r
-    getCellEditor : function(colIndex, rowIndex){\r
-        return this.config[colIndex].editor;\r
-    },\r
-\r
-    /**\r
-     * Sets if a column is editable.\r
-     * @param {Number} col The column index\r
-     * @param {Boolean} editable True if the column is editable\r
-     */\r
-    setEditable : function(col, editable){\r
-        this.config[col].editable = editable;\r
-    },\r
-\r
-\r
-    /**\r
-     * Returns true if the column is hidden.\r
-     * @param {Number} colIndex The column index\r
-     * @return {Boolean}\r
-     */\r
-    isHidden : function(colIndex){\r
-        return this.config[colIndex].hidden;\r
-    },\r
-\r
-\r
-    /**\r
-     * Returns true if the column width cannot be changed\r
-     */\r
-    isFixed : function(colIndex){\r
-        return this.config[colIndex].fixed;\r
-    },\r
-\r
-    /**\r
-     * Returns true if the column can be resized\r
-     * @return {Boolean}\r
-     */\r
-    isResizable : function(colIndex){\r
-        return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;\r
-    },\r
-    /**\r
-     * Sets if a column is hidden.\r
-     * @param {Number} colIndex The column index\r
-     * @param {Boolean} hidden True if the column is hidden\r
-     */\r
-    setHidden : function(colIndex, hidden){\r
-        var c = this.config[colIndex];\r
-        if(c.hidden !== hidden){\r
-            c.hidden = hidden;\r
-            this.totalWidth = null;\r
-            this.fireEvent("hiddenchange", this, colIndex, hidden);\r
-        }\r
-    },\r
-\r
-    /**\r
-     * Sets the editor for a column.\r
-     * @param {Number} col The column index\r
-     * @param {Object} editor The editor object\r
-     */\r
-    setEditor : function(col, editor){\r
-        this.config[col].editor = editor;\r
-    }\r
-});\r
-\r
-// private\r
-Ext.grid.ColumnModel.defaultRenderer = function(value){\r
-    if(typeof value == "string" && value.length < 1){\r
-        return "&#160;";\r
-    }\r
-    return value;\r
-};\r
-\r
-// Alias for backwards compatibility\r
-Ext.grid.DefaultColumnModel = Ext.grid.ColumnModel;
\ No newline at end of file