On Tue, Feb 25, 2014 at 11:19 PM, ashish1703 <[email protected]
> wrote:

> Hi,
>
> I have been facing this issue from quite a while now. I am using
> mx:datagrid
> control with column sorting true.
> Since i have been using  XML returned from c#(returns string for each value
> of xml) i want this to be handled on Flex.
> I have binded the dataprovider correctly but sorting for the columns is
> treated as string even for columns which have decimal/float values.
> For eg. I want 47 to be displayed as 47.00 and treated as a floating number
> so that it can be sorted and placed correctly in the grid.
>
> I tried to convert this with several methods but then they all return
> string
> which again is an issue for my requirement.
>
> Is there anyone who has come across such issue and can help me out on this.
>
> Thanks
>
>
There are different ways to do this.  One way is to use the parseFloat [1]
method to convert the string into a Number.  This should help with the
sorting.  As for the display, you may want to use a labelFunction [2]  In
this function, use Number.toFixed() [3] to display it in the format you
want.

The other way is to keep everything as strings and use a custom
sortCompareFunction [4] for your datagrid column.  In this function, you
can convert the strings to Numbers using parseFloat and use the numbers for
comparison.

Hope this helps.

Thanks,
Om

[1]
http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000589.html
[2]
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/dataGridClasses/DataGridColumn.html#labelFunction
[3]
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Number.html#toFixed%28%29
[4]
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/dataGridClasses/DataGridColumn.html#sortCompareFunction



>
> --
> View this message in context:
> http://apache-flex-users.2333346.n4.nabble.com/Data-type-to-convert-and-store-a-srting-into-decimal-float-value-tp5202.html
> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>

Reply via email to