Accessing the Render Variable of the DataGridColumn Element

In a DataGrid, I have a DataGridColumn that uses a custom component as an item renderer. Inside the component, I have an ArrayCollection that stores a collection of value objects. My problem is that I cannot access the ArrayCollection values โ€‹โ€‹outside of the item's render component. Does anyone know how this could be done? I've posted a code snippet below.

<mx:Script>
    <![CDATA[
        // Cannot access arrFiles from here.
    ]]>
</mx:Script>
<mx:DataGrid editable="true">
    <mx:columns>
        <mx:DataGridColumn id="dgcUpload" width="130" headerText="Uploaded Files"
        editable="false">
        <mx:itemRenderer>
        <mx:Component>
                    <mx:VBox>
                        <mx:Script>
                            <![CDATA[
                                [Bindable]public var arrFiles:ArrayCollection = new ArrayCollection();
                            ]]>
                        </mx:Script>
                    </mx:VBox>
        </mx:Component>
        </mx:itemRenderer>
        </mx:DataGridColumn>
    </mx:columns>
</mx:DataGrid>

      

Is it possible?

Thanks in advance for any help,

Orville

+2


source to share


2 answers


I would create a custom MXML Box component as rendered with a label (myLabel) as a child. Set the data provider for the DataGrid to an array. In your custom MXML component, override the set data method, which is called every time data is displayed for each row, and sets the label to the current value passed to:

override public function set data(value:Object):void{
         myLabel.text = value.myTextForLabel;
}

      



If the field in the ArrayCollection (myArrayCollection) is always the same for the label, just set the DataGrid Data Provider to the ArrayCollection property and the DataField property of the column to the appropriate value (myText):

<mx:DataGrid editable="true" dataProvider="myArrayCollection">
   <mx:columns>
    <mx:DataGridColumn id="dgcUpload" width="130" dataField="myText" headerText="Uploaded Files"
    editable="false">
   </mx:columns>
</mx:DataGrid>

      

+1


source


This is possible depending on how you want to access it. You can access the property of a specific item displayed by the itemRenderer by calling the itemToItemRenderer function on the datagrid. This gives you an instance of that particular itemRenderer, and you can call the arrFiles variable on that item.

Here's an example

        protected function datagrid1_clickHandler(event:MouseEvent):void
        {
            var obj:Object = dgcUpload.itemToItemRenderer(dgcUpload.selectedItem);
            var newArray:ArrayCollection = obj.arrFiles;
        }

      



I call this when something is clicked on the DataGrid and I want to access the arrFiles variable for the selected item.

Is this what you are looking for?

= Ryan

+1


source







All Articles