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

📄 columnmodel.js

📁 EXT2.0的中文API源代码
💻 JS
📖 第 1 页 / 共 2 页
字号:
/**
 * @class Ext.grid.ColumnModel
 * @extends Ext.util.Observable
 * 该实现(implementation)用于Grid的列模型(ColumnModel)。用于定义Grid里面的每一列的状态。
 * <br>用法:<br>
 <pre><code>
 var colModel = new Ext.grid.ColumnModel([
	{header: "Ticker", width: 60, sortable: true, locked: true}, 
	{header: "Company Name", width: 150, sortable: true}, 
	{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>
 * 该类列出的配置选项也适用于各个列的定义(column definition)。
 * @constructor
 * @param {Object} config An Array of column config objects列配置组成的数组,参阅关于本类的配置对象的更多资料。
*/
/**
 * @class Ext.grid.ColumnModel
 * @extends Ext.util.Observable
 * This is the default implementation of a ColumnModel used by the Grid. This class is initialized
 * with an Array of column config objects.
 * <br><br>
 * An individual column's config object defines the header string, the {@link Ext.data.Record}
 * field the column draws its data from, an otional rendering function to provide customized
 * data formatting, and the ability to apply a CSS class to all cells in a column through its
 * {@link #id} config option.<br>
 * <br>Usage:<br>
 <pre><code>
 var colModel = new Ext.grid.ColumnModel([
	{header: "Ticker", width: 60, sortable: true},
	{header: "Company Name", width: 150, sortable: true},
	{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 config options listed for this class are options which may appear in each
 * individual column definition.
 * @constructor
 * @param {Object} config An Array of column config objects. See this class's
 * config objects for details.
*/
Ext.grid.ColumnModel = function(config){
	/**
     * The config passed into the constructor
     * @property {Array} config
     */
     this.setConfig(config, true);
    /**
     * 列宽度的默认值(默认为100)
     * @type Number
     */
    /**
     * The width of columns which have no width specified (defaults to 100)
     * @type Number
     */
    this.defaultWidth = 100;

    /**
     * 是否默认排序(默认为false)
     * @type Boolean
     */
    /**
     * Default sortable of columns which have no sortable specified (defaults to false)
     * @type Boolean
     */
    this.defaultSortable = false;

    this.addEvents({
        /**
	     * @event widthchange
	     * 当列的宽度改变时触发
	     * @param {ColumnModel} this
	     * @param {Number} columnIndex 列索引
	     * @param {Number} newWidth 新宽度
	     */
        /**
	     * @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": true,
        /**
	     * @event headerchange
	     * 当头部文字改变时触发
	     * @param {ColumnModel} this
	     * @param {Number} columnIndex 列索引
	     * @param {Number} newText 新头部文字
	     */
        /**
	     * @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": true,
        /**
	     * @event hiddenchange
	     * 当列隐藏或“反隐藏”时触发
	     * @param {ColumnModel} this
	     * @param {Number} columnIndex 列索引
	     * @param {Number} hidden true:隐藏,false:“反隐藏”
	     */
        /**
	     * @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": true,
	    /**
         * @event columnmoved
         * 当列被移动时触发
         * @param {ColumnModel} this
         * @param {Number} oldIndex
         * @param {Number} newIndex
         */
	    /**
         * @event columnmoved
         * Fires when a column is moved.
         * @param {ColumnModel} this
         * @param {Number} oldIndex
         * @param {Number} newIndex
         */
        "columnmoved" : true,
        /**
         * @event columlockchange
         * 当列锁定状态被改变时触发
         * @param {ColumnModel} this
         * @param {Number} colIndex
         * @param {Boolean} locked true:已锁定的
         */
        /**
         * @event columnlockchange
         * Fires when a column's locked state is changed
         * @param {ColumnModel} this
         * @param {Number} colIndex
         * @param {Boolean} locked true if locked
         */
        "columnlockchange" : true,
        /**
         * @event configchanged
         * Fires when the configuration is changed
         * @param {ColumnModel} this
         */
        "configchange" : true
    });
    Ext.grid.ColumnModel.superclass.constructor.call(this);
};
Ext.extend(Ext.grid.ColumnModel, Ext.util.Observable, {
    /**
     * @cfg {String} id (Optional) Defaults to the column's initial ordinal position.
     * A name which identifies this column. The id is used to create a CSS class name which
     * is applied to all table cells (including headers) in that column. The class name
     * takes the form of <pre>x-grid-td-<b>id<b></pre>
     * <br><br>
     * Header cells will also recieve this class name, but will also have the class x-grid-hd,
     * so to target header cells, use CSS selectors such as:<pre>.x-grid-hd.x-grid-td-<b>id</b></pre>
     * The {@link Ext.grid.Grid#autoExpandColumn} grid config option references the column
     * via this identifier.
     */
    /**
     * @cfg {String} header 在Grid头部视图中显示的文字。
     */
    /**
     * @cfg {String} header The header text to display in the Grid view.
     */
    /**
     * @cfg {String} dataIndex (可选的)  数据索引,相当于Grid记录集({@link Ext.data.Store}里面的
     * {@link Ext.data.Record} )中字段名称,字段的值用于展示列里面的值(column's value)。
     * 如不指定,Record的数据列中的索引将作为列的索引。
     */
    /**
     * @cfg {String} dataIndex (Optional) 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. If not
     * specified, the column's index is used as an index into the Record's data Array.
     */
    /**
     * @cfg {Number} width (可选的) 列的初始宽度(像素)。如采用{@link Ext.grid.Grid#autoSizeColumns} 性能较差。
     */
    /**
     * @cfg {Number} width (Optional) The initial width in pixels of the column. Using this
     * instead of {@link Ext.grid.Grid#autoSizeColumns} is more efficient.
     */
    /**
     * @cfg {Boolean} sortable (可选的) True表示为可在该列上进行排列。默认为true
     * 由{@link Ext.data.Store#remoteSort}指定本地排序抑或是远程排序。
     */
    /**
     * @cfg {Boolean} sortable (Optional) True if sorting is to be allowed on this column.
     * Defaults to the value of the {@link #defaultSortable} property.
     * Whether local/remote sorting is used is specified in {@link Ext.data.Store#remoteSort}.
     */
    /**
     * @cfg {Boolean} locked (可选的) True表示当滚动grid时,锁定列在某个位置。默认为false。
     */
    /**
     * @cfg {Boolean} locked (Optional) True to lock the column in place while scrolling the Grid.  Defaults to false.
     */
    /**
     * @cfg {Boolean} fixed (可选的) True表示宽度不能改变。默认为false。.
     */
    /**
     * @cfg {Boolean} fixed (Optional) True if the column width cannot be changed.  Defaults to false.
     */
    /**
     * @cfg {Boolean} resizable (可选的) False禁止列可变动大小。默认为true。
     */
    /**
     * @cfg {Boolean} resizable (Optional) False to disable column resizing. Defaults to true.
     */
    /**
     * @cfg {Boolean} hidden (可选的) True表示隐藏列,默认为false
     */
    /**
     * @cfg {Boolean} hidden (Optional) True to hide the column. Defaults to false.
     */
    /**
     * @cfg {Function} renderer (可选的) 该函数用于加工单元格的原始数据,转换成为HTML并返回给GridView进一步处理。 参阅{@link #setRenderer}。 
     * 如不指定,则对原始数据值进行默认地渲染。
     */
    /**
     * @cfg {Function} renderer (Optional) A function used to generate HTML markup for a cell
     * given the cell's data value. See {@link #setRenderer}. If not specified, the
     * default renderer uses the raw data value.
     */
    /**
     * @cfg {String} align (可选的) 设置列的CSS text-align 属性。默认为undefined。
     */
    /**
     * @cfg {String} align (Optional) Set the CSS text-align property of the column.  Defaults to undefined.
     */

    /**
     * 返回指定index的列Id
     * @param {Number} index
     * @return {String} the id
     */
    /**
     * 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;
    },

    /**
     * Reconfigures this column model
     * @param {Array} config Array of Column configs
     */
    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();
                }
            }
        }
        this.config = config;
        this.lookup = {};
        // if no id, create one
        for(var i = 0, len = config.length; i < len; i++){
            var c = config[i];
            if(typeof c.renderer == "string"){
                c.renderer = Ext.util.Format[c.renderer];
            }
            if(typeof c.id == "undefined"){
                c.id = i;
            }
            if(c.editor && c.editor.isFormField){
                c.editor = new Ext.grid.GridEditor(c.editor);
            }
            this.lookup[c.id] = c;
        }
        if(!initial){
            this.fireEvent('configchange', this);
        }
    },

    /**
     * 返回指定id的列
     * @param {String} id 列id
     * @return {Object} 列
     */
    /**
     * Returns the column for a specified id.
     * @param {String} id The column id
     * @return {Object} the column
     */
    getColumnById : function(id){
        return this.lookup[id];
    },

    /**
     * 返回指定列id的索引
     * @param {String} id 列id
     * @return {Number} 索引,-1表示找不到
     */
    /**
     * 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;
    },

    // private
    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);
    },

    // no longer supported!
    isLocked : function(colIndex){
        return this.config[colIndex].locked === true;
    },

    // private
    setLocked : function(colIndex, value, suppressEvent){
        if(this.isLocked(colIndex) == value){
            return;
        }
        this.config[colIndex].locked = value;
        if(!suppressEvent){
            this.fireEvent("columnlockchange", this, colIndex, value);
        }
    },

    // private
    getTotalLockedWidth : function(){
        var totalWidth = 0;
        for(var i = 0; i < this.config.length; i++){
            if(this.isLocked(i) && !this.isHidden(i)){
                this.totalWidth += this.getColumnWidth(i);
            }
        }
        return totalWidth;
    },

    // private
    getLockedCount : function(){
        for(var i = 0, len = this.config.length; i < len; i++){
            if(!this.isLocked(i)){
                return i;
            }
        }
    },

    /**
     * 返回列数
     * @return {Number}
     */
    /**
     * Returns the number of columns.
     * @return {Number}
     */
    getColumnCount : function(visibleOnly){
        if(visibleOnly === true){

⌨️ 快捷键说明

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