开发者

Populating a cell in a dataGrid with multiple values seperated by commas - Flex

开发者 https://www.devze.com 2023-03-16 08:57 出处:网络
I have an XML file with this data. <resultSet> <MerchandiseAssortmentCategory> <merchandiseAssortmentCategoryId>275</merchandiseAssortmentCategoryId>

I have an XML file with this data.

<resultSet> 
<MerchandiseAssortmentCategory>
                                <merchandiseAssortmentCategoryId>275</merchandiseAssortmentCategoryId>
                                <merchandiseAssortmentCategoryName>D21 Plywood</merchandiseAssortmentCategoryName>
                                <merchandiseSubordinateClasses>
                                                <merchandiseSubordinateClass>
                                                                <merchandiseSubordinateClassNumber>2</merchandiseSubordinateClassNumber>
                                                                <merchandiseSubordinateClassDescription>SHEATHING</merchandiseSubordinateClassDescription>
                                                </merchandiseSubordinateClass>
                                                <merchandiseSubordinateClass>
                                                                <merchandiseSubordinateClassNumber>3</merchandiseSubordinateClassNumber>
                                                                <merchandiseSubordinateClassDescription>WAFERBOARD</merchandiseSubordinateClassDescription>
                                                </merchandiseSubordinateClass>
                                                <merchandiseSubordinateClass>
                                                                <merchandiseSubordinateClassNumber>4</merchandiseSubordinateClassNumber>
                                                                <merchandiseSubordinateClassDescription>SANDED</merchandiseSubordinateClassDescription>
                                                </merchandiseSubordinateClass>
                                </merchandiseSubordinateClasses>
</MerchandiseAssortmentCategory>
</resultSet> 

I need to populate a data grid with the merchandiseAssortmentCategoryName and all its merchandiseSubordinateClassNumber(s) seperated with commas in the same row.

the categoryList is which is the dataprovider for the dataGrid is defined as follows :

this.categoryList= evt.result.resultSet.MerchandiseAssortmentCategory;

and this is how the dataGrid is defined

<mx:DataGrid x="466" y="73" width="192" height="225" 
        dataProvider="{categoryList}" 
        verticalScrollPolicy="on" 
        id="categories"
        rowCount="10" enable开发者_JAVA百科d="true">
        <mx:columns>
            <mx:DataGridColumn headerText="Category name" dataField="merchandiseAssortmentCategoryName"/>
            <mx:DataGridColumn headerText="Subclasses" dataField="merchandiseSubordinateClasses.merchandiseSubordinateClass.merchandiseSubordinateClassNumber"/>

            </mx:columns>
    </mx:DataGrid>

When i run this, only the category name is filled. the subordinateclass number is just blank. Help out with this. Thanks


You're going to have to write a labelFunction to return the comma separated list you want displayed in the column.

Read these docs on creating a custom label function. Here are some relevant details:

[Start Quote]

You can pass a label function to the List control to provide logic that determines the text that appears in the control. The label function must have the following signature:

labelFunction(item:Object):String

The item parameter passed in by the Label control contains the list item object. The function must return the string to display in the List control.

Note: Most subclasses of ListBase also take a labelFunction property with the signature described above. For the DataGrid and DataGridColumn controls, the method signature is labelFunction(item:Object, dataField:DataGridColumn):String, where item contains the DataGrid item object, and dataField specifies the DataGrid column.

....

<mx:Script><![CDATA[
    public function myLabelFunc(item:Object):String {
        return item.data + ", " + item.label; 
    }
]]></mx:Script>

[End Quote]

The item object parameter is the element of the dataProvider you want to generate a label for.

You can specify the labelFunction property on the class in question:

<mx:DataGridColumn labelFunction="myLabelFunc" />

You can also do the same thing with a custom itemRenderer.


Here's what I would do:

  1. Make a custom itemRenderer for the Subclasses column in the DataGrid.
  2. Override the set data method to go through all of your subclasses and build the comma delimited string.
  3. Set the value of the itemRenderer's label to your comma delimited string.
0

精彩评论

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