X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/c930e9176a5a85509c5b0230e2bff5c22a591432..92c2b89db26be16707f4a805d3303ab2531006e1:/docs/source/ColumnModel.html diff --git a/docs/source/ColumnModel.html b/docs/source/ColumnModel.html index 1f787ccb..823984ac 100644 --- a/docs/source/ColumnModel.html +++ b/docs/source/ColumnModel.html @@ -1,5 +1,6 @@
+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 * {@link Ext.grid.Column#dataIndex dataIndex}. If the @@ -89,66 +90,7 @@ * @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 is programmaticially changed using - *{@link #setColumnWidth}
.
- * Note internal resizing suppresses the event from firing. See also
- * {@link Ext.grid.GridPanel}.{@link #columnresize}
.
- * @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, {
+Ext.grid.ColumnModel = Ext.extend(Ext.util.Observable, {
/**
* @cfg {Number} defaultWidth (optional) The width of columns which have no {@link #width}
* specified (defaults to 100). This property shall preferably be configured through the
@@ -171,6 +113,66 @@ Ext.extend(Ext.grid.ColumnModel, Ext.util.Observable, {
* configuration options to all {@link #columns}. Configuration options specified with
* individual {@link Ext.grid.Column column} configs will supersede these {@link #defaults}.
*/
+
+ constructor : 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 is programmaticially changed using
+ * {@link #setColumnWidth}
.
+ * Note internal resizing suppresses the event from firing. See also
+ * {@link Ext.grid.GridPanel}.{@link #columnresize}
.
+ * @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);
+ },
/**
* Returns the id of the column at the specified index.
@@ -200,10 +202,7 @@ Ext.extend(Ext.grid.ColumnModel, Ext.util.Observable, {
if(!initial){ // cleanup
delete this.totalWidth;
for(i = 0, len = this.config.length; i < len; i++){
- c = this.config[i];
- if(c.editor){
- c.editor.destroy();
- }
+ this.config[i].destroy();
}
}
@@ -215,12 +214,16 @@ Ext.extend(Ext.grid.ColumnModel, Ext.util.Observable, {
this.config = config;
this.lookup = {};
- // if no id, create one
+
for(i = 0, len = config.length; i < len; i++){
c = Ext.applyIf(config[i], this.defaults);
+ // if no id, create one using column's ordinal position
+ if(Ext.isEmpty(c.id)){
+ c.id = i;
+ }
if(!c.isColumn){
- var cls = Ext.grid.Column.types[c.xtype || 'gridcolumn'];
- c = new cls(c);
+ var Cls = Ext.grid.Column.types[c.xtype || 'gridcolumn'];
+ c = new Cls(c);
config[i] = c;
}
this.lookup[c.id] = c;
@@ -293,8 +296,10 @@ var columns = grid.getColumnModel().getColumnsBy(function(c){
return c.hidden;
});
- * @param {Function} fn
- * @param {Object} scope (optional)
+ * @param {Function} fn A function which, when passed a {@link Ext.grid.Column Column} object, must
+ * return true
if the column is to be included in the returned Array.
+ * @param {Object} scope (optional) The scope (this
reference) in which the function
+ * is executed. Defaults to this ColumnModel.
* @return {Array} result
*/
getColumnsBy : function(fn, scope){
@@ -314,7 +319,7 @@ var columns = grid.getColumnModel().getColumnsBy(function(c){
* @return {Boolean}
*/
isSortable : function(col){
- return this.config[col].sortable;
+ return !!this.config[col].sortable;
},
/**
@@ -337,6 +342,10 @@ var columns = grid.getColumnModel().getColumnsBy(function(c){
}
return this.config[col].renderer;
},
+
+ getRendererScope : function(col){
+ return this.config[col].scope;
+ },
/**
* Sets the rendering (formatting) function for a column. See {@link Ext.util.Format} for some
@@ -498,7 +507,11 @@ var grid = new Ext.grid.GridPanel({
* @return {Boolean}
*/
isCellEditable : function(colIndex, rowIndex){
- return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false;
+ var c = this.config[colIndex],
+ ed = c.editable;
+
+ //force boolean
+ return !!(ed || (!Ext.isDefined(ed) && c.editor));
},
/**
@@ -521,22 +534,24 @@ var grid = new Ext.grid.GridPanel({
this.config[col].editable = editable;
},
-
/**
- * Returns true if the column is hidden.
+ * Returns true if the column is {@link Ext.grid.Column#hidden hidden}
,
+ * false otherwise.
* @param {Number} colIndex The column index
* @return {Boolean}
*/
isHidden : function(colIndex){
- return this.config[colIndex].hidden;
+ return !!this.config[colIndex].hidden; // ensure returns boolean
},
-
/**
- * Returns true if the column width cannot be changed
+ * Returns true if the column is {@link Ext.grid.Column#fixed fixed}
,
+ * false otherwise.
+ * @param {Number} colIndex The column index
+ * @return {Boolean}
*/
isFixed : function(colIndex){
- return this.config[colIndex].fixed;
+ return !!this.config[colIndex].fixed;
},
/**
@@ -569,16 +584,15 @@ myGrid.getColumnModel().setHidden(0, true); // hide column 0 (0 = the first colu
* @param {Object} editor The editor object
*/
setEditor : function(col, editor){
- Ext.destroy(this.config[col].editor);
- this.config[col].editor = editor;
+ this.config[col].setEditor(editor);
},
/**
* Destroys this column model by purging any event listeners, and removing any editors.
*/
destroy : function(){
- for(var i = 0, c = this.config, len = c.length; i < len; i++){
- Ext.destroy(c[i].editor);
+ for(var i = 0, len = this.config.length; i < len; i++){
+ this.config[i].destroy();
}
this.purgeListeners();
}