3 Replies Latest reply on Nov 22, 2009 9:52 PM by manishmulani

    AdvancedDataGridColumn DataField problem

    manishmulani

      I've a XML which is the dataProvider to AdvancedDataGrid.

       

      XML looks like this

       

      <data>

      <positions>

         <count type="success">30</count>

         <count type="failed">40</count>

         <count type="skipped">20</count>

      </positions>

      ....

      ....

       

       

       

      I've three columns in AdvancedDataGrid , countSuccess , countFailed, countSkipped

       

      I want to show 30 , 40 , 20 in these columns respectively..

       


      I tried setting the dataField = "positions.count.(@type="success")"   . similarly for each of three columns

      This doesn't work

        • 1. Re: AdvancedDataGridColumn DataField problem
          paul.williams Level 4

          I doubt the DataGridColumn will handle this kind of conditional dataField expression. Support has been added in 3.4 for nested properties, but you've gone beyond that. I would suggest using a labelFunction instead:

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
             
              <mx:Script>
                  <![CDATA[
                      import mx.controls.dataGridClasses.DataGridColumn;
                     
                      private static const COUNT_SUCCESS : String = "countSuccess";
                      private static const COUNT_FAILED : String = "countFailed";
                      private static const COUNT_SKIPPED : String = "countSkipped";
                     
                      [Bindable]
                      private var myXML : XML = <data>
                          <positions>
                              <count type="success">30</count>
                              <count type="failed">40</count>
                              <count type="skipped">20</count>
                          </positions>
                          <positions>
                              <count type="success">12</count>
                              <count type="failed">15</count>
                              <count type="skipped">93</count>
                          </positions>
                          <positions>
                              <count type="success">15</count>
                              <count type="failed">45</count>
                              <count type="skipped">6</count>
                          </positions>
                      </data>;
                     
                      private function labelFunction( value : Object, column : DataGridColumn ) : String
                      {
                          var result : String;
                          var position : XML = XML( value );
                          switch( column.headerText )
                          {
                              case COUNT_SUCCESS : result = position.count.(@type=="success"); break;
                              case COUNT_FAILED : result = position.count.(@type=="failed"); break;
                              case COUNT_SKIPPED : result = position.count.(@type=="skipped"); break;
                              default : throw new Error( "Unknown column: " + column.headerText ); break;
                          }       
                         
                          return result;
                      }
                     
                  ]]>
              </mx:Script>
             
              <mx:DataGrid
                  dataProvider="{ myXML.positions }"
                  labelFunction="labelFunction">
                  <mx:columns>
                      <mx:DataGridColumn headerText="{ COUNT_SUCCESS }"/>
                      <mx:DataGridColumn headerText="{ COUNT_FAILED }"/>
                      <mx:DataGridColumn headerText="{ COUNT_SKIPPED }"/>
                  </mx:columns>
              </mx:DataGrid>
             
          </mx:Application>

          • 2. Re: AdvancedDataGridColumn DataField problem
            ShankarFlex3

            Hi,

             

            Are you able to modify your xml if so try to do it this way

             

            <data>

            <positions>

               <success>30</success>

               <failed>40</failed>

               <skipped>20</skipped>

            </positions>

             

            Now you can access the values by "positions.success", "positions.failed" and "positions.skipped".

             

            Hope this helps.

            • 3. Re: AdvancedDataGridColumn DataField problem
              manishmulani Level 1

              Thanks paul.williams

               

              This is what I was looking for.