Package | fl.controls.dataGridClasses |
Class | public class DataGridColumn |
Inheritance | DataGridColumn Object |
Language Version: | ActionScript 3.0 |
Product Version: | Flash CS3 |
Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0 |
You can specify the kind of component that displays the data for a DataGridColumn. The characteristics that can be specified include the text that appears in the column header and whether the column can be edited, sorted, or resized.
Related API Elements
Property | Defined By | ||
---|---|---|---|
cellRenderer : Object
The class that is used to render the items in this column. | DataGridColumn | ||
constructor : Object
A reference to the class object or constructor function for a given object instance. | Object | ||
dataField : String
Identifies the name of the field or property in the data provider item
that is associated with the column. | DataGridColumn | ||
editable : Boolean = true
Indicates whether the items in the column can be edited. | DataGridColumn | ||
editorDataField : String = "text"
Identifies the name of the property of the item editor that contains the new
data for the list item. | DataGridColumn | ||
headerRenderer : Object
The class that is used to render the header of this column. | DataGridColumn | ||
headerText : String
The column name to be displayed in the column header. | DataGridColumn | ||
imeMode : String
The mode of the input method editor (IME). | DataGridColumn | ||
itemEditor : Object = fl.controls.dataGridClasses.DataGridCellEditor
Indicates the class of the instances of the item editor to use for the
column, when it is editable. | DataGridColumn | ||
labelFunction : Function
A function that determines the text to be displayed in this column. | DataGridColumn | ||
minWidth : Number
The minimum width of the column, in pixels. | DataGridColumn | ||
prototype : Object [static]
A reference to the prototype object of a class or function object. | Object | ||
resizable : Boolean = true
Indicates whether the user is allowed to change the width of the
column. | DataGridColumn | ||
sortable : Boolean = true
Indicates whether the user can click on the header of the current column
to sort the data provider. | DataGridColumn | ||
sortCompareFunction : Function
A callback function that is called when sorting the data in
the column. | DataGridColumn | ||
sortDescending : Boolean = false
Indicates whether the DataGridColumn is to be sorted in ascending or
descending order. | DataGridColumn | ||
sortOptions : uint = 0
One or more defined constants, identified by name or number and separated
by the bitwise OR (|) operator. | DataGridColumn | ||
visible : Boolean
Indicates whether the column is visible. | DataGridColumn | ||
width : Number
The width of the column, in pixels. | DataGridColumn |
Method | Defined By | ||
---|---|---|---|
DataGridColumn(columnName:String = null)
Creates a new DataGridColumn instance. | DataGridColumn | ||
Indicates whether an object has a specified property defined. | Object | ||
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter. | Object | ||
Returns the string that the item renderer displays for the given data object. | DataGridColumn | ||
Indicates whether the specified property exists and is enumerable. | Object | ||
Sets the availability of a dynamic property for loop operations. | Object | ||
Returns the string representation of this object, formatted according to locale-specific conventions. | Object | ||
Returns a string representation of the DataGridColumn object. | DataGridColumn | ||
Returns the primitive value of the specified object. | Object |
cellRenderer | property |
cellRenderer:Object
Language Version: | ActionScript 3.0 |
Product Version: | Flash CS3 |
Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0 |
The class that is used to render the items in this column. The type of this property can be Class, Sprite or String. If the property type is String, the String value must be a fully qualified class name.
The default value is null.
Implementation
public function get cellRenderer():Object
public function set cellRenderer(value:Object):void
Related API Elements
Example ( How to use this example )
import fl.controls.dataGridClasses.DataGridColumn; var dgc:DataGridColumn = new DataGridColumn("Field"); dgc.cellRenderer = "MyCustomCellRendererClass"; dg.addColumn(dgc);
dataField | property |
public var dataField:String
Language Version: | ActionScript 3.0 |
Product Version: | Flash CS3 |
Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0 |
Identifies the name of the field or property in the data provider item that is associated with the column.
editable | property |
public var editable:Boolean = true
Language Version: | ActionScript 3.0 |
Product Version: | Flash CS3 |
Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0 |
Indicates whether the items in the column can be edited. A value of true
indicates that the column items can be edited; a value of false
indicates
that they cannot be edited.
If this property is set to true
and the editable
property of the DataGrid is also true
, the items in a column are
editable and can be individually edited by clicking an item
or by navigating to the item by using the Tab and arrow keys.
The default value is true.
editorDataField | property |
public var editorDataField:String = "text"
Language Version: | ActionScript 3.0 |
Product Version: | Flash CS3 |
Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0 |
Identifies the name of the property of the item editor that contains the new data for the list item.
For example, the default itemEditor
is
TextInput, so the default value of the editorDataField
property is "text"
. This value specifies the
text
property of the TextInput component.
The default value is "text".
headerRenderer | property |
headerRenderer:Object
Language Version: | ActionScript 3.0 |
Product Version: | Flash CS3 |
Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0 |
The class that is used to render the header of this column.
The type of this property can be Class, Sprite or String. If the property type is String, the string value must be a fully qualified class name.
The default value is null.
Implementation
public function get headerRenderer():Object
public function set headerRenderer(value:Object):void
Related API Elements
headerText | property |
headerText:String
Language Version: | ActionScript 3.0 |
Product Version: | Flash CS3 |
Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0 |
The column name to be displayed in the column header.
By default, the DataGrid component uses the value of the dataField
property as the column name.
Implementation
public function get headerText():String
public function set headerText(value:String):void
Example ( How to use this example )
import fl.controls.DataGrid; import fl.controls.dataGridClasses.DataGridColumn; import fl.data.DataProvider; var dp:DataProvider = new DataProvider(); dp.addItem({name:"Person A", sales:13453}); dp.addItem({name:"Person B", sales:23432}); dp.addItem({name:"Person C", sales:9454}); var nameCol:DataGridColumn = new DataGridColumn("name"); nameCol.headerText = "Employee:"; var salesCol:DataGridColumn = new DataGridColumn("sales"); salesCol.headerText = "Sales:"; salesCol.labelFunction = currencyFormatter; salesCol.sortOptions = Array.NUMERIC; var myDataGrid:DataGrid = new DataGrid(); myDataGrid.addColumn(nameCol); myDataGrid.addColumn(salesCol); myDataGrid.dataProvider = dp; myDataGrid.move(10, 10); myDataGrid.setSize(320, 240); addChild(myDataGrid); function currencyFormatter(item:Object):String { return "$" + item.sales.toFixed(0); }
imeMode | property |
imeMode:String
Language Version: | ActionScript 3.0 |
Product Version: | Flash CS3 |
Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0 |
The mode of the input method editor (IME). The IME enables users to enter text in Chinese, Japanese, and Korean. The flash.system.IMEConversionMode class defines constants to be used as the valid values for this property.
If this property is null
, the mode of the IME is
set to the value of the imeMode
property of the DataGrid
component.
The default value is null.
Implementation
public function get imeMode():String
public function set imeMode(value:String):void
Related API Elements
itemEditor | property |
public var itemEditor:Object = fl.controls.dataGridClasses.DataGridCellEditor
Language Version: | ActionScript 3.0 |
Product Version: | Flash CS3 |
Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0 |
Indicates the class of the instances of the item editor to use for the column, when it is editable. The type of this property can be Class, Sprite or String. If the property type is String, the string value must be a fully qualified class name.
The default value is "fl.controls.dataGridClasses.DataGridCellEditor".
Example ( How to use this example )
import fl.controls.dataGridClasses.DataGridColumn; var dgc:DataGridColumn = new DataGridColumn("Field"); dgc.itemEditor = "MyCustomItemEditorClass"; dg.addColumn(dgc);
labelFunction | property |
labelFunction:Function
Language Version: | ActionScript 3.0 |
Product Version: | Flash CS3 |
Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0 |
A function that determines the text to be displayed in this column. By default, the
column displays the text for the data field that matches the column name.
However, a column can also be used to display the text of more than one data field,
or to display content that is not in the proper format. This can be done by
using the labelFunction
property to specify a callback function.
If both the labelFunction
and labelField
properties
are defined, the labelFunction
takes precedence.
The default value is null.
Implementation
public function get labelFunction():Function
public function set labelFunction(value:Function):void
Example ( How to use this example )
import fl.controls.DataGrid; import fl.controls.ScrollPolicy; import fl.controls.dataGridClasses.DataGridColumn; import fl.data.DataProvider; var i:uint; var totalRows:uint = 16; var dp:DataProvider = new DataProvider(); for (i = 0; i < totalRows; i++) { dp.addItem({col1:getRandomNumber(), col2:getRandomNumber(), col3:getRandomNumber(), col4:getRandomNumber()}); } var c1:DataGridColumn = new DataGridColumn("col1"); c1.sortOptions = Array.NUMERIC; var c2:DataGridColumn = new DataGridColumn("col2"); c2.sortOptions = Array.NUMERIC; var c3:DataGridColumn = new DataGridColumn("col3"); c3.sortOptions = Array.NUMERIC; c3.labelFunction = currencyFormatter; var dg:DataGrid = new DataGrid(); dg.setSize(200, 300); dg.addColumn(c1); dg.addColumn(c2); dg.addColumn(c3); dg.dataProvider = dp; addChild(dg); function getRandomNumber():Number { return Math.random() * 100; } function currencyFormatter(data:Object):String { var value:Number = Number(data.col3); return "$" + value.toFixed(2); }
labelFunction
and sortCompareFunction
:
import fl.controls.DataGrid; import fl.controls.dataGridClasses.DataGridColumn; import fl.data.DataProvider; var data:XML = <data> <item name="Employee A" isManager="1" /> <item name="Employee B" isManager="0" /> <item name="Employee C" isManager="1" /> </data>; var dp:DataProvider = new DataProvider(data); var nameDGC:DataGridColumn = new DataGridColumn("name"); nameDGC.sortCompareFunction = isManager; nameDGC.labelFunction = nameLabelFunction; var myDataGrid:DataGrid = new DataGrid() myDataGrid.addColumn(nameDGC); myDataGrid.dataProvider = dp; myDataGrid.width = 200; myDataGrid.rowCount = myDataGrid.length; myDataGrid.move(10, 10); addChild(myDataGrid); function nameLabelFunction(item:Object):String { var managerString:String = ""; if (item.isManager == "1") { managerString = " (Manager)"; } return item.name + managerString; } function isManager(itemA:Object, itemB:Object):int { if (itemA.isManager > itemB.isManager) { return -1; } else if (itemA.isManager < itemB.isManager) { return 1; } else { return 0; } }
minWidth | property |
minWidth:Number
Language Version: | ActionScript 3.0 |
Product Version: | Flash CS3 |
Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0 |
The minimum width of the column, in pixels.
The default value is 20.
Implementation
public function get minWidth():Number
public function set minWidth(value:Number):void
Related API Elements
Example ( How to use this example )
import fl.controls.DataGrid; import fl.controls.dataGridClasses.DataGridColumn; import fl.data.DataProvider; import fl.events.DataGridEvent; var data:XML = <data> <row col1="item 1.A" col2="item 1.B" col3="item 1.C" /> <row col1="item 2.A" col2="item 2.B" col3="item 2.C" /> <row col1="item 3.A" col2="item 3.B" col3="item 3.C" /> </data>; var dp:DataProvider = new DataProvider(data); var c1:DataGridColumn = new DataGridColumn("col1"); c1.minWidth = 100; var c2:DataGridColumn = new DataGridColumn("col2"); var c3:DataGridColumn = new DataGridColumn("col3"); var myDataGrid:DataGrid = new DataGrid(); myDataGrid.addColumn(c1); myDataGrid.addColumn(c2); myDataGrid.addColumn(c3); myDataGrid.dataProvider = dp; myDataGrid.move(10, 10); myDataGrid.setSize(300, 200); myDataGrid.addEventListener(DataGridEvent.COLUMN_STRETCH, columnStretchHandler); addChild(myDataGrid); function columnStretchHandler(event:DataGridEvent):void { var column:DataGridColumn; for each (column in myDataGrid.columns) { trace(column.dataField, "width:" + column.width, "minWidth:" + column.minWidth); } trace("---"); }
resizable | property |
public var resizable:Boolean = true
Language Version: | ActionScript 3.0 |
Product Version: | Flash CS3 |
Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0 |
Indicates whether the user is allowed to change the width of the
column. A value of true
indicates that the user can
change the column width; a value of false
indicates that
the user cannot change the column width.
The default value is true.
sortable | property |
public var sortable:Boolean = true
Language Version: | ActionScript 3.0 |
Product Version: | Flash CS3 |
Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0 |
Indicates whether the user can click on the header of the current column
to sort the data provider. A value of true
indicates that
the column can be sorted by clicking on its header; a value of false
indicates that it cannot be sorted by clicking on its header.
The default value is true.
Example ( How to use this example )
import fl.controls.DataGrid; import fl.controls.dataGridClasses.DataGridColumn; import fl.data.DataProvider; import fl.events.DataGridEvent; var data:XML = <dataProvider> <data col1="Person A" col2="11.383" /> <data col1="Person B" col2="3.399" /> <data col1="Person C" col2="25.624" /> </dataProvider> var dp:DataProvider = new DataProvider(data); var c1:DataGridColumn = new DataGridColumn("col1"); var c2:DataGridColumn = new DataGridColumn("col2"); c2.sortable = false; var myDataGrid:DataGrid = new DataGrid(); myDataGrid.addColumn(c1); myDataGrid.addColumn(c2); myDataGrid.dataProvider = dp; myDataGrid.move(10, 10); myDataGrid.setSize(160, 120); addChild(myDataGrid);
sortable
property to false
:
import fl.controls.DataGrid; import fl.controls.dataGridClasses.DataGridColumn; import fl.data.DataProvider; import fl.events.DataGridEvent; var xmlDP:XML = <items> <item name="Person 1" bio="Person 1 bio" /> <item name="Person 2" bio="Person 2 bio" /> </items>; var dp:DataProvider = new DataProvider(xmlDP); var nameCol:DataGridColumn = new DataGridColumn("name"); nameCol.headerText = "Name:"; var bioCol:DataGridColumn = new DataGridColumn("bio"); bioCol.headerText = "Bio:"; bioCol.sortable = false; var myDataGrid:DataGrid = new DataGrid(); myDataGrid.addColumn(nameCol); myDataGrid.addColumn(bioCol); myDataGrid.dataProvider = dp; myDataGrid.rowCount = dp.length; myDataGrid.width = 200; myDataGrid.move(10, 10); myDataGrid.addEventListener(DataGridEvent.HEADER_RELEASE, headerReleaseHandler); addChild(myDataGrid); function headerReleaseHandler(event:DataGridEvent):void { var myDG:DataGrid = event.currentTarget as DataGrid; trace("dataField:" + event.dataField); trace("columnIndex:" + event.columnIndex); trace("{DataGrid}.sortDescending:" + myDG.sortDescending); trace("{DataGridColumn}.sortDescending:" + myDG.getColumnAt(event.columnIndex).sortDescending); trace(""); }
sortCompareFunction | property |
sortCompareFunction:Function
Language Version: | ActionScript 3.0 |
Product Version: | Flash CS3 |
Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0 |
A callback function that is called when sorting the data in
the column. If this property is not specified, the data is sorted by string
or number, depending on the sortOptions
property.
When specified, the sortCompareFunction
property allows you to create
your own custom sorting method for the current data grid column.
The default value is null.
Implementation
public function get sortCompareFunction():Function
public function set sortCompareFunction(value:Function):void
Related API Elements
Example ( How to use this example )
labelFunction
and sortCompareFunction
:
import fl.controls.DataGrid; import fl.controls.dataGridClasses.DataGridColumn; import fl.data.DataProvider; var data:XML = <data> <item name="Employee A" isManager="1" /> <item name="Employee B" isManager="0" /> <item name="Employee C" isManager="1" /> </data>; var dp:DataProvider = new DataProvider(data); var nameDGC:DataGridColumn = new DataGridColumn("name"); nameDGC.sortCompareFunction = isManager; nameDGC.labelFunction = nameLabelFunction; var myDataGrid:DataGrid = new DataGrid() myDataGrid.addColumn(nameDGC); myDataGrid.dataProvider = dp; myDataGrid.width = 200; myDataGrid.rowCount = myDataGrid.length; myDataGrid.move(10, 10); addChild(myDataGrid); function nameLabelFunction(item:Object):String { var managerString:String = ""; if (item.isManager == "1") { managerString = " (Manager)"; } return item.name + managerString; } function isManager(itemA:Object, itemB:Object):int { if (itemA.isManager > itemB.isManager) { return -1; } else if (itemA.isManager < itemB.isManager) { return 1; } else { return 0; } }
sortDescending | property |
public var sortDescending:Boolean = false
Language Version: | ActionScript 3.0 |
Product Version: | Flash CS3 |
Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0 |
Indicates whether the DataGridColumn is to be sorted in ascending or
descending order. A value of true
indicates that the
DataGridColumn is sorted in descending order; a value of false
indicates that the DataGridColum is sorted in ascending order.
The default value is false.
sortOptions | property |
public var sortOptions:uint = 0
Language Version: | ActionScript 3.0 |
Product Version: | Flash CS3 |
Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0 |
One or more defined constants, identified by name or number and separated by the bitwise OR (|) operator. These constants are used to specify the sort operation.
The default value is 0.
Related API Elements
Example ( How to use this example )
sortOptions
property
to specify that a data grid column should be sorted numerically:
import fl.data.DataProvider; import fl.controls.dataGridClasses.DataGridColumn; var data:XML = <players> <player name="Player 1" score="1234" /> <player name="Player 2" score="198" /> <player name="Player 3" score="987" /> </players>; var dp:DataProvider = new DataProvider(data); var nameDGC:DataGridColumn = new DataGridColumn("name"); var scoreDGC:DataGridColumn = new DataGridColumn("score"); scoreDGC.sortOptions = Array.NUMERIC; dg.addColumn(nameDGC); dg.addColumn(scoreDGC); dg.dataProvider = dp;
visible | property |
visible:Boolean
Language Version: | ActionScript 3.0 |
Product Version: | Flash CS3 |
Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0 |
Indicates whether the column is visible. A value of true
indicates
that the column is visible; a value of false
indicates that the column
is invisible.
The default value is true.
Implementation
public function get visible():Boolean
public function set visible(value:Boolean):void
Example ( How to use this example )
visible
property of each of these columns by clicking the corresponding Button instance on the Stage.
import fl.controls.Button; import fl.controls.DataGrid; import fl.controls.dataGridClasses.DataGridColumn; import fl.data.DataProvider; var dp:DataProvider = new DataProvider(); dp.addItem({name:"Person A", average:0.297}); dp.addItem({name:"Person B", average:0.288}); dp.addItem({name:"Person C", average:0.310}); var nameCol:DataGridColumn = new DataGridColumn("name"); nameCol.headerText = "Name:"; var averageCol:DataGridColumn = new DataGridColumn("average"); averageCol.headerText = "Average:"; averageCol.labelFunction = numberFormatter; averageCol.sortOptions = Array.NUMERIC; averageCol.visible = false; var myDataGrid:DataGrid = new DataGrid(); myDataGrid.addColumn(nameCol); myDataGrid.addColumn(averageCol); myDataGrid.dataProvider = dp; myDataGrid.rowCount = dp.length; myDataGrid.width = 320; myDataGrid.move(10, 10); addChild(myDataGrid); var nameButton:Button = new Button(); nameButton.label = "Toggle name"; nameButton.toggle = true; nameButton.selected = nameCol.visible; nameButton.move(myDataGrid.x, myDataGrid.y + myDataGrid.height + 10); nameButton.addEventListener(Event.CHANGE, changeHandler); addChild(nameButton); var averageButton:Button = new Button(); averageButton.label = "Toggle average"; averageButton.toggle = true; averageButton.selected = averageCol.visible; averageButton.move(nameButton.x + nameButton.width + 10, nameButton.y); averageButton.addEventListener(Event.CHANGE, changeHandler); addChild(averageButton); function numberFormatter(item:Object):String { return Number(item.average).toFixed(3); } function changeHandler(event:Event):void { var colIndex:int = -2; var col:DataGridColumn; switch (event.currentTarget) { case nameButton: colIndex = myDataGrid.getColumnIndex("name"); break; case averageButton: colIndex = myDataGrid.getColumnIndex("average"); break; default: return; } if (colIndex > -1) { col = myDataGrid.getColumnAt(colIndex); col.visible = !col.visible; myDataGrid.removeColumnAt(colIndex); myDataGrid.addColumnAt(col, colIndex); } myDataGrid.spaceColumnsEqually(); }
width | property |
DataGridColumn | () | Constructor |
public function DataGridColumn(columnName:String = null)
Language Version: | ActionScript 3.0 |
Product Version: | Flash CS3 |
Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0 |
Creates a new DataGridColumn instance.
ParameterscolumnName:String (default = null ) — The column name to display in the column header. If
no name is specified, the dataField value is used.
|
Related API Elements
itemToLabel | () | method |
public function itemToLabel(data:Object):String
Language Version: | ActionScript 3.0 |
Product Version: | Flash CS3 |
Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0 |
Returns the string that the item renderer displays for the given data object.
If the DataGridColumn or its DataGrid component has a non-null labelFunction
property, it applies the function to the data object. Otherwise, the method extracts
the contents of the field that is specified by the dataField
property, or gets the
string value of the data object. If the method cannot convert the parameter to a string,
it returns a single space.
Parameters
data:Object — The Object to be rendered.
|
String — Displayable string based on the specified data object.
|
toString | () | method |
- Add the DataGrid and Button components to the library.
- Save this code as DataGridColumnExample.as in the same directory as your FLA.
- Set the DocumentClass in the FLA to DataGridColumnExample.
package { import flash.display.Sprite; import flash.events.MouseEvent; import fl.data.DataProvider; import fl.events.DataChangeEvent; import fl.controls.DataGrid; import fl.controls.Button; import fl.controls.dataGridClasses.DataGridColumn; public class DataGridColumnExample extends Sprite { private var dg:DataGrid; private var dp:DataProvider; private var names:Array = [ "Mary", "Bob", "Sue", "Joe" ]; public function DataGridColumnExample() { dp = new DataProvider(); dp.addEventListener(DataChangeEvent.DATA_CHANGE,dataChanged); dg = new DataGrid(); addChild(dg); dg.move(10,45); dg.setSize(450,300); dg.addColumn(new DataGridColumn("name")); dg.addColumn(new DataGridColumn("phone")); dg.addColumn(new DataGridColumn("email")); var firstColumn = dg.columns[0]; firstColumn.resizable = false; var secondColumn = dg.columns[1]; secondColumn.sortable = false; var thirdColumn = dg.columns[2]; thirdColumn.sortable = false; var addContactBtn:Button = new Button(); addContactBtn.label = "Add Contact"; addContactBtn.move(10,10); addContactBtn.addEventListener(MouseEvent.CLICK, addContact); addChild(addContactBtn); } private function getRandomPhone():String { return randomDigit()+randomDigit()+randomDigit()+"-"+randomDigit()+randomDigit()+randomDigit()+"-"+randomDigit()+randomDigit()+randomDigit()+randomDigit(); } private function randomDigit():String { return String(Math.round(Math.random()*10)%10); } private function getRandomName():String { return names[Math.round(Math.random()*names.length)%names.length]; } private function addContact(e:MouseEvent):void { var randomName:String = getRandomName() dp.addItem( { name: randomName, phone: getRandomPhone(), email: randomName + "@fictitious.com" } ); } private function dataChanged(e:DataChangeEvent):void { var changedItems:Array = e.items; dg.addItem(changedItems[0]); } } }
Mon Nov 28 2011, 06:48 AM -08:00