1 Reply Latest reply on Feb 9, 2007 10:07 PM by chris.huston.t10

    DataFields calling functions

    David Sargent
      I created a class with an methods and properties, called "User". One of the methods or functions returns a text representation for the numerical status of the user. I want to show the text from the function "statusTitle " in the DataGrid. I would assume that you would bind the function name with statusTitle() to the dataField of the DataGridColumn. But I get a blank column when I do that. So how do you bind functions of objects to dataGrids?

      Thanks for help


      <mx:DataGrid x="23" y="10" width="445" dataProvider="{userArray}">
      <mx:columns>
      <mx:DataGridColumn headerText="First" dataField="fname" width="30"/>
      <mx:DataGridColumn headerText="Last" dataField="lname"/>
      <mx:DataGridColumn headerText="Status" dataField="statusTitle()"/>
      </mx:columns>
      </mx:DataGrid>




      public class User extends Object {
      public var fname:String = "Mike";
      public var lname:String = "Jones";
      public var statusID:int = 1;


      public function statusTitle(): String{
      switch(statusID){
      case 1: return "Active";
      case 2: return "InActive";
      }
      return "Undefined";
      }
      }



        • 1. Re: DataFields calling functions
          chris.huston.t10 Level 3
          I don't think you can bind a function to a dataField, but what if you made your statusTitle update a variable that was bound to the dataField like this:

          public class User extends Object {
          public var fname:String = "Mike";
          public var lname:String = "Jones";
          public var statusID:int = 1;
          [Bindable] public var activeStatus:String = "Undefined";

          public function statusTitle(): String{
          switch(statusID){
          case 1: activeStatus = "Active";
          case 2: activeStatus = "InActive";
          default: activeStatus = "Undefined";
          }
          }
          }

          It this doesn't work, then an itemRenderer might be an option.

          Vygo