1
votes


i am using below code for using linkbutton in flex datagrid

<mx:DataGridColumn headerText="Case ID" width="80">
                    <mx:itemRenderer>
                        <fx:Component>
                            <mx:Canvas>
                                <mx:LinkButton id="lnkCaseId" click="outerDocument.lnkCaseIdClick(event)" label="{data.caseId}" textDecoration="underline" color="#0052A5">
                                </mx:LinkButton>
                            </mx:Canvas>
                        </fx:Component>
                    </mx:itemRenderer>
                </mx:DataGridColumn><br/>

now on link button click i want linkbutton label name and selected row inside lnkCaseIdClick method, how can i do this?
thanks.

2
i hv got linkbutton label using 'event.currentTarget.label.toString();' how can i get selected row?user594979

2 Answers

1
votes

Here is sample according to explanation in @J_A_X but its using default MouseEvent You can extent *MouseEvent* Class to hold your custom data

<?xml version="1.0" encoding="utf-8"?>
<mx:Application 
    xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
    click="{clicked(event)}">
    <mx:Script>
        <![CDATA[
            import mx.controls.LinkButton;
            import mx.core.UIComponent;
            import mx.controls.Alert;
            public function clicked(event:MouseEvent):void
            {
                if (event.target is LinkButton)
                {
                    var innerLinkButon:LinkButton = event.target as LinkButton;
                    Alert.show("Application : "+innerLinkButon.label);
                }
            }
        ]]>
    </mx:Script>
    <mx:DataGrid id="grid">
        <mx:dataProvider>
            <mx:ArrayCollection>
                <mx:Array>
                    <mx:Object label="AAAA"/> 
                    <mx:Object label="BBBB"/>
                    <mx:Object label="CCCC"/>
                    <mx:Object label="DDDD"/>
                </mx:Array>
            </mx:ArrayCollection>
        </mx:dataProvider>
        <mx:columns>
            <mx:DataGridColumn id="columnA" headerText="columnA" dataField="@label">
                <mx:itemRenderer>
                    <mx:Component>
                        <mx:LinkButton click="{clicked(event)}" label="{data.label.toString()}">
                            <mx:Script>
                                <![CDATA[
                                    import mx.controls.Alert;

                                    public function clicked(event:MouseEvent):void
                                    {
                                        Alert.show("linkButton");
                                    }

                                ]]>
                            </mx:Script>
                        </mx:LinkButton>
                    </mx:Component>
                </mx:itemRenderer>
            </mx:DataGridColumn>
        </mx:columns>
    </mx:DataGrid>
</mx:Application>

Hopes that helps

3
votes

Don't use outerDocument.lnkCaseIdClick(event), it's a horrible practice since you're assuming the function will always be there and makes your code coupled.

You should look into bubbling a custom event that holds the data you need from the item renderer, and then from your container, add the event listener for your custom event.