2 Replies Latest reply on Oct 24, 2011 6:55 PM by HaroldCHeardJr

    Formatting a SummaryField2 as a percentage

    HaroldCHeardJr

      My data is coming in via XML where SLA is either a 1=Meets SLA or a 0=Failed SLA, I then runn the field in a summay row where I average on the grouping field.  I have a SummaryField2 that I need to format the grouping field showing as a percentage.  any assistance would be appreciated.  I need to format the results in this manor "87.45%" below is the Grouping Field code below:

       

      <mx:GroupingField name="Customer" >

        <mx:summaries>

          <mx:SummaryRow summaryPlacement="group">

            <mx:fields>

              <mx:SummaryField2 dataField="SLA" summaryOperation="AVG" />

            </mx:fields>

          </mx:SummaryRow>

        </mx:summaries>

      </mx:GroupingField>

       

      <mx:AdvancedDataGridColumn id="adgSLA" dataField="SLA" headerText="SLA" textAlign="right" visible="false" />

       

      SLA.jpg

       

      SLA.jpg

        • 1. Re: Formatting a SummaryField2 as a percentage
          kraikit Level 2

          Have you tried implementing your own ISummaryCalculator object and providing that for the SummaryField2.summaryOperation property?

           

          -- Tom

          • 2. Re: Formatting a SummaryField2 as a percentage
            HaroldCHeardJr Level 1

            To solve this issue I added the "labelFunction" property to the AdvancedDataGridColumn columns like this:

             

            labelFunction="genericLabelFunction"

             

            -----------------------------------------------------------------------------

             

            private function genericLabelFunction(obj_data:Object, obj_AdvanceddataGridColumn:AdvancedDataGridColumn):String

            {

                      var functionsNS:Namespace;

                      var q:QName = new QName(functionsNS, obj_AdvanceddataGridColumn.dataField);

                      var str_data:String = obj_data[q.localName.valueOf()];

             

                      if (obj_AdvanceddataGridColumn.dataField == "SLA")

                                if (!isNaN(Number(str_data)))

                                {

                                          var tempNumber:Number = new Number(str_data);

                                          tempNumber = tempNumber * 100;

                                          str_data = tempNumber.toFixed(2) + "%";

                                }

                      return str_data;

            }

             

            I hope this helps others.