Upgrade to ExtJS 3.1.1 - Released 02/08/2010
[extjs.git] / src / widgets / grid / Column.js
index 12d1bc5..d879792 100644 (file)
@@ -1,6 +1,6 @@
 /*!
- * Ext JS Library 3.0.3
- * Copyright(c) 2006-2009 Ext JS, LLC
+ * Ext JS Library 3.1.1
+ * Copyright(c) 2006-2010 Ext JS, LLC
  * licensing@extjs.com
  * http://www.extjs.com/license
  */
  * <p>While subclasses are provided to render data in different ways, this class renders a passed\r
  * data field unchanged and is usually used for textual columns.</p>\r
  */\r
-Ext.grid.Column = function(config){\r
-    Ext.apply(this, config);\r
-\r
-    if(Ext.isString(this.renderer)){\r
-        this.renderer = Ext.util.Format[this.renderer];\r
-    } else if(Ext.isObject(this.renderer)){\r
-        this.scope = this.renderer.scope;\r
-        this.renderer = this.renderer.fn;\r
-    }\r
-    this.renderer = this.renderer.createDelegate(this.scope || config);\r
-\r
-    if(this.editor){\r
-        this.editor = Ext.create(this.editor, 'textfield');\r
-    }\r
-};\r
-\r
-Ext.grid.Column.prototype = {\r
+Ext.grid.Column = Ext.extend(Object, {\r
     /**\r
      * @cfg {Boolean} editable Optional. Defaults to <tt>true</tt>, enabling the configured\r
      * <tt>{@link #editor}</tt>.  Set to <tt>false</tt> to initially disable editing on this column.\r
@@ -232,6 +216,24 @@ var grid = new Ext.grid.GridPanel({
      * Defaults to true.\r
      */\r
     isColumn : true,\r
+    \r
+    constructor : function(config){\r
+        Ext.apply(this, config);\r
+        \r
+        if(Ext.isString(this.renderer)){\r
+            this.renderer = Ext.util.Format[this.renderer];\r
+        }else if(Ext.isObject(this.renderer)){\r
+            this.scope = this.renderer.scope;\r
+            this.renderer = this.renderer.fn;\r
+        }\r
+        if(!this.scope){\r
+            this.scope = this;\r
+        }\r
+        \r
+        var ed = this.editor;\r
+        delete this.editor;\r
+        this.setEditor(ed);\r
+    },\r
 \r
     /**\r
      * Optional. A function which returns displayable data when passed the following parameters:\r
@@ -262,6 +264,32 @@ var grid = new Ext.grid.GridPanel({
     getEditor: function(rowIndex){\r
         return this.editable !== false ? this.editor : null;\r
     },\r
+    \r
+    /**\r
+     * Sets a new editor for this column.\r
+     * @param {Ext.Editor/Ext.form.Field} editor The editor to set\r
+     */\r
+    setEditor : function(editor){\r
+        if(this.editor){\r
+            this.editor.destroy();\r
+        }\r
+        this.editor = null;\r
+        if(editor){\r
+            //not an instance, create it\r
+            if(!editor.isXType){\r
+                editor = Ext.create(editor, 'textfield');\r
+            }\r
+            //check if it's wrapped in an editor\r
+            if(!editor.startEdit){\r
+                editor = new Ext.grid.GridEditor(editor);\r
+            }\r
+            this.editor = editor;\r
+        }\r
+    },\r
+    \r
+    destroy : function(){\r
+        this.setEditor(null);\r
+    },\r
 \r
     /**\r
      * Returns the {@link Ext.Editor editor} defined for this column that was created to wrap the {@link Ext.form.Field Field}\r
@@ -270,20 +298,9 @@ var grid = new Ext.grid.GridPanel({
      * @return {Ext.Editor}\r
      */\r
     getCellEditor: function(rowIndex){\r
-        var editor = this.getEditor(rowIndex);\r
-        if(editor){\r
-            if(!editor.startEdit){\r
-                if(!editor.gridEditor){\r
-                    editor.gridEditor = new Ext.grid.GridEditor(editor);\r
-                }\r
-                return editor.gridEditor;\r
-            }else if(editor.startEdit){\r
-                return editor;\r
-            }\r
-        }\r
-        return null;\r
+        return this.getEditor(rowIndex);\r
     }\r
-};\r
+});\r
 \r
 /**\r
  * @class Ext.grid.BooleanColumn\r
@@ -379,7 +396,7 @@ Ext.grid.TemplateColumn = Ext.extend(Ext.grid.Column, {
      */\r
     constructor: function(cfg){\r
         Ext.grid.TemplateColumn.superclass.constructor.call(this, cfg);\r
-        var tpl = Ext.isObject(this.tpl) ? this.tpl : new Ext.XTemplate(this.tpl);\r
+        var tpl = (!Ext.isPrimitive(this.tpl) && this.tpl.compile) ? this.tpl : new Ext.XTemplate(this.tpl);\r
         this.renderer = function(value, p, r){\r
             return tpl.apply(r.data);\r
         };\r