views:

867

answers:

2

In a Flex AdvancedDatGrid, we're doing a lot of grouping. Most of the columns are the same for the parents and for the children, so I'd like to show the first value of the group as the summary rather than the MAX, MIN or AVG

This code works on numerical but not textual values (without the commented line you get NaN's):

private function firstValue(itr:IViewCursor,field:String, str:String=null):Object 
{
  //if(isNaN(itr.current[field])) return 0  //Theory: Only works on Numeric Values?
  return itr.current[field]
}

The XML:

(mx:GroupingField name="Offer")
  (mx:summaries)
    (mx:SummaryRow summaryPlacement="group")
      (mx:fields)
        (mx:SummaryField dataField="OfferDescription"   label="OfferDescription" summaryFunction="firstValue"/)
        (mx:SummaryField dataField="OfferID"   label="OfferID" summaryFunction="firstValue"/)
        (/mx:fields)
    (/mx:SummaryRow)
  (/mx:summaries)
(/mx:GroupingField)

OfferID's work Correctly, OfferDescriptions don't

+1  A: 

It looks like the summaryFunction has to return a number. According to the Adobe bug tracker, it is a bug in the documentation:

Comment from Sameer Bhatt:

In the documentation it is mentioned that - The built-in summary functions for SUM, MIN, MAX, AVG, and COUNT all return a Number containing the summary data.

So people can get an idea but I agree with you that we should clearly mention that the return type should be a Number.

We kept it as an Object so that it'll be easy in the future to add more things in it.

81bronco
+2  A: 

If you need to get a string to show then use the labelfunction on the advancedDataGridColumn. This will render the summary row.

(mx:AdvancedDataGridColumn headerText="Comment" width="140" dataField="comment" labelFunction="formatColumn" /)

      private function getNestedItem(item:Object):Object {

       try {
        if (item.undefined[0]) {
         item = getNestedItem(item.undefined[0]);
        }
       } catch (e:Error) {
        // leave item alone
       }
       return item;
      }   
      private function formatColumn(item:Object, column:AdvancedDataGridColumn):String {

       var output:String;
       // If this is a summary row
       if (item.GroupLabel) {

        item = getNestedItem(item);
       } 

       switch (column.dataField) {

        case 'comment':

         return item.comment;


       }

      }
CPriebe