3 Replies Latest reply on May 28, 2011 12:27 PM by Shongrunden

    alternatingItemColors not working in custom itemRenderer

    BennyB23

      I'm trying to set the alternatingItemColors for a custom <s:MXDataGridItemRenderer /> and nothing seems to work. I've tried every combination of setting the property that I can think of, from the application, to the dataGrid, to the renderer, with every combination of autoDrawBackground set to true or false with no luck. Ultimately, I'm looking to use the custom itemRenderer, which has a set of semi-transparent <s:Rect/> primitives behind the label, with the alternatingItemColors to make the rows easier to read, but keep the style of the custom renderer intact. Any suggestions would be appreciated.

       

      Thanks,

      ~Benny

        • 1. Re: alternatingItemColors not working in custom itemRenderer
          FinFlex Level 1

          Try override itemrenderer set data function.

           

          override public function set data(value:Object):void

          {

               if(value != null)

               {

                    super.data = value;

               }

          }

          • 2. Re: alternatingItemColors not working in custom itemRenderer
            BennyB23 Level 1

            I tried placing that block of code inside the ItemRenderer and nothing happened. Was that what you were thinking, or did I not follow you correctly? Either way, thanks for taking a shot at it.

             

            ~B

            • 3. Re: alternatingItemColors not working in custom itemRenderer
              Shongrunden Adobe Employee

              This seems to work for me:

               

              <?xml version="1.0" encoding="utf-8"?>

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

                                     xmlns:s="library://ns.adobe.com/flex/spark"

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

               

                  <mx:DataGrid alternatingItemColors="[red, blue]">

                      <mx:dataProvider>

                          <s:ArrayCollection>

                              <fx:Object name="test" />

                              <fx:Object name="test" />

                              <fx:Object name="test" />

                              <fx:Object name="test" />

                          </s:ArrayCollection>

                      </mx:dataProvider>

                      <mx:itemRenderer>

                          <fx:Component>

                              <s:MXDataGridItemRenderer>

                                  <s:Rect width="100%" height="100%">

                                      <s:fill>

                                          <s:SolidColor color="green" alpha="0.5" />

                                      </s:fill>

                                  </s:Rect>

               

                                  <s:Label text="{data.name}" />

                              </s:MXDataGridItemRenderer>

                          </fx:Component>

                      </mx:itemRenderer>

                  </mx:DataGrid>

               

              </s:Application>

               

              Can you explain what isn't working?