You can return a string from summaryObjectFunction

In Flex AdvancedDatGrid we do a lot of grouping. Most columns are the same for parents and children, so I would like to show the first value of the group as a summary, not MAX, MIN or AVG

This code works with numeric, but not textual values ​​(without a commented line, you get NaN):

 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] } 

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 Correct, OfferDescription no.

+4
source share
2 answers

It looks like summaryFunction should return a number. According to Adobe's Error Tracking , this is a documentation error:

Comment by Sameer Bhatt:

The documentation mentions that - The built-in summary functions for SUM, MIN, MAX, AVG and COUNT return a number containing the summary data.

Thus, people can get an idea, but I agree with you that we must clearly indicate that the type of return should be a number.

We saved it as an object so that in the future it would be easy to add more things to it.

+1
source

If you need to get a row for display, then use labelfunction on advancedDataGridColumn. This will make the final line.

(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; } } 
+3
source

Source: https://habr.com/ru/post/1276705/


All Articles