Awesome - works great. Thanks Alex - sometimes the biggest problem is figuring out that something like labelFunction exists. I read through the Flex help docs but must've somehow overlooked this.
--- In flexcoders@yahoogroups.com, "Alex Harui" <[EMAIL PROTECTED]> wrote: > > read up on labelFunction > > ________________________________ > > From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On > Behalf Of byte.sensei > Sent: Wednesday, September 26, 2007 7:59 AM > To: flexcoders@yahoogroups.com > Subject: [flexcoders] DataGrid itemRenderer > > > > I've been pulling my hair out trying to figure out the best way to > format numbers in a DataGrid. I've got a dataProvider with fields > used in the grids that are of type "Number" -- some are currency, > some are integers, and some are numbers that need to be formatted to > 1 decimal point. > > In other places in my application, I'm using a custom function to > format numbers: > > public function format_number(num : Number, format : String) : String > { > var formatter : NumberFormatter = new NumberFormatter(); > var str : String; > > switch (format) { > case "currency": > formatter.precision = 2; > formatter.useThousandsSeparator = true; > str = "$" + formatter.format(num); > break; > case "percent": > formatter.precision = 1; > formatter.useThousandsSeparator = true; > str = formatter.format(num*100) + "%"; > break; > case "decimal2": > formatter.precision = 2; > formatter.useThousandsSeparator = false; > str = formatter.format(num); > break; > case "cuft": > formatter.precision = 1; > formatter.useThousandsSeparator = true; > if (num < 0) { num = 0 } > str = formatter.format(num); > break; > default: > str = String(num); > break; > } > > return str; > } > > However, I can't figure out a way to utilize this function on my > DataGrid columns. I've tried creating both inline and external > itemRenderer components, but in both cases I don't see a way to > inject the required Actionscript into the itemRenderer component -- I > keep getting compile errors when I try to use an mx:Script block in > the component. > > Anyone know of a way to make this work? >