开发者

One DataGrid Item Renderer for multiple columns

I'm trying to create a Flex DataGrid where the firstname and lastname are shown under each other, but in the DataGridColumn

Ideally I would want to do something like

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

so that both values get passed to the itemrender开发者_C百科er, is this possible?

Dennis


The itemRenderer gets the data for the whole row, so you can simply assemble it from there. Also, you may not even need an itemRenderer because that simple example can be done using a labelFunction.

Do not, however, use dataField="firstName,lastName" as you show. Assuming your collection row has a firstName and a lastName property, you could do it like this:

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

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

I typically use labelFunction when I just need to do simple string manipulations or formatting, and an itemRender if I need icons or other controls within the cell.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜