⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 columnmodel.js

📁 Ext JS是一个创建丰富互联网应用程序的跨浏览器的JavaScrip库。它包含:高效率
💻 JS
📖 第 1 页 / 共 2 页
字号:
/*
 * Ext JS Library 3.0 Pre-alpha
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

/** * @class Ext.grid.ColumnModel * @extends Ext.util.Observable * <p>After the data has been read into the client side cache (<b>{@link Ext.data.Store Store}</b>), * the ColumnModel is used to configure how and what parts of that data will be displayed in the * vertical slices (columns) of the grid. The Ext.grid.ColumnModel Class is the default implementation * of a ColumnModel used by implentations of {@link Ext.grid.GridPanel GridPanel}.</p>  * <p>Data is mapped into the store's records and then indexed into the ColumnModel using the * <tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt>:</p> * <pre><code>{data source} == mapping ==> {data store} == <b><tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt></b> ==> {ColumnModel} * </code></pre>  * <p>Each {@link Ext.grid.Column Column} in the grid's ColumnModel is configured with a * <tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt> to specify how the data within * each record in the store is indexed into the ColumnModel.</p> * <p>There are two ways to initialize the ColumnModel class:</p> * <p><u>Initialization Method 1: an Array</u></p><pre><code> var colModel = new Ext.grid.ColumnModel([    { header: "Ticker", width: 60, sortable: true},    { header: "Company Name", width: 150, sortable: true, id: 'company'},    { header: "Market Cap.", width: 100, sortable: true},    { header: "$ Sales", width: 100, sortable: true, renderer: money},    { header: "Employees", width: 100, sortable: true, resizable: false} ]); </code></pre> * <p>The ColumnModel may be initialized with an Array of {@link Ext.grid.Column} column configuration * objects to define the initial layout / display of the columns in the Grid. The order of each * {@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> * <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 * <b><tt>{@link Ext.grid.Column#dataIndex dataIndex}</tt></b> is not explicitly defined (as shown in the * example above) it will use the column configuration's index in the Array as the index.</p> * <p>See <b><tt>{@link Ext.grid.Column}</tt></b> for additional configuration options for each column.</p> * <p><u>Initialization Method 2: an Object</u></p> * <p>In order to use configuration options from <tt>Ext.grid.ColumnModel</tt>, an Object may be used to * initialize the ColumnModel.  The column configuration Array will be specified in the <tt><b>{@link #columns}</b></tt> * config property. The <tt><b>{@link #defaults}</b></tt> config property can be used to apply defaults * for all columns, eg:</p><pre><code> var colModel = new Ext.grid.ColumnModel({    columns: [        { header: "Ticker", width: 60, menuDisabled: false},        { header: "Company Name", width: 150, id: 'company'},        { header: "Market Cap."},        { header: "$ Sales", renderer: money},        { header: "Employees", resizable: false}    ],    defaults: {        sortable: true,        menuDisabled: true,        width: 100    },    listeners: {        widthchange: function(cm, colIndex, width) {            saveConfig(colIndex, width);        }    }}); </code></pre> * <p>In both examples above, the ability to apply a CSS class to all cells in a column (including the * header) is demonstrated through the use of the <b><tt>{@link Ext.grid.Column#id id}</tt></b> config * option. This column could be styled by including the following css:</p><pre><code> //add this css *after* the core css is loaded.x-grid3-td-company {    color: red; // entire column will have red font}// modify the header row only, adding an icon to the column header.x-grid3-hd-company {    background: transparent         url(../../resources/images/icons/silk/building.png)         no-repeat 3px 3px ! important;        padding-left:20px;} </code></pre> * Note that the "Company Name" column could be specified as the * <b><tt>{@link Ext.grid.GridPanel}.{@link Ext.grid.GridPanel#autoExpandColumn autoExpandColumn}</tt></b>. * @constructor * @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 changes.         * @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, {    /**     * @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     * <tt><b>{@link #defaults}</b></tt> config property.     */    defaultWidth: 100,    /**     * @cfg {Boolean} defaultSortable (optional) Default sortable of columns which have no     * sortable specified (defaults to <tt>false</tt>).  This property shall preferably be configured     * through the <tt><b>{@link #defaults}</b></tt> config property.     */    defaultSortable: false,    /**     * @cfg {Array} columns An Array of object literals.  The config options defined by     * <b>{@link Ext.grid.Column}</b> are the options which may appear in the object literal for each     * individual column definition.     */    /**     * @cfg {Object} defaults Object literal which will be used to apply {@link Ext.grid.Column}     * configuration options to all <tt><b>{@link #columns}</b></tt>.  Configuration options specified with     * individual {@link Ext.grid.Column column} configs will supersede these <tt><b>{@link #defaults}</b></tt>.     */    /**     * @cfg {String} xtype (optional) A String which references a predefined {@link Ext.grid.Column} subclass     * type which is preconfigured with an appropriate {@link Ext.grid.Column#renderer renderer} 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>     */    /**     * Returns the id of the column at the specified index.     * @param {Number} index The column index     * @return {String} the id     */    getColumnId : function(index){        return this.config[index].id;    },    getColumnAt : function(index){        return this.config[index];    },    /**     * <p>Reconfigures this column model according to the passed Array of column definition objects.      * For a description of the individual properties of a column definition object, see the      * <a href="#Ext.grid.ColumnModel-configs">Config Options</a>.</p>     * <p>Causes the {@link #configchange} event to be fired. A {@link Ext.grid.GridPanel GridPanel}      * using this ColumnModel will listen for this event and refresh its UI automatically.</p>     * @param {Array} config Array of Column definition objects.     * @param {Boolean} initial Specify <tt>true</tt> to bypass cleanup which deletes the <tt>totalWidth</tt>     * and destroys existing editors.     */    setConfig : function(config, initial){        if(!initial){ // cleanup            delete this.totalWidth;            for(var i = 0, len = this.config.length; i < len; i++){                var c = this.config[i];                if(c.editor){                    c.editor.destroy();                }            }        }        // backward compatibility        this.defaults = Ext.apply({            width: this.defaultWidth,            sortable: this.defaultSortable        }, this.defaults);        this.config = config;        this.lookup = {};        // if no id, create one        for(var i = 0, len = config.length; i < len; i++){            var c = Ext.applyIf(config[i], this.defaults);            if(!c.isColumn){                var cls = Ext.grid.Column.types[c.xtype || 'gridcolumn'];                c = new cls(c);                config[i] = c;            }            this.lookup[c.id] = c;        }        if(!initial){            this.fireEvent('configchange', this);        }    },    /**     * Returns the column for a specified id.     * @param {String} id The column id     * @return {Object} the column     */    getColumnById : function(id){        return this.lookup[id];    },    /**     * Returns the index for a specified column id.     * @param {String} id The column id     * @return {Number} the index, or -1 if not found     */    getIndexById : function(id){        for(var i = 0, len = this.config.length; i < len; i++){            if(this.config[i].id == id){                return i;            }        }        return -1;    },    /**     * Moves a column from one position to another.     * @param {Number} oldIndex The index of the column to move.     * @param {Number} newIndex The position at which to reinsert the coolumn.     */    moveColumn : function(oldIndex, newIndex){        var c = this.config[oldIndex];        this.config.splice(oldIndex, 1);        this.config.splice(newIndex, 0, c);        this.dataMap = null;        this.fireEvent("columnmoved", this, oldIndex, newIndex);    },    /**     * Returns the number of columns.     * @param {Boolean} visibleOnly Optional. Pass as true to only include visible columns.     * @return {Number}     */    getColumnCount : function(visibleOnly){        if(visibleOnly === true){            var c = 0;            for(var i = 0, len = this.config.length; i < len; i++){                if(!this.isHidden(i)){                    c++;                }            }            return c;        }        return this.config.length;    },    /**     * Returns the column configs that return true by the passed function that is called     * with (columnConfig, index)<pre><code>// returns an array of column config objects for all hidden columnsvar columns = grid.getColumnModel().getColumnsBy(function(c){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -