Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 08-14-2007, 12:35 AM   #1
Registered User
Join Date: Jul 2007
Posts: 70
Default Formatter in a DataGrid?

I created a custom formatter that takes a decimal number and returns a fraction (string). I can use it with some sample text areas, like so:
<comp:FractionFormatter id="makeFraction" myNumber="{myTI.text}"/> 
<mx:TextInput id="myTI"/> 
<mx:TextArea text="Formatted string is {makeFraction.format(myTI.text)}"/>
But if I try to use it in my DataGrid, like so:
<mx:DataGridColumn dataField="{makeFraction.format(@qty)}" width="35" wordWrap="true"/>
The compile fails with "Error: Access of undefined property qty."


Here's the formatter:
package myComponents
    //Import base Formatter class
    import mx.formatters.Formatter

    public class FractionFormatter extends Formatter {

        // Declare the variable to hold the pattern string.
        public var myNumber:String;

        // Constructor
        public function FractionFormatter() {
            // Call base class constructor.

        // Override format().
        override public function format(value:Object):String         {
            //Validate value - it must be a nonzero length string.
            if(value.length == 0) {    
                    // Return empty string and error message for zero-length string.
                    error="Zero Length String";
                    return ""

            //If the value is valid, format the string.  
            switch (myNumber) {  
                case ".25" :
                    return "1/4";
				case ".5":
					return "1/2";
				case ".75":
					return "3/4";
				case "1":
					return "1";
				case "1.25":
					return "1 1/4";

                default :
                    // If formatString is not "upper" or "lower", 
                    //     return empty string and set the error message.
                    error="Invalid Format String";
                    return "";
handycam is offline   Reply With Quote
Old 08-15-2007, 09:36 AM   #2
Everything about me's...
Join Date: Aug 2006
Location: UK
Posts: 198

Where's @qty coming from?
flexy is offline   Reply With Quote
Old 08-15-2007, 11:39 AM   #3
Registered User
Join Date: Jul 2007
Posts: 70

It's from the XML data (via E4X) in the data grid:
<item ln1="Widgets" minQ=".25" maxQ="2" qty=".25" />
handycam is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can you create a DataGrid soley in code using new DataGrid(); frank grimes Components 3 04-16-2007 07:31 AM
Proper way to bind data to the DataGrid component - Best practices. andrea_muta Components 1 04-03-2007 09:13 AM
Datagrid Scrolling bug? Column repeats over and over while mouse is pressed... diesel5599 Components 2 12-18-2006 04:34 PM
Datagrid positional scrolling vaene Components 0 05-13-2006 01:38 AM
Please help loading data/ datagrid ericb1 Components 1 11-22-2005 07:26 PM

All times are GMT. The time now is 01:58 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.