1 Reply Latest reply on Mar 1, 2010 7:55 AM by Claudino Bur

    datagrid itemrenderer multiple use

    Matt Le Fevre Level 4

      Hopefully a straightforward and easy to answer question,

       

      I have a datagrid with an item renderer, like so

       

      <mx:DataGrid id="dg1" x="371" y="97" creationComplete="dg1.dataProvider = getStuff.lastResult.info">
              <mx:columns>
                  <mx:DataGridColumn id="val1" dataField="val1" itemRenderer="checkBoxRenderer"/>
                  <mx:DataGridColumn id="val1" dataField="val2" itemRenderer="checkBoxRenderer"/>
                  <mx:DataGridColumn id="val3" dataField="val3" itemRenderer="checkBoxRenderer"/>
                  <mx:DataGridColumn id="val4" dataField="val4" itemRenderer="checkBoxRenderer"/>
              </mx:columns>
      </mx:DataGrid>
      

       

      the item renderer is this

       

      <mx:CheckBox xmlns:mx="http://www.adobe.com/2006/mxml" selected="{handleData(##############)}">
      
      <mx:Script>
          <![CDATA[
              
              private function handleData(value:String):Boolean
              {
                  var checkValue:Boolean = false;
                  
                  if (value == "yes")
                  {
                      checkValue = true;
                  }
                  
                  trace(this.name);
                  
                  return checkValue;
              }
          ]]>
      </mx:Script>
          
      </mx:CheckBox>
      

       

       


      i'm trying to use the same item renderer for all 4 columns and they read their data from different areas of the XML, an example of which looks like this:

       

      <info><val1>yes</val1><val2>no</val2><val3>no</val3><val4>yes</val4></info>
      <info><val1>yes</val1><val2>no</val2><val3>yes</val3><val4>yes</val4></info>
      <info><val1>yes</val1><val2>yes</val2><val3>no</val3><val4>yes</val4></info>
      

       

      I'm aware of being able to pass around values such as "data.val1" and "data.val2" within the renderer, so it'll work individually for a single column of data.

       

      question is, how to i make them refer correctly to their respective datafields?

       

      or will i have to use individual item renderers for each column / some botch job using alot of if statements and "this.name" ?

        • 1. Re: datagrid itemrenderer multiple use
          Claudino Bur Level 2

          Hello,

           

          Your itemRenderer will need to implement IDropInListItemRenderer which hase set/get listdata:BaseListData or something like that.

           

          The dataGridColumn seting the itemRenderer's data, if it will also implement the mentioned interface it will set it's listData. With this list data

          you can take it's owner (a datagrid) and the column index and you can obtain the dataGridColumn you need. In this way from your itemRenderer you will have the associaed datagridColumn. From your dataGridColumn you can take your dataField and use it.

           

          Claude Bur.