views:

64

answers:

2

Hi Friends, I am facing an issue in my Flex application. I am creating some array collections and storing date objects in it.In the later part of the application I will create 'advanceddatagridcolumns' with these array collections as the data sources.

Initially while creating the Array Col , I do have the 'formats' given by user, for each array collection eg. '1995/06/25' but in the later part I have no access to these formats. I want to display this dates in the data grid in same way as the user has specified. Right now, it displays it in the default format 'Sun Jun 25 00:00:00 GMT+0530 1995' instead of '1995/06/25'.

I have a common 'labelFunction' for these advancedatagridcolumns, and thus I can not use the DateFormatter as I 'formatstring' would be different for different columns.

So is there some way to display/retrieve the date in the same format as stored and not in the default way. Or while creating the date object can't I specify that I would always like it to be returned in some desired format.

Thanks a lot in advance.

Ashine.

A: 

The Date class in Flex as far, as my experiences go, is not very versatile. My hunch is that this is by no means possible with the regular framework capabilities.

However, if the date does not need to be changed after the user has input it, you might just want to save it as String and only create a temporary ArrayCollection of Dates for displaying them. This way you don't need to worry about the format changing because you're saving the original value.

How are you parsing the dates anyway? I mean that are you finding out the format yourself with RegExps or such, or using the parse method of the Date class?

tehmou
Hi Tehmou,Seems a good idea but I have two concerns(1) I have to write the parser manually in myAxis.parser function. This is required as the string has to be converted to date. And I don't know of any flex built-in method that can allow user to parse formated strings to date. I tried to use 'parseDateString' method of datformatter but it is static and I could not think of how to use it. I also tried to use parse method as follows but it is not robust and covers very limited cases."var d:Date = new Date(Date.parse(dateString));"
Ashine
(2) In future I am looking for scope to add 'zooming/filter' etc. In such cases having a direct date value in data will be more helpful than having a formatted string (which couldn't be parsed by flex methods directly which supports only the parsing for basic formats like 'MM\DD\YY' in my case it is bit unusual 'Tue HH:NN:SS' )
Ashine
A: 

just create a labelfunction specific to that column only and then you can use the formatstring

Shua
Thanks Shua.I did the same thing finally.Actually, we are required to show this formatted date string for ex in data tips, axis labels and data grid and each time we have to keep the design so that at run time the format infoprmation is availabel in the label function. And as the label function has a fixed signature, it becomes truly difficult to share this format information. I use a class variable to pass format inforamtion in the label function as I could not pass it through the arguments.
Ashine
I feel you pain... I've created VOs before to handle this headache... So I would either in the VO object dynamically create the label string in a function or pass it the actual label string value to a variable (most likely named label) this way when I passed the object around my application it always had the correct label and didnt have to worry about label functions in each component/tooltip/axis/ whatever...
Shua
I would really love to know more about VOs implementation in current scenario. Can you please describe it a bit further ?
Ashine