This content has been marked as final. Show 6 replies
You can use the labelFunction and the DateFormatter to handle this. The item is passed into the date formatter and it will configure the date as you like.
I'd understand if I had the datagrid set up like the way you did but the problem I have is I have a whole datatable that I passed into flex that I need to assign to the datagrid so it gets all the columns and rows. and i just want to change the format of the columns that are date type. (so i need to assign the datagrid from the script.
in the code i meant dg.dataProvider = dataSet.Table.Rows (dataSet is the C# dataset object I pass into flex)
How would that work with your solution?
Same way. Use a labelFunction for the columns that are dates.
Or are you saying you are not declaring individual DataGridColumns?
Pre-processing the data is an ok way to handle this. First you need to be sure you have the date in a format that the AS Date object understands. Is your if condition, "i is Date" ever returning true?
What format are you getting?
Just a quick thought in the code attached you have for(var i:Object and that is what you are trying to format. However a DateFormatter doesn't know how to format an entire object. Wouldn't you either need to loop over all the identifiers in the object so formatter.format(i.DateColumn1) etc.. or scope i into the more specific field of what it is your trying to format? You are also scoping i to an Object so I wouldn't think your if(i is Date) is going to ever return true.
For performance reasons you'll want to handle this during the display and not modify the objects directly. Let's say you have 2,000 rows of data... you would end up formatting all 2,000 records. Your DataGrid in most cases will scroll and only about 20 records would be displayed at a time. When you use the labelFunction you're only changing 20 at a time and performance is faster. In addition you're able to modify the Date as a Date later if your requirements change.
I have attached an actionscript example for you to use. If you're creating the entire grid on the fly then you'll just need to add more DataGridColumn's and add them to the dg.columns array.
Kurt is correct on the performance issue however my last comment on that is if you are returning a 2000 row recordset back to Flex I would do the processing on the server side returning back two identifiers one as the original date and the second as the formatted date eliminating the need for labelFunctions or DateFormatters all together. Better to chew up a servers CPU then it is your clients.