Upgrade to ExtJS 3.1.1 - Released 02/08/2010
[extjs.git] / docs / source / GroupingView.html
index fe1ba17..3915285 100644 (file)
@@ -192,11 +192,11 @@ var grid = new Ext.grid.GridPanel({
 \r
     // private\r
     onAdd : function(){\r
 \r
     // private\r
     onAdd : function(){\r
-        if(this.enableGrouping && !this.ignoreAdd){\r
+        if(this.canGroup() && !this.ignoreAdd){\r
             var ss = this.getScrollState();\r
             this.refresh();\r
             this.restoreScroll(ss);\r
             var ss = this.getScrollState();\r
             this.refresh();\r
             this.restoreScroll(ss);\r
-        }else if(!this.enableGrouping){\r
+        }else if(!this.canGroup()){\r
             Ext.grid.GroupingView.superclass.onAdd.apply(this, arguments);\r
         }\r
     },\r
             Ext.grid.GroupingView.superclass.onAdd.apply(this, arguments);\r
         }\r
     },\r
@@ -230,7 +230,7 @@ var grid = new Ext.grid.GridPanel({
         }\r
         if((item = items.get('showGroups'))){\r
             item.setDisabled(disabled);\r
         }\r
         if((item = items.get('showGroups'))){\r
             item.setDisabled(disabled);\r
-        item.setChecked(this.enableGrouping, true);\r
+            item.setChecked(this.enableGrouping, true);\r
         }\r
     },\r
 \r
         }\r
     },\r
 \r
@@ -251,7 +251,7 @@ var grid = new Ext.grid.GridPanel({
                 this.hmenu.add({\r
                     itemId:'showGroups',\r
                     text: this.showGroupsText,\r
                 this.hmenu.add({\r
                     itemId:'showGroups',\r
                     text: this.showGroupsText,\r
-            checked: true,\r
+                    checked: true,\r
                     checkHandler: this.onShowGroupsClick,\r
                     scope: this\r
                 });\r
                     checkHandler: this.onShowGroupsClick,\r
                     scope: this\r
                 });\r
@@ -279,10 +279,11 @@ var grid = new Ext.grid.GridPanel({
 \r
     // private\r
     onGroupByClick : function(){\r
 \r
     // private\r
     onGroupByClick : function(){\r
-    this.enableGrouping = true;\r
+        this.enableGrouping = true;\r
         this.grid.store.groupBy(this.cm.getDataIndex(this.hdCtxIndex));\r
         this.grid.store.groupBy(this.cm.getDataIndex(this.hdCtxIndex));\r
+        this.grid.fireEvent('groupchange', this, this.grid.store.getGroupState());\r
         this.beforeMenuShow(); // Make sure the checkboxes get properly set when changing groups\r
         this.beforeMenuShow(); // Make sure the checkboxes get properly set when changing groups\r
-    this.refresh();\r
+        this.refresh();\r
     },\r
 \r
     // private\r
     },\r
 \r
     // private\r
@@ -292,6 +293,7 @@ var grid = new Ext.grid.GridPanel({
             this.onGroupByClick();\r
         }else{\r
             this.grid.store.clearGrouping();\r
             this.onGroupByClick();\r
         }else{\r
             this.grid.store.clearGrouping();\r
+            this.grid.fireEvent('groupchange', this, null);\r
         }\r
     },\r
 \r
         }\r
     },\r
 \r
@@ -301,7 +303,7 @@ var grid = new Ext.grid.GridPanel({
      * @param {Boolean} expanded (optional)\r
      */\r
     toggleRowIndex : function(rowIndex, expanded){\r
      * @param {Boolean} expanded (optional)\r
      */\r
     toggleRowIndex : function(rowIndex, expanded){\r
-        if(!this.enableGrouping){\r
+        if(!this.canGroup()){\r
             return;\r
         }\r
         var row = this.getRow(rowIndex);\r
             return;\r
         }\r
         var row = this.getRow(rowIndex);\r
@@ -375,6 +377,9 @@ var grid = new Ext.grid.GridPanel({
 \r
     // private\r
     afterRender : function(){\r
 \r
     // private\r
     afterRender : function(){\r
+        if(!this.ds || !this.cm){\r
+            return;\r
+        }\r
         Ext.grid.GroupingView.superclass.afterRender.call(this);\r
         if(this.grid.deferRowRender){\r
             this.updateGroupWidths();\r
         Ext.grid.GroupingView.superclass.afterRender.call(this);\r
         if(this.grid.deferRowRender){\r
             this.updateGroupWidths();\r
@@ -413,17 +418,16 @@ var grid = new Ext.grid.GridPanel({
         if(rs.length < 1){\r
             return '';\r
         }\r
         if(rs.length < 1){\r
             return '';\r
         }\r
-        var groupField = this.getGroupField(),\r
-            colIndex = this.cm.findColumnIndex(groupField),\r
-            g;\r
-\r
-        this.enableGrouping = (this.enableGrouping === false) ? false : !!groupField;\r
 \r
 \r
-        if(!this.enableGrouping || this.isUpdating){\r
+        if(!this.canGroup() || this.isUpdating){\r
             return Ext.grid.GroupingView.superclass.doRender.apply(\r
                     this, arguments);\r
         }\r
             return Ext.grid.GroupingView.superclass.doRender.apply(\r
                     this, arguments);\r
         }\r
-        var gstyle = 'width:' + this.getTotalWidth() + ';',\r
+\r
+        var groupField = this.getGroupField(),\r
+            colIndex = this.cm.findColumnIndex(groupField),\r
+            g,\r
+            gstyle = 'width:' + this.getTotalWidth() + ';',\r
             cfg = this.cm.config[colIndex],\r
             groupRenderer = cfg.groupRenderer || cfg.renderer,\r
             prefix = this.showGroupName ? (cfg.groupName || cfg.header)+': ' : '',\r
             cfg = this.cm.config[colIndex],\r
             groupRenderer = cfg.groupRenderer || cfg.renderer,\r
             prefix = this.showGroupName ? (cfg.groupName || cfg.header)+': ' : '',\r
@@ -489,6 +493,11 @@ var grid = new Ext.grid.GridPanel({
         return this.getPrefix(field) + Ext.util.Format.htmlEncode(val);\r
     },\r
 \r
         return this.getPrefix(field) + Ext.util.Format.htmlEncode(val);\r
     },\r
 \r
+    // private\r
+    canGroup  : function(){\r
+        return this.enableGrouping && !!this.getGroupField();\r
+    },\r
+\r
     // private\r
     getPrefix: function(field){\r
         return this.grid.getGridEl().id + '-gp-' + field + '-';\r
     // private\r
     getPrefix: function(field){\r
         return this.grid.getGridEl().id + '-gp-' + field + '-';\r
@@ -506,7 +515,7 @@ var grid = new Ext.grid.GridPanel({
 \r
     // private\r
     getRows : function(){\r
 \r
     // private\r
     getRows : function(){\r
-        if(!this.enableGrouping){\r
+        if(!this.canGroup()){\r
             return Ext.grid.GroupingView.superclass.getRows.call(this);\r
         }\r
         var r = [];\r
             return Ext.grid.GroupingView.superclass.getRows.call(this);\r
         }\r
         var r = [];\r
@@ -522,7 +531,7 @@ var grid = new Ext.grid.GridPanel({
 \r
     // private\r
     updateGroupWidths : function(){\r
 \r
     // private\r
     updateGroupWidths : function(){\r
-        if(!this.enableGrouping || !this.hasRows()){\r
+        if(!this.canGroup() || !this.hasRows()){\r
             return;\r
         }\r
         var tw = Math.max(this.cm.getTotalWidth(), this.el.dom.offsetWidth-this.getScrollOffset()) +'px';\r
             return;\r
         }\r
         var tw = Math.max(this.cm.getTotalWidth(), this.el.dom.offsetWidth-this.getScrollOffset()) +'px';\r