2 Replies Latest reply on Sep 5, 2010 1:04 PM by real_ideveloper

    AdvancedDataGrid group by Date Problem

    real_ideveloper

      Hi all.

       

      I have a datasource with the date and a text, which i used in the grouping collection.

      The data is grouped by the year and month:

       

      YEAR

        |-->Month

             |-->day

             |-->day

        |-->Month

             |->day

       

      Now I have a strange problem when i refresh the GroupingCollection after i add new item, which has the same day name (not the day date!!!), but lies in another month.

      I show it better on an example

       

      2000

      |-->April

           |-->10, Mon

           |-->1, Sam

           |-->8, Sam

       

      After adding 2000-06-10 which has the same day name, the datasets with the same day name are interpreted like separte month.

       

      2000

      |-->April

           |-->10, Mon          => Here ist the problem (April-Data is split)

      |-->Mai

           |-->17, Mon          => Here is the Problem

      |-->April

           |-->1, Sam

           |-->8, Sam

       

      How could this problem be solved?

       

      Here is an sample code

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
      <mx:Script>
           <![CDATA[
                import mx.controls.Alert;
                import mx.collections.ArrayCollection;
                
                [Bindable]
                private var dataCollection:ArrayCollection = new ArrayCollection(
                [{"dataValue":new Date(2000,3,1),"myInfo":"info"}
                ,{"dataValue":new Date(2000,3,8),"myInfo":"info"}
                ,{"dataValue":new Date(2000,3,10),"myInfo":"info"}]);
                
                private var days:Array = new Array("Sonntag"
                                                   ,"Montag"
                                                   ,"Dienstag"
                                                   ,"Mittwoch"
                                                   ,"Donnerstag"
                                                   ,"Freitag"
                                                   ,"Samstag"
                                                   );
               private var monthArray:Array = new Array("Januar"
                                                   ,"Februar"
                                                   ,"März"
                                                   ,"April"
                                                   ,"Mai"
                                                   ,"Juni"
                                                   ,"Juli"
                                                   ,"August"
                                                   ,"September"
                                                   ,"Oktober"
                                                   ,"November"
                                                   ,"Dezember");
                
                
                private function yearGroup(item:Object, field:GroupingField):String
                {               
                     if(item.dataValue != null)
                     {
                          var groupingValue:String = item.dataValue.fullYear + "";
                          return groupingValue;
                     }
                     return "";
                }
                
                private function monthGroup(item:Object, field:GroupingField):String
                {
                     var groupingValue:String = getMonthString(item.dataValue.month);
                     return groupingValue;
                }
                
                private function getMonthString(mon:Number):String
                {
                     return monthArray[mon];
                }
                
                private function getDayDate(item:Object, column:AdvancedDataGridColumn):String
                {
                     var dayDate:String = (item.dataValue.date) + ", " + getDay(item.dataValue.getDay());
                     return dayDate;
                }
                
                private function getDay(day:Number):String
                {
                     return days[day];
                }
                
                private function addNewDateHandler():void
                {
                     dataCollection.addItem({"dataValue":new Date(2000,6,17),"myInfo":"info"});
                     
                     term.refresh();
                }
           ]]>
      </mx:Script>
      
      <mx:Button label="Add new date" click="addNewDateHandler()">
           
      </mx:Button>
      
      <mx:AdvancedDataGrid id="meineTermine"
                       width="100%" height="262" variableRowHeight="true" initialize="term.refresh();" y="30">
                       <mx:dataProvider>
                            <mx:GroupingCollection id="term" source="{dataCollection}" childrenField = "unused">
                              <mx:Grouping id="grp" >
                                  <mx:GroupingField name="dataValue" id="year" groupingFunction="yearGroup"/>
                                  <mx:GroupingField name="dataValue" id="month" groupingFunction="monthGroup"/>                            
                              </mx:Grouping>
                           </mx:GroupingCollection>
                       </mx:dataProvider>
                       
                       <mx:groupedColumns>
                           <mx:AdvancedDataGridColumn dataField="Dates" width="112" resizable="true" labelFunction="getDayDate"/>
                           <mx:AdvancedDataGridColumn dataField="myInfo" />
                       </mx:groupedColumns>
                  </mx:AdvancedDataGrid>                  
      </mx:Application>