3 Replies Latest reply on Jan 21, 2010 10:28 AM by Shongrunden

    Using DataGroup & custom itemRenderer w/ alternatingItemColors property

    Paul The Lad Level 1

      With an out-of-box renderer, the alternatingItemColors works just fine:
          <s:DataGroup
              alternatingItemColors="[red,blue]"
              itemRenderer="spark.skins.spark.DefaultItemRenderer">
              <s:layout>
                  <s:VerticalLayout />
              </s:layout>
              <s:ArrayCollection>
                  <fx:String>primitive data 1</fx:String>
                  <fx:String>primitive data 2</fx:String>
                  <fx:String>primitive data 3</fx:String>
          </s:DataGroup >

       

      But with any custom itemRenderer, it is as if the property is not inherited and doesn't take effect. Why is that?

        • 1. Re: Using DataGroup & custom itemRenderer w/ alternatingItemColors property
          Paul The Lad Level 1

          After taking a look at the implementation for park.skins.spark.DefaultItemRenderer I realized that I can NOT just have the following:

           

          <s:ItemRenderer ...>

              <s:HGroup>

                <s:Label text="blah1"/>

                <s:Label text="blah2"/>

                <s:Label text="blah3"/>
              </s:HGroup>

          </s:ItemRenderer>

           

          I definitely need the <s:Rect ../> tag in there too. I was incorrect to assume that a default rectangle comes from the implemetation of spark.components.supportClasses.ItemRenderer itself. That is NOT the case, it has to be explicitly defined. So anyone who faces somethign similar can rip out the <s:Rect ../> tag as written in DefaultItemRenderer and paste it into their own custom ItemRenderer to quickly move forward.

           

          <s:ItemRenderer ...>

              <!-- copy/paste or write your own -->

              <s:Rect .../>

              <s:HGroup .../>

          </s:ItemRenderer>

          • 2. Re: Using DataGroup & custom itemRenderer w/ alternatingItemColors property
            Flex harUI Adobe Employee

            In Spark, all of the visuals are owned by the renderer so you have full

            control (and full responsibility as well).  In mx, the List class drew a

            bunch of things like row backgrounds which made some things simpler but you

            lost full control

            1 person found this helpful
            • 3. Re: Using DataGroup & custom itemRenderer w/ alternatingItemColors property
              Shongrunden Adobe Employee

              This seems to work for me, does this show the alternatingItemColors for you too:

               

                  <s:DataGroup
                      alternatingItemColors="[red,blue]">
                      <s:layout>
                          <s:VerticalLayout />
                      </s:layout>
                      <s:ArrayCollection>
                          <fx:String>primitive data 1</fx:String>
                          <fx:String>primitive data 2</fx:String>
                          <fx:String>primitive data 3</fx:String>
                      </s:ArrayCollection>
                      <s:itemRenderer>
                          <fx:Component>
                              <s:ItemRenderer>
                                  <s:HGroup>
                                      <s:Label text="blah" />
                                      <s:Label text="blah" />
                                      <s:Label text="blah" />
                                  </s:HGroup>
                              </s:ItemRenderer>
                          </fx:Component>
                      </s:itemRenderer>
                  </s:DataGroup>