4 Replies Latest reply on Dec 30, 2011 12:43 PM by Flexpadawan

    Datagrid itemrenderer & evaluation of different column

    Flexpadawan

      Hey All,

       

      I've been playing with this for a while but can't get it right.  Basically, I have an itemrenderer that has an image and label, but I need to see what the value is of a different column before I know what image to use.  I have a feeling the reason why my intended logic won't work is becasue the data[] does not reporesent the whole data structure...but I could be wrong.

       

      This is what I have now:

      I have a grid that references this itemrenderer & the grid dataprovider is an array collection:

      Form

      <s:GridColumn dataField="employee"  headerText="Employee"

                       itemRenderer="com.mycompany.view.assets.renderers.EmployeeStatusColour"></s:GridColumn>

       

       


       

      Item Renderer

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

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

           ....>

       

        <fx:Script>

             <![CDATA[

       

                override public function prepare(hasBeenRecycled:Boolean):void {  

                //THIS WORKS BUT NEED TO ADD LOGIC

                     lblData.text = data[column.dataField];

                     statusImage.source = "com/mycompany/view/assets/images/dot_GREEN.png";

       

                //THIS IS WHAT I WANT INSTEAD - SYNTAX BELOW IS WRONG BUT YOU'LL GET THE IDEA

                     lblData.text = data[column.dataField];

                     if(data[column(3)]; = "MONDAY"{

                          statusImage.source = "com/mycompany/view/assets/images/dot_GREEN.png";

                     }else{

                          statusImage.source = "com/mycompany/view/assets/images/dot_BLUE.png";

                     }

                }

              ]]>

        </fx:Script>

       

                <s:HGroup verticalAlign="middle" height="100%" gap="2">

                <s:Image id="statusImage"/>

                <s:Label id="lblData" paddingTop="5"/>

        </s:HGroup>

       

      </s:GridItemRenderer>

       

       

       

      Thanks in advance to anybody who can direct me to a solution.

      Flex

        • 1. Re: Datagrid itemrenderer & evaluation of different column
          jfb00 Level 3

          Hi,

          Try labelFunction as:

          <s:GridColumn dataField="employee"  headerText="Employee" labelFunction="setColor"

           

          Here an idea for you function:

          private function setColor(o:Object, c:spark.components.gridClasses.GridColumn):String

                      {

                          if (o[c.dataField] == 3){

                              return "dot_GREEN.png";

                          }else

                              return "dot_BLUE.png";

                      }

           

          Best,

          • 2. Re: Datagrid itemrenderer & evaluation of different column
            Flexpadawan Level 1

            Hi,

             

            I tried your suggestion but it didn't work.   Thanks though! 

             

            However, if you see the code below this works as I stated above.  data[column.dataField] returns the value of the referenced value. 

             

            override public function prepare(hasBeenRecycled:Boolean):void {

                                                    lblData.text = data[column.dataField];

                                                    statusImage.source = "com/mycompany/view/assets/images/dot_green.png";

            }

             

            So I did a debug inside my item renderer and found that the data object had all the object values of the row from my grid, which is what I want.  I just don't know how to access them individually to do my comparison.  It's probably something really easy like

             

            If (data[column(4).dataField]=="MONDAY"){  

                       statusImage.source = "com/mycompany/view/assets/images/dot_GREEN.png";

            }

             

             

            I know I'm close just don't know the syntax.

             

            Thanks!

            • 3. Re: Datagrid itemrenderer & evaluation of different column
              Flexpadawan Level 1

              I guess what it boils down to is how to I access the full data reference inside in the GridItemRenderer?

               

              data[column.dataField] - Returns the cell value of the Column where the item renderer is referenced inside my grid.

               

              data - Has the whole recordset and I can see it in debug mode, so in my case I need to access the fourth object inside of the data object.  If I can get that problem solved.

               

              Thanks again!

              • 4. Re: Datagrid itemrenderer & evaluation of different column
                Flexpadawan Level 1

                Found the solution.  Okay, I can go bang my head against the wall now!  lol

                 

                To find any value in the data structure you do the following:

                data[column.dataField="dayStatus"];