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

📄 columnmodel.js

📁 EXT2.0的中文API源代码
💻 JS
📖 第 1 页 / 共 2 页
字号:
            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;
    },

    /**
     * 传入一个function类型的参数,对这个函数传入(columnConfig, index)的参数并调用,如返回true则加入到数组中并返回
     * @param {Function} fn
     * @param {Object} scope (可选的)
     * @return {Array} result
     */
    /**
     * Returns the column configs that return true by the passed function that is called with (columnConfig, index)
     * @param {Function} fn
     * @param {Object} scope (optional)
     * @return {Array} result
     */
    getColumnsBy : function(fn, scope){
        var r = [];
        for(var i = 0, len = this.config.length; i < len; i++){
            var c = this.config[i];
            if(fn.call(scope||this, c, i) === true){
                r[r.length] = c;
            }
        }
        return r;
    },

    /**
     * 返回指定的列可否排序
     * @param {Number} col 列索引
     * @return {Boolean}
     */
    /**
     * Returns true if the specified column is sortable.
     * @param {Number} col The column index
     * @return {Boolean}
     */
    isSortable : function(col){
        if(typeof this.config[col].sortable == "undefined"){
            return this.defaultSortable;
        }
        return this.config[col].sortable;
    },

    /**
     * 返回对某个列的渲染(格式化formatting)函数
     * @param {Number} col 列索引
     * @return {Function} 用于渲染单元格的那个函数。参阅 {@link #setRenderer}。
     */
    /**
     * Returns the rendering (formatting) function defined for the column.
     * @param {Number} col The column index.
     * @return {Function} The function used to render the cell. See {@link #setRenderer}.
     */
    getRenderer : function(col){
        if(!this.config[col].renderer){
            return Ext.grid.ColumnModel.defaultRenderer;
        }
        return this.config[col].renderer;
    },

    /**
     * 设置对某个列的渲染(格式化formatting)函数
     * @param {Number} col 列索引
     * @param {Function} fn 该函数用于加工单元格的原始数据,转换成为HTML并返回给GridView进一步处理。这个渲染函数调用时会有下列的参数:<ul>
     * <li>数据值。</li>
     * <li>单元格元数据(Cell metadata)。 你也可以设置这么一个对象,有下列的属性:<ul>
     * <li>css 单元格适用的CSS样式,类型字符串。</li>
     * <li>attr 一段HTML属性的字符串,应用于表格单元格的数据容器元素An HTML attribute definition string to apply to 
     * the data container element <i>within</i> the table cell.</li></ul>
     * <li>从数据中提取的{@link Ext.data.Record}。</li>
     * <li>行索引</li>
     * <li>列索引</li>
     * <li>The {@link Ext.data.Store}从Record中提取的对象。</li></ul>
     */
    /**
     * Sets the rendering (formatting) function for a column.
     * @param {Number} col The column index
     * @param {Function} fn The function to use to process the cell's raw data
     * to return HTML markup for the grid view. The render function is called with
     * the following parameters:<ul>
     * <li>Data value.</li>
     * <li>Cell metadata. An object in which you may set the following attributes:<ul>
     * <li>css A CSS class name to add to the cell's TD element.</li>
     * <li>attr An HTML attribute definition string to apply to the data container element <i>within</i> the table cell
     * (e.g. 'style="color:red;"').</li></ul>
     * <li>The {@link Ext.data.Record} from which the data was extracted.</li>
     * <li>Row index</li>
     * <li>Column index</li>
     * <li>The {@link Ext.data.Store} object from which the Record was extracted</li></ul>
     */
    setRenderer : function(col, fn){
        this.config[col].renderer = fn;
    },

    /**
     * 返回某个列的宽度
     * @param {Number} col 列索引
     * @return {Number}
     */
    /**
     * Returns the width for the specified column.
     * @param {Number} col The column index
     * @return {Number}
     */
    getColumnWidth : function(col){
        return this.config[col].width || this.defaultWidth;
    },

    /**
     * 设置某个列的宽度
     * @param {Number} col 列索引
     * @param {Number} width 新宽度
     */
    /**
     * Sets the width for a column.
     * @param {Number} col The column index
     * @param {Number} width The new width
     */
    setColumnWidth : function(col, width, suppressEvent){
        this.config[col].width = width;
        this.totalWidth = null;
        if(!suppressEvent){
             this.fireEvent("widthchange", this, col, width);
        }
    },

    /**
     * 返回所有列宽度之和
     * @param {Boolean} includeHidden True表示为包括隐藏的宽度
     * @return {Number}
     */
    /**
     * Returns the total width of all columns.
     * @param {Boolean} includeHidden True to include hidden column widths
     * @return {Number}
     */
    getTotalWidth : function(includeHidden){
        if(!this.totalWidth){
            this.totalWidth = 0;
            for(var i = 0, len = this.config.length; i < len; i++){
                if(includeHidden || !this.isHidden(i)){
                    this.totalWidth += this.getColumnWidth(i);
                }
            }
        }
        return this.totalWidth;
    },

    /**
     * 返回某个列的头部(header)
     * @param {Number} col 列索引
     * @return {String}
     */
    /**
     * Returns the header for the specified column.
     * @param {Number} col The column index
     * @return {String}
     */
    getColumnHeader : function(col){
        return this.config[col].header;
    },

    /**
     * 设置某个列的头部(header)
     * @param {Number} col 列索引
     * @param {String} header 新头部
     */
    /**
     * Sets the header for a column.
     * @param {Number} col The column index
     * @param {String} header The new header
     */
    setColumnHeader : function(col, header){
        this.config[col].header = header;
        this.fireEvent("headerchange", this, col, header);
    },

    /**
     * 返回某个列的工具提示(tooltip)
     * @param {Number} col 列索引
     * @return {String}
     */
    /**
     * Returns the tooltip for the specified column.
     * @param {Number} col The column index
     * @return {String}
     */
    getColumnTooltip : function(col){
            return this.config[col].tooltip;
    },
    /**
     * 设置某个列的工具提示(tooltip)
     * @param {Number} col 列索引
     * @param {String} tooltip 新tooltip
     */
    /**
     * Sets the tooltip for a column.
     * @param {Number} col The column index
     * @param {String} tooltip The new tooltip
     */
    setColumnTooltip : function(col, tooltip){
            this.config[col].tooltip = tooltip;
    },

    /**
     * 返回某个列的工具的dataindex
     * @param {Number} col 列索引
     * @return {Number}
     */
    /**
     * Returns the dataIndex for the specified column.
     * @param {Number} col The column index
     * @return {Number}
     */
    getDataIndex : function(col){
        return this.config[col].dataIndex;
    },

    /**
     * 设置某个列的工具的dataindex
     * @param {Number} col 列索引
     * @param {Number} dataIndex 新dataIndex
     */
    /**
     * Sets the dataIndex for a column.
     * @param {Number} col The column index
     * @param {Number} dataIndex The new dataIndex
     */
    setDataIndex : function(col, dataIndex){
        this.config[col].dataIndex = dataIndex;
    },

    findColumnIndex : function(dataIndex){
        var c = this.config;
        for(var i = 0, len = c.length; i < len; i++){
            if(c[i].dataIndex == dataIndex){
                return i;
            }
        }
        return -1;
    },

    /**
     * 返回单元格能否被编辑。
     * @param {Number} colIndex 列索引
     * @param {Number} rowIndex 行索引
     * @return {Boolean}
     */
    /**
     * Returns true if the cell is editable.
     * @param {Number} colIndex The column index
     * @param {Number} rowIndex The row index
     * @return {Boolean}
     */
    isCellEditable : function(colIndex, rowIndex){
        return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false;
    },

    /**
     * 返回单元格/列所定义的编辑器
     * @param {Number} colIndex 列索引
     * @param {Number} rowIndex 行索引
     * @return {Object}
     */
    /**
     * Returns the editor defined for the cell/column.
     * @param {Number} colIndex The column index
     * @param {Number} rowIndex The row index
     * @return {Object}
     */
    getCellEditor : function(colIndex, rowIndex){
        return this.config[colIndex].editor;
    },

    /**
     * 设置列是否可编辑的。
     * @param {Number} col 列索引
     * @param {Boolean} editable True表示为列是可编辑的
     */
    /**
     * Sets if a column is editable.
     * @param {Number} col The column index
     * @param {Boolean} editable True if the column is editable
     */
    setEditable : function(col, editable){
        this.config[col].editable = editable;
    },


    /**
     * 返回true如果列是隐藏的
     * @param {Number} colIndex 列索引
     * @return {Boolean}
     */
    /**
     * Returns true if the column is hidden.
     * @param {Number} colIndex The column index
     * @return {Boolean}
     */
    isHidden : function(colIndex){
        return this.config[colIndex].hidden;
    },


    /**
     * 返回true如果列是固定的
     */
    /**
     * Returns true if the column width cannot be changed
     */
    isFixed : function(colIndex){
        return this.config[colIndex].fixed;
    },

    /**
     * 返回true如果列不能被调整尺寸
     * @return {Boolean}
     */
    /**
     * Returns true if the column can be resized
     * @return {Boolean}
     */
    isResizable : function(colIndex){
        return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
    },
    /**
     * 设置列隐藏
     * @param {Number} colIndex 列索引
     */
    /**
     * Sets if a column is hidden.
     * @param {Number} colIndex The column index
     * @param {Boolean} hidden True if the column is hidden
     */
    setHidden : function(colIndex, hidden){
        var c = this.config[colIndex];
        if(c.hidden !== hidden){
            c.hidden = hidden;
            this.totalWidth = null;
            this.fireEvent("hiddenchange", this, colIndex, hidden);
        }
    },

    /**
     * 为列设置编辑器
     * @param {Number} col 列索引
     * @param {Object} editor 编辑器对象
     */
    /**
     * Sets the editor for a column.
     * @param {Number} col The column index
     * @param {Object} editor The editor object
     */
    setEditor : function(col, editor){
        this.config[col].editor = editor;
    }
});

// private
Ext.grid.ColumnModel.defaultRenderer = function(value){
	if(typeof value == "string" && value.length < 1){
	    return "&#160;";
	}
	return value;
};

// Alias for backwards compatibility
Ext.grid.DefaultColumnModel = Ext.grid.ColumnModel;

⌨️ 快捷键说明

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