DataGridColumn.labelFunction

Availability

Flash Player 6 (6.0.79.0).

Edition

Flash MX Professional 2004.

Usage

myDataGrid.getColumnAt(index).labelFunction

Description

Property; specifies a function to determine which field (or field combination) of each item to display. This function receives one parameter, item, which is the item being rendered, and must return a string representing the text to display. This property can be used to create virtual columns that have no equivalent field in the item.

NOTE

The specified function operates in a nondefined scope.

Example

The following example calculates a value for the "Subtotal" column:

import mx.controls.gridclasses.DataGridColumn;

var my_dg:mx.controls.DataGrid;
my_dg.setSize(300, 200);

// Set up columns.
var guitar_dgc:DataGridColumn = new DataGridColumn("guitar");
var value_dgc:DataGridColumn = new DataGridColumn("value");
var tax_dgc:DataGridColumn = new DataGridColumn("tax");
var st_dgc:DataGridColumn = new DataGridColumn("Subtotal");
//Define labelFunction for Subtotal column.
st_dgc.labelFunction = function(item:Object):String {
 if ((item.value != undefined) && (item.tax != undefined)) {
  return "$"+(item.value+item.tax);
 }
};

// Add columns to grid.
my_dg.addColumn(guitar_dgc);
my_dg.addColumn(value_dgc);
my_dg.addColumn(tax_dgc);
my_dg.addColumn(st_dgc);

// Set data model.
my_dg.addItem({guitar:"Flying V", value:10, tax:1});
my_dg.addItem({guitar:"SG", value:20, tax:2});
my_dg.addItem({guitar:"jagstang", value:30, tax:3});