NumberFormat Columns of Datagrid in Flex
I am filling my datagrid using XML as datasource. I need to forma开发者_如何学运维t the numeric columns with thousands of separators. Thus I have created a <mx:NumberFormatter id="setNumberFormat" .../>
But I fail to use it in the code below. (See the comment //Format Numbers using numberFormatter)
for each(var item in fieldsXMLListNew){
//Copy all columns in to a proxy
var dgColumns:Array = myGrid.columns;
//create a new dynamic Column
var aColumn:DataGridColumn = new DataGridColumn();
// add parameters
aColumn.dataField = '@' + item.attribute("field");
if (item.attribute("data_type") == "N"){ //Numeric Fields Only
//Sort Numeric Columns
aColumn.sortCompareFunction = xmlDataGridNumericSorter(item.attribute("field").toString());
//Format Numbers using numberFormatter
setNumberFormat.format(item.attribute("field").toString());
}
aColumn.headerText = item.attribute("header_text");
//add to proxy
dgColumns.push(aColumn);
//copy all in to Data Grid columns again.
myGrid.columns = dgColumns;
}
Any tweaking to this code so that it takes the number format?
Use labelFunction in each column that you want, assinging the labelFunction:
<s:GridColumn dataField="field" labelFunction="myLabelFunction"/>
The labelFunction:
private function myLabelFunction(item:Object, column:GridColumn):String
{
return setNumberFormat.format(item[column.dataField]);
}
精彩评论