开发者

Displaying properties from two objects in a datagrid

Previously I post a discussion on this matter on Flex Adobe forum and still don't understand what needs to be done. So, I'll try my luck again on stackoverflow.

I'm using drag and drop data binding functionality in flash builder 4 on a data-grid. However, the data I need to show need to be query from another object.

<mx:DataGrid id="dataGrid2" dataProvider="{getMajorDetailsResult.lastResult}"> <mx:columns> <mx:DataGridColumn headerText="Category Name" /> <mx:DataGridColumn headerText="Require Credits" dataField="requireCredits" resizable="false" width="40"/> </mx:columns> </mx:DataGrid>

In this datagrid I bind it with an object MACL which has

  • ID
  • CAT_ID
  • requireCredits

However, I would like to display CategoryName in the first column but categoryName is in another Object (category)

  • CAT_ID
  • CategoryName

In this case what should I do?

I did this so that if in the future Category Name n开发者_开发百科eeds to be rename. I can just rename the one in category table.

Someone there told me to use data model. I guess I should try to cast the object retrieved from callresponder into my self defined class object then set this class to my datagrid's dataprovider? Is that what should be done

Sample code is highly appreciated.


you could use the labelFunction attribute of the DatagridColumn in which you assign a function that decides whats going to be shown in the column:

private function labelFunction(item:Object, column:DataGridColumn):String
{
    //search for the categoryName
    for (var i:int = 0; i < categories.length; i++)
    {
        var category:Category = categories[i];
        if (category.cat_id == item.cat_id)
        {
            return category.categoryName;
        }
     }
     // in case it was not fault return a default value
     return "";
 }

HTH Gus

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜