3 Replies Latest reply on Feb 22, 2011 11:05 PM by flexiblekrish

    Want to access the current index of DataGroup component in the neasted datagroup

    flexiblekrish Level 1

      Hi

       

             I have 2 dimensional Arraycollection which contains the persons details. i want to display those by using Datagroup component. because it is a 2 dimentional i have to use nestead datagroup. but am not able to acces currentIndex (like repeater we can able to access). Please help me how can i access

      currentindex.

       

      sample code :

       

      <?xml version="1.0"?>

      <!-- repeater\RefNestedComponents.mxml -->

      <s:Application

      xmlns:fx="http://ns.adobe.com/mxml/2009"  

      xmlns:mx="library://ns.adobe.com/flex/mx"   

      xmlns:s="library://ns.adobe.com/flex/spark" xmlns:local="*" creationComplete="testd()">

      <fx:Script>

      <![CDATA[

      import mx.collections.ArrayCollection;

      import mx.collections.ArrayList;

      import mx.collections.IList;

       

      [Bindable]

      public var tests:ArrayCollection;

       

      public function testd():void{

      tests  = new ArrayCollection([

      {name:new ArrayCollection([{name:"Wilma Carter", Bats:"R", Throws:"R", Year:"So", Home: "Redlands, CA"}])},

      {name:new ArrayCollection([{name:"Sue Pennypacker", Bats:"L", Throws:"R", Year:"Fr", Home: "Athens, GA"}])},

      {name:new ArrayCollection([{name:"Jill Smithfield", Bats:"R", Throws:"L", Year:"Sr", Home: "Spokane, WA"}])},

      {name:new ArrayCollection([{name:"Shirley Goth", Bats:"R", Throws:"R", Year:"Sr", Home: "Carson, NV"}])},

      {name:new ArrayCollection([{name:"Jennifer Dunbar", Bats:"R", Throws:"R", Year:"Fr", Home: "Seaside, CA"}])},

      ]);

      }

       

      public function change(e:Event):void{

      tests[1].name ="tested";

      tests.refresh();

      }

      ]]>

      </fx:Script>

       

      <s:layout>

      <s:VerticalLayout/>

      </s:layout>

       

      <s:DataGroup id="datagroup" dataProvider="{tests}" >

      <s:layout>

      <s:VerticalLayout/>

      </s:layout>

      <s:itemRenderer>

      <fx:Component >

        <!-- <s:DataGroup dataProvider="{outerDocument.tests[1].name}">-->

      <s:DataGroup dataProvider="{outerDocument.tests[INDEX].name}">

      <s:itemRenderer>

      <fx:Component>

      <mx:Text text="{data.name}"/>

      </fx:Component>

      </s:itemRenderer>

      </s:DataGroup>

      </fx:Component>

      </s:itemRenderer>

       

      </s:DataGroup>

       

      <s:Button click="change(event)"  label="click to change"/>

      </s:Application>

       

       

      in the above code :

       

        <!-- <s:DataGroup dataProvider="{outerDocument.tests[1].name}">-->

      <s:DataGroup dataProvider="{outerDocument.tests[INDEX].name}">

       

       

      i want to get INDEX value ..

       

      please help me out .. thanks

        • 2. Re: Want to access the current index of DataGroup component in the neasted datagroup
          Shongrunden Adobe Employee

          In spark the ItemRenderer class should be the root tag inside your fx:Component tags.  That class has an itemIndex property built into it.

           

          Here is your code tweaked to show the itemIndex within the nested DataGroup and the outer DataGroup:

           

          <?xml version="1.0"?>

          <!-- repeater\RefNestedComponents.mxml -->

          <s:Application

              xmlns:fx="http://ns.adobe.com/mxml/2009

              xmlns:mx="library://ns.adobe.com/flex/mx"  

              xmlns:s="library://ns.adobe.com/flex/spark" xmlns:local="*" creationComplete="testd()">

              <fx:Script>

                  <![CDATA[

                      import mx.collections.ArrayCollection;

                      import mx.collections.ArrayList;

                      import mx.collections.IList;

           

                      [Bindable]

                      public var tests:ArrayCollection;

           

                      public function testd():void{

                          tests  = new ArrayCollection([

                              {name:new ArrayCollection([{name:"Wilma Carter", Bats:"R", Throws:"R", Year:"So", Home: "Redlands, CA"}])},

                              {name:new ArrayCollection([{name:"Sue Pennypacker", Bats:"L", Throws:"R", Year:"Fr", Home: "Athens, GA"}])},

                              {name:new ArrayCollection([{name:"Jill Smithfield", Bats:"R", Throws:"L", Year:"Sr", Home: "Spokane, WA"}])},

                              {name:new ArrayCollection([{name:"Shirley Goth", Bats:"R", Throws:"R", Year:"Sr", Home: "Carson, NV"}])},

                              {name:new ArrayCollection([{name:"Jennifer Dunbar", Bats:"R", Throws:"R", Year:"Fr", Home: "Seaside, CA"}])},

                          ]);

                      }

           

                      public function change(e:Event):void{

                          tests[1].name ="tested";

                          tests.refresh();

                      }

                  ]]>

              </fx:Script>

           

              <s:layout>

                  <s:VerticalLayout/>

              </s:layout>

           

              <s:DataGroup id="datagroup" dataProvider="{tests}" >

                  <s:layout>

                      <s:VerticalLayout/>

                  </s:layout>

                  <s:itemRenderer>

                      <fx:Component>

                          <s:ItemRenderer>

                              <s:DataGroup dataProvider="{outerDocument.tests[1].name}">

                                  <s:itemRenderer>

                                      <fx:Component>

                                          <s:ItemRenderer>

                                              <mx:Text text="{data.name}, {itemIndex}, {outerDocument.itemIndex}"/>

                                          </s:ItemRenderer>

                                      </fx:Component>

                                  </s:itemRenderer>

                              </s:DataGroup>

                          </s:ItemRenderer>

                      </fx:Component>

                  </s:itemRenderer>

           

              </s:DataGroup>

           

              <s:Button click="change(event)"  label="click to change"/>

           

          </s:Application>

          • 3. Re: Want to access the current index of DataGroup component in the neasted datagroup
            flexiblekrish Level 1

            Really you helpd me a lot ...thank you so much... am able to access.