开发者

How to convert XML data to Number before filling an AdvancedDataGrid

开发者 https://www.devze.com 2023-03-13 04:43 出处:网络
I import XML data in order to fill an AdvancedDataGrid (using Flex 4.5). This ADG is correctly filled with the data, columns display the right information etc. etc.

I import XML data in order to fill an AdvancedDataGrid (using Flex 4.5).

This ADG is correctly filled with the data, columns display the right information etc. etc.

I would like to summarize this ADG using

<mx:SummaryRow summaryPlacement="group">
    <mx:SummaryField2 dataField="Cost" label="amount" summaryOperation="SUM">
</mx:SummaryRow>

But there is a problem! Indeed, the 'Cost' data are imported as 'Strings' and that is why I cannot do the SUM... I just get a nice 0 as a result! I would like to convert these data into Numbers, so that the addition can be processed. This conversion has to be done before filling the ADG I think.

I already tried to implement a custom summaryOperation but was unlucky...

public function calculateSummary(data:Object, field:SummaryField2, rowData:Object):void
{
    var dataField:String = field.dataField;
    var value:Number = Number(rowData[dataField]);
    Alert.show(rowData[dataField]);
    if (!data.hasOwnProperty(dataField))
        data[dataField] = value ;
    else
        data[dataField] +=开发者_开发知识库 value;   
}

The Alert always displays a void message, the data are not transmitted to this function I think

There is another thing: the user can insert new data in the XML dynamically and that insertion has to update the SUM result.

Could anybody help me? I will go on searching and if I find something, I would post it :D

Thank you!


You can convert astring to a number doing something like this:

var myNewNumber : Number = Number(stringValue);

Where exactly you want to do that in relation to your code, I'm not sure. You could definitely convert your XML into an array of objects, and then use that array as your dataProvider. I suspect you could also do it as part of the process to calculate the total.


If you are working with XML don't forget to use the '@' to identify the attibute (@Cost).

<mx:SummaryRow summaryPlacement="group">
    <mx:SummaryField2 dataField="@Cost" label="amount" summaryOperation="SUM">
</mx:SummaryRow>

You don't need to convert Strings to Numbers, the framework is already doing it internally.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号