Upgrade to ExtJS 3.1.1 - Released 02/08/2010
[extjs.git] / src / widgets / grid / Column.js
index af23de2..d879792 100644 (file)
@@ -1,6 +1,6 @@
 /*!
- * Ext JS Library 3.1.0
- * 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
  */
@@ -219,7 +219,7 @@ var grid = new Ext.grid.GridPanel({
     \r
     constructor : function(config){\r
         Ext.apply(this, config);\r
-\r
+        \r
         if(Ext.isString(this.renderer)){\r
             this.renderer = Ext.util.Format[this.renderer];\r
         }else if(Ext.isObject(this.renderer)){\r
@@ -229,10 +229,10 @@ var grid = new Ext.grid.GridPanel({
         if(!this.scope){\r
             this.scope = this;\r
         }\r
-\r
-        if(this.editor){\r
-            this.editor = Ext.create(this.editor, 'textfield');\r
-        }\r
+        \r
+        var ed = this.editor;\r
+        delete this.editor;\r
+        this.setEditor(ed);\r
     },\r
 \r
     /**\r
@@ -264,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
@@ -272,18 +298,7 @@ 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