Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 08-14-2007, 12:35 AM   #1
handycam
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:
Code:
<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:
Code:
<mx:DataGridColumn dataField="{makeFraction.format(@qty)}" width="35" wordWrap="true"/>
The compile fails with "Error: Access of undefined property qty."

Suggestions?

Here's the formatter:
Code:
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.
            super();
        }

        // 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";
                    break; 
				case ".5":
					return "1/2";
					break;
				case ".75":
					return "3/4";
					break;
				case "1":
					return "1";
					break;
				case "1.25":
					return "1 1/4";
					break;

                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
flexy
Everything about me's...
 
Join Date: Aug 2006
Location: UK
Posts: 198
Default

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

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


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 11:53 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.