Using a label function to support a multicolumn DataGrid
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
backgroundColor="white">
<mx:Script>
import mx.collections.ArrayCollection;
[Bindable]
public var myAC:ArrayCollection = new ArrayCollection([
{name:"A", username:"a",dtJoined:"01/02/2011"},
{name:"T", username:"t",dtJoined:"03/12/201"},
]);
public function formatDate(rowItem:Object,column:DataGridColumn):String
{
var retVal:String = "";
if(column.dataField == "dtJoined")
retVal = dFmt.format(rowItem.dtJoined);
else if(column.dataField == "dtLogin")
retVal = dFmt.format(rowItem.dtLogin);
return retVal;
}
</mx:Script>
<mx:DateFormatter id="dFmt" formatString="MM/DD/YY" />
<mx:DataGrid id="dg" width="500" height="100" dataProvider="{myAC}">
<mx:columns>
<mx:DataGridColumn dataField="name" headerText="Name" />
<mx:DataGridColumn dataField="username" headerText="Username" />
<mx:DataGridColumn dataField="dtJoined" headerText="Joined" labelFunction="formatDate"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>
Related examples in the same category