1 Reply Latest reply on Jan 25, 2011 12:35 PM by =VA=FyreHeart

    AdvancedDataGrid GroupingField confusing labelFunction

    =VA=FyreHeart Level 2

      I have an AdvancedDataGrid with grouped rows. I want to multiply two fields together and display the result in a third field.

       

      Problem is, my labelFunction receives an ArrayCollection of Objects and appears to only be called on the Grouped rows, like a SummaryFunction. If I attempt to do calculations of the type: item[column.dataField] I get undefined. If I loop through item.children and do the calculation, it works but naturally creates an aggregate, and that only displays on the Grouped rows rather than the sub-rows.

       

      Oddly enough, my CurrencyFormatter and DateFormatter work fine.

       

      Anyone seen anything like this? I'd like to avoid an itemRender since they slow down the grid much worse than a labelFunction.

       

      Code Snippet:

      <mx:GroupingField name="Project"/>

      ...

      <mx:AdvancedDataGridColumn editable="false" headerText="Total" id="total" labelFunction="calcTotal" width="100"/>

      ...

      protected function calcTotal(item:Object, column:AdvancedDataGridColumn):String {
           var total:Number = item['quantity']*item['price'];
           return MoneyFormatter.format(total);

      }//End calcTotal

        • 1. Re: AdvancedDataGrid GroupingField confusing labelFunction
          =VA=FyreHeart Level 2

          Figured it out: I had to use labelFunction on the mx:AdvancedDatagrid tag rather than the mx:AdvancedDataGridColumn tag.

           

          *gnashes teeth*

           

          Adobe, if anybody's reading this, I would love a more logical layout to the DG and ADG, with row- and cell-level control.

           

          If I want something to apply to a column, it should be on the column control. If I want something to apply to a row, it should be on the (nonexistent) row control. If I want something to apply to a cell, it should be on the cell control.

           

          Applying a labelFunction on the ADG itself to apply something at the column level makes a modicum of sense, since it's cascading down the hierarchy. I could get over it if there weren't also a labelFunction on the column control that points UP to the GroupingField HIGHER in the hierarchy. That just doesn't make sense. Pick one or the other!