?? columnmodel.js
字號:
/*
* Ext JS Library 1.1 RC 1
* Copyright(c) 2006-2007, Ext JS, LLC.
* licensing@extjs.com
*
* http://www.extjs.com/license
*/
/**
* @class Ext.grid.ColumnModel
* @extends Ext.util.Observable
* This is the default implementation of a ColumnModel used by the Grid. It defines
* the columns in the grid.
* <br>Usage:<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>
* 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
*/
this.config = config;
this.lookup = {};
// if no id, create one
// if the column does not have a dataIndex mapping,
// map it to the order it is in the config
for(var i = 0, len = config.length; i < len; i++){
var c = config[i];
if(typeof c.dataIndex == "undefined"){
c.dataIndex = 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;
}
/**
* The width of columns which have no width specified (defaults to 100)
* @type Number
*/
this.defaultWidth = 100;
/**
* Default sortable of columns which have no sortable specified (defaults to false)
* @type Boolean
*/
this.defaultSortable = false;
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": true,
/**
* @event headerchange
* Fires when the text of a header changes.
* @param {ColumnModel} this
* @param {Number} columnIndex The column index
* @param {Number} newText The new header text
*/
"headerchange": true,
/**
* @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
* Fires when a column is moved.
* @param {ColumnModel} this
* @param {Number} oldIndex
* @param {Number} newIndex
*/
"columnmoved" : true,
/**
* @event columlockchange
* Fires when a column's locked state is changed
* @param {ColumnModel} this
* @param {Number} colIndex
* @param {Boolean} locked true if locked
*/
"columnlockchange" : true
});
Ext.grid.ColumnModel.superclass.constructor.call(this);
};
Ext.extend(Ext.grid.ColumnModel, Ext.util.Observable, {
/**
* @cfg {String} header The header text to display in the Grid view.
*/
/**
* @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 (Optional) The initial width in pixels of the column. Using this
* instead of {@link Ext.grid.Grid#autoSizeColumns} is more efficient.
*/
/**
* @cfg {Boolean} sortable (Optional) True if sorting is to be allowed on this column. Defaults to true.
* Whether local/remote sorting is used is specified in {@link Ext.data.Store#remoteSort}.
*/
/**
* @cfg {Boolean} locked (Optional) True to lock the column in place while scrolling the Grid.
* Defaults to false.
*/
/**
* @cfg {Boolean} resizable (Optional) False to disable column resizing. Defaults to true.
*/
/**
* @cfg {Boolean} hidden (Optional) True to hide the column. Defaults to false.
*/
/**
* @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 (Optional) Set the CSS text-align property of the column. Defaults to undefined.
*/
/**
* 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;
},
/**
* 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;
},
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);
},
isLocked : function(colIndex){
return this.config[colIndex].locked === true;
},
setLocked : function(colIndex, value, suppressEvent){
if(this.isLocked(colIndex) == value){
return;
}
this.config[colIndex].locked = value;
if(!suppressEvent){
this.fireEvent("columnlockchange", this, colIndex, value);
}
},
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;
},
getLockedCount : function(){
for(var i = 0, len = this.config.length; i < len; i++){
if(!this.isLocked(i)){
return i;
}
}
},
/**
* Returns the number of 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)
* @param {Function} fn
* @param {Object} scope (optional)
* @return {Array} result
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -