2 Replies Latest reply on Nov 18, 2009 5:56 AM by Gregory Lafrance

    Assign data field in a data grid based on a condition

    appdevs

      I have a n XMLList called as resultA and it looks like this

       

      <cmpName srcVariable="aft_panic" srcValue= "8" tgtVariable ="aft_panic" tgtValue ="7" >
      <cmpName srcVariable="Missing"   srcValue= "Missing" tgtVariable ="maxphys" tgtValue ="2400">

       

      I have used this XMLList to create a data grid and it works fine:


      <mx:DataGrid id="dg3" dataProvider="{resultA1}" >
             <mx:columns >
         <mx:DataGridColumn id = "col1" dataField="@srcVariable" headerText="EtcSystem Variable"/>
         <mx:DataGridColumn id = "col2" dataField="@srcValue" headerText="{server1Display}"/>
         <mx:DataGridColumn id = "col3" dataField="@tgtValue" headerText="{server2Display}"/>
             </mx:columns>
      </mx:DataGrid>

       

      Now , I need to make a small change to the first column dataField:

       

      The first column in the data grid should have the @srcVariable data.But if the @srcVariable = "Missing" as in the second row in the XMLList above, the @tgtVariable should become the first column data.

       

      Something like this :

      if(resultA.@srcVariable == "Missing"){
         dg3.col1.dataField = resultA.@tgtVariable
      }else{
         dg3.col1.dataField = resultA.@srcVariable
      }

       

      Can anyone let me know how i can achieve this?

        • 2. Re: Assign data field in a data grid based on a condition
          Gregory Lafrance Level 6

          If this post answers your question or helps, please mark it as such.

           

          Here is the labelFunction in action:

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
            <mx:Script>
              <![CDATA[
                private function myLabFunc(item:Object, dgc:DataGridColumn):String{
                  var retStr:String;
                  if(item.@srcVariable == "Missing"){
                    retStr = item.@tgtVariable;
                  }else{
                    retStr = item.@srcVariable;
                  }
                  return retStr;
                }
              ]]>
            </mx:Script>
            <mx:XMLList id="resultA1" xmlns="">
              <cmpName srcVariable="aft_panic" srcValue= "8" 
                tgtVariable ="aft_panic" tgtValue ="7" />
              <cmpName srcVariable="Missing"   srcValue= "Missing" 
                tgtVariable ="maxphys" tgtValue ="2400"/>    
            </mx:XMLList>
            <mx:DataGrid id="dg3" dataProvider="{resultA1}" width="200">
              <mx:columns>
                <mx:DataGridColumn id = "col1" labelFunction="myLabFunc" width="150" 
                  dataField="@srcVariable" headerText="EtcSystem Variable"/> 
              </mx:columns>
            </mx:DataGrid>  
          </mx:Application>