0 Replies Latest reply on Jan 18, 2010 2:39 AM by manfred2k3

    AdvancedDatagrid CaretIndex loss

    manfred2k3

      When the program dispatch the CollectionEventKind.RESET  to the collection, the caretIndex loss, but when i inform selectedItem or selectedIndex ,  the caretIndex thinks its in the first row.

       

      I´ve found one Issue on Jira, i think is the same problem:

       

      http://bugs.adobe.com/jira/browse/SDK-9697

       

      There is 2 SWF Files. The HierarquicalDataSolution works.And The Other Don´t.

       

      Below is the code from the HierarquicalDataProblem.swf :

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="startUp()" xmlns:local="*">
        <mx:Script>
        <![CDATA[
         import mx.events.CollectionEventKind;
         import mx.events.CollectionEvent;
               import mx.collections.ArrayCollection;
                   
               [Bindable]
          private var dpHierarchy:ArrayCollection = new ArrayCollection([
            {Region:"Southwest", categories: [
               {Region:"Arizona", categories: [
                  {Territory_Rep:"Barbara Jennings", Actual:38865, Estimate:40000},
                  {Territory_Rep:"Dana Binn", Actual:29885, Estimate:30000}]}, 
               {Region:"Central California", categories: [
                  {Territory_Rep:"Joe Smith", Actual:29134, Estimate:30000}]}, 
               {Region:"Nevada", categories: [
                  {Territory_Rep:"Bethany Pittman", Actual:52888, Estimate:45000}]}, 
               {Region:"Northern California", categories: [
                  {Territory_Rep:"Lauren Ipsum", Actual:38805, Estimate:40000},
                  {Territory_Rep:"T.R. Smith", Actual:55498, Estimate:40000}]}, 
               {Region:"Southern California", categories: [
                  {Territory_Rep:"Alice Treu", Actual:44985, Estimate:45000},
                  {Territory_Rep:"Jane Grove", Actual:44913, Estimate:45000}
               ]}      
            ]},     
            {Region:"Southwest", categories: [
               {Region:"Arizona", categories: [
                  {Territory_Rep:"Barbara Jennings", Actual:38865, Estimate:40000},
                  {Territory_Rep:"Dana Binn", Actual:29885, Estimate:30000}]}, 
               {Region:"Central California", categories: [
                  {Territory_Rep:"Joe Smith", Actual:29134, Estimate:30000}]}, 
               {Region:"Nevada", categories: [
                  {Territory_Rep:"Bethany Pittman", Actual:52888, Estimate:45000}]}, 
               {Region:"Northern California", categories: [
                  {Territory_Rep:"Lauren Ipsum", Actual:38805, Estimate:40000},
                  {Territory_Rep:"T.R. Smith", Actual:55498, Estimate:40000}]}, 
               {Region:"Southern California", categories: [
                  {Territory_Rep:"Alice Treu", Actual:44985, Estimate:45000},
                  {Territory_Rep:"Jane Grove", Actual:44913, Estimate:45000}
               ]}     
            ]},     
            {Region:"Southwest", categories: [
               {Region:"Arizona", categories: [
                  {Territory_Rep:"Barbara Jennings", Actual:38865, Estimate:40000},
                  {Territory_Rep:"Dana Binn", Actual:29885, Estimate:30000}]}, 
               {Region:"Central California", categories: [
                  {Territory_Rep:"Joe Smith", Actual:29134, Estimate:30000}]}, 
               {Region:"Nevada", categories: [
                  {Territory_Rep:"Bethany Pittman", Actual:52888, Estimate:45000}]}, 
               {Region:"Northern California", categories: [
                  {Territory_Rep:"Lauren Ipsum", Actual:38805, Estimate:40000},
                  {Territory_Rep:"T.R. Smith", Actual:55498, Estimate:40000}]}, 
               {Region:"Southern California", categories: [
                  {Territory_Rep:"Alice Treu", Actual:44985, Estimate:45000},
                  {Territory_Rep:"Jane Grove", Actual:44913, Estimate:45000}
               ]}     
            ]},     
            {Region:"Southwest", categories: [
               {Region:"Arizona", categories: [
                  {Territory_Rep:"Barbara Jennings", Actual:38865, Estimate:40000},
                  {Territory_Rep:"Dana Binn", Actual:29885, Estimate:30000}]}, 
               {Region:"Central California", categories: [
                  {Territory_Rep:"Joe Smith", Actual:29134, Estimate:30000}]}, 
               {Region:"Nevada", categories: [
                  {Territory_Rep:"Bethany Pittman", Actual:52888, Estimate:45000}]}, 
               {Region:"Northern California", categories: [
                  {Territory_Rep:"Lauren Ipsum", Actual:38805, Estimate:40000},
                  {Territory_Rep:"T.R. Smith", Actual:55498, Estimate:40000}]}, 
               {Region:"Southern California", categories: [
                  {Territory_Rep:"Alice Treu", Actual:44985, Estimate:45000},
                  {Territory_Rep:"Jane Grove", Actual:44913, Estimate:45000}
               ]}     
            ]},     
            {Region:"Southwest", categories: [
               {Region:"Arizona", categories: [
                  {Territory_Rep:"Barbara Jennings", Actual:38865, Estimate:40000},
                  {Territory_Rep:"Dana Binn", Actual:29885, Estimate:30000}]}, 
               {Region:"Central California", categories: [
                  {Territory_Rep:"Joe Smith", Actual:29134, Estimate:30000}]}, 
               {Region:"Nevada", categories: [
                  {Territory_Rep:"Bethany Pittman", Actual:52888, Estimate:45000}]}, 
               {Region:"Northern California", categories: [
                  {Territory_Rep:"Lauren Ipsum", Actual:38805, Estimate:40000},
                  {Territory_Rep:"T.R. Smith", Actual:55498, Estimate:40000}]}, 
               {Region:"Southern California", categories: [
                  {Territory_Rep:"Alice Treu", Actual:44985, Estimate:45000},
                  {Territory_Rep:"Jane Grove", Actual:44913, Estimate:45000}
               ]}     
            ]}
          ]);
         
          private function startUp():void{
           adg.setFocus();
           adg.selectedItem = dpHierarchy.getItemAt(0);
          }
       
          private function refresh():void{
           var event:CollectionEvent = new CollectionEvent(CollectionEvent.COLLECTION_CHANGE);
           event.kind = CollectionEventKind.RESET;
           hdata.dispatchEvent(event);
           adg.selectedItem = dpHierarchy.getItemAt(4);    
           adg.setFocus();
           dpHierarchy.refresh();    
          }
         
         
          ]]>
        </mx:Script>

          <mx:AdvancedDataGrid top="10" left="10" right="10"  bottom="50" id="adg">
              <mx:dataProvider>
                  <mx:HierarchicalData id="hdata" source="{dpHierarchy}"
                      childrenField="categories"/>
              </mx:dataProvider>
              <mx:columns>
                  <mx:AdvancedDataGridColumn dataField="Region"/>
                  <mx:AdvancedDataGridColumn dataField="Territory_Rep"
                      headerText="Territory Rep"/>
                  <mx:AdvancedDataGridColumn dataField="Actual"/>
                  <mx:AdvancedDataGridColumn dataField="Estimate"/>
              </mx:columns>
          </mx:AdvancedDataGrid>
         
          <mx:Button bottom="5" right="10" height="30" click="refresh()" />
      </mx:Application>

       

      Below is the code from the HierarquicalDataSolution.swf (2 Files) :

       

      adgTeste.as

       

      package
      {
      import mx.collections.ICollectionView;
      import mx.collections.IViewCursor;
      import mx.controls.AdvancedDataGrid;
      import mx.controls.listClasses.IListItemRenderer;
      import mx.events.AdvancedDataGridEvent;
      import mx.events.ListEvent;
      import flash.events.KeyboardEvent;
      import flash.display.DisplayObject;

      public class AdgTeste extends AdvancedDataGrid
      {
        public function AdgTeste()
        {
         super();
        }
       
        override protected function treeNavigationHandler(event:KeyboardEvent):Boolean
           {
               if ((caretIndex == -1)&&(selectedIndex != -1))
                caretIndex = selectedIndex;
              
               return super.treeNavigationHandler(event);
              
              
           }
        
      }
      }

       

      HierarquicalDataTeste.mxml

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="startUp()" xmlns:local="*">
        <mx:Script>
        <![CDATA[
         import mx.events.CollectionEventKind;
         import mx.events.CollectionEvent;
               import mx.collections.ArrayCollection;
                   
               [Bindable]
          private var dpHierarchy:ArrayCollection = new ArrayCollection([
            {Region:"Southwest", categories: [
               {Region:"Arizona", categories: [
                  {Territory_Rep:"Barbara Jennings", Actual:38865, Estimate:40000},
                  {Territory_Rep:"Dana Binn", Actual:29885, Estimate:30000}]}, 
               {Region:"Central California", categories: [
                  {Territory_Rep:"Joe Smith", Actual:29134, Estimate:30000}]}, 
               {Region:"Nevada", categories: [
                  {Territory_Rep:"Bethany Pittman", Actual:52888, Estimate:45000}]}, 
               {Region:"Northern California", categories: [
                  {Territory_Rep:"Lauren Ipsum", Actual:38805, Estimate:40000},
                  {Territory_Rep:"T.R. Smith", Actual:55498, Estimate:40000}]}, 
               {Region:"Southern California", categories: [
                  {Territory_Rep:"Alice Treu", Actual:44985, Estimate:45000},
                  {Territory_Rep:"Jane Grove", Actual:44913, Estimate:45000}
               ]}      
            ]},     
            {Region:"Southwest", categories: [
               {Region:"Arizona", categories: [
                  {Territory_Rep:"Barbara Jennings", Actual:38865, Estimate:40000},
                  {Territory_Rep:"Dana Binn", Actual:29885, Estimate:30000}]}, 
               {Region:"Central California", categories: [
                  {Territory_Rep:"Joe Smith", Actual:29134, Estimate:30000}]}, 
               {Region:"Nevada", categories: [
                  {Territory_Rep:"Bethany Pittman", Actual:52888, Estimate:45000}]}, 
               {Region:"Northern California", categories: [
                  {Territory_Rep:"Lauren Ipsum", Actual:38805, Estimate:40000},
                  {Territory_Rep:"T.R. Smith", Actual:55498, Estimate:40000}]}, 
               {Region:"Southern California", categories: [
                  {Territory_Rep:"Alice Treu", Actual:44985, Estimate:45000},
                  {Territory_Rep:"Jane Grove", Actual:44913, Estimate:45000}
               ]}     
            ]},     
            {Region:"Southwest", categories: [
               {Region:"Arizona", categories: [
                  {Territory_Rep:"Barbara Jennings", Actual:38865, Estimate:40000},
                  {Territory_Rep:"Dana Binn", Actual:29885, Estimate:30000}]}, 
               {Region:"Central California", categories: [
                  {Territory_Rep:"Joe Smith", Actual:29134, Estimate:30000}]}, 
               {Region:"Nevada", categories: [
                  {Territory_Rep:"Bethany Pittman", Actual:52888, Estimate:45000}]}, 
               {Region:"Northern California", categories: [
                  {Territory_Rep:"Lauren Ipsum", Actual:38805, Estimate:40000},
                  {Territory_Rep:"T.R. Smith", Actual:55498, Estimate:40000}]}, 
               {Region:"Southern California", categories: [
                  {Territory_Rep:"Alice Treu", Actual:44985, Estimate:45000},
                  {Territory_Rep:"Jane Grove", Actual:44913, Estimate:45000}
               ]}     
            ]},     
            {Region:"Southwest", categories: [
               {Region:"Arizona", categories: [
                  {Territory_Rep:"Barbara Jennings", Actual:38865, Estimate:40000},
                  {Territory_Rep:"Dana Binn", Actual:29885, Estimate:30000}]}, 
               {Region:"Central California", categories: [
                  {Territory_Rep:"Joe Smith", Actual:29134, Estimate:30000}]}, 
               {Region:"Nevada", categories: [
                  {Territory_Rep:"Bethany Pittman", Actual:52888, Estimate:45000}]}, 
               {Region:"Northern California", categories: [
                  {Territory_Rep:"Lauren Ipsum", Actual:38805, Estimate:40000},
                  {Territory_Rep:"T.R. Smith", Actual:55498, Estimate:40000}]}, 
               {Region:"Southern California", categories: [
                  {Territory_Rep:"Alice Treu", Actual:44985, Estimate:45000},
                  {Territory_Rep:"Jane Grove", Actual:44913, Estimate:45000}
               ]}     
            ]},     
            {Region:"Southwest", categories: [
               {Region:"Arizona", categories: [
                  {Territory_Rep:"Barbara Jennings", Actual:38865, Estimate:40000},
                  {Territory_Rep:"Dana Binn", Actual:29885, Estimate:30000}]}, 
               {Region:"Central California", categories: [
                  {Territory_Rep:"Joe Smith", Actual:29134, Estimate:30000}]}, 
               {Region:"Nevada", categories: [
                  {Territory_Rep:"Bethany Pittman", Actual:52888, Estimate:45000}]}, 
               {Region:"Northern California", categories: [
                  {Territory_Rep:"Lauren Ipsum", Actual:38805, Estimate:40000},
                  {Territory_Rep:"T.R. Smith", Actual:55498, Estimate:40000}]}, 
               {Region:"Southern California", categories: [
                  {Territory_Rep:"Alice Treu", Actual:44985, Estimate:45000},
                  {Territory_Rep:"Jane Grove", Actual:44913, Estimate:45000}
               ]}     
            ]}
          ]);
         
          private function startUp():void{
           adg.setFocus();
           adg.selectedItem = dpHierarchy.getItemAt(0);
          }
       
          private function refresh():void{
           var event:CollectionEvent = new CollectionEvent(CollectionEvent.COLLECTION_CHANGE);
           event.kind = CollectionEventKind.RESET;
           hdata.dispatchEvent(event);
           adg.selectedItem = dpHierarchy.getItemAt(4);    
           adg.setFocus();
           dpHierarchy.refresh();
          
          }
         
         
          ]]>
        </mx:Script>

          <local:AdgTeste top="10" left="10" right="10"  bottom="50" id="adg">
              <local:dataProvider>
                  <mx:HierarchicalData id="hdata" source="{dpHierarchy}"
                      childrenField="categories"/>
              </local:dataProvider>
              <local:columns>
                  <mx:AdvancedDataGridColumn dataField="Region"/>
                  <mx:AdvancedDataGridColumn dataField="Territory_Rep"
                      headerText="Territory Rep"/>
                  <mx:AdvancedDataGridColumn dataField="Actual"/>
                  <mx:AdvancedDataGridColumn dataField="Estimate"/>
              </local:columns>
          </local:AdgTeste>
         
          <mx:Button bottom="5" right="10" height="30" click="refresh()" />
      </mx:Application>

      Simulation: Click the button on the bottom, and press the up key on the keyboard. Nothing happens.

       

      Many thanks in Advance.