2010-04-30 56 views
0

我試圖創建Flex數據網格,其中名字和姓氏都在對方顯示,但在的DataGridColumn一個DataGrid的項目渲染多個列

理想我希望做這樣的事情

<mx:columns> <mx:DataGridColumn headerText="Column 2" dataField="time"/> <mx:DataGridColumn headerText="Column 2" dataField="firstname,lastname" itemRenderer="renderers.FirstNameLastName"/>

這樣既值傳遞給itemRenderer的,這是POS機錫布爾赫丁?

丹尼斯

回答

1

的itemRenderer獲取數據的整行,所以你可以簡單地從那裏組裝。此外,你可能甚至不需要itemRenderer,因爲這個簡單的例子可以使用labelFunction完成。

但是,請不要像您展示的那樣使用dataField="firstName,lastName"。假設您的收藏行已經將firstname和lastname屬性,你可以做這樣的:

private function lastNameFirstName(item:Object, column:DataGridColumn) : String { 
    return item.lastName + ", " + item.firstName; 
} 

... 
<mx:DataGridColumn headerText="Column 2" labelFunction="lastNameFirstName"/> 
... 

我通常使用的labelFunction時,我只需要做簡單的字符串操作或格式化,以及itemRender如果我需要的圖標或細胞內的其他控制。