开发者

Flex DataGrid - How we get object of Custom Control from a cell

I have a quick question about getting the value from control which I added in my dat开发者_C百科a grid by Item render and how can I get that control object when I am clicking on the cell of that column.


you can access by this

<mx:DataGrid id="fileGrid" click="onClick(event)" dataProvider="{grpCollection}" width="100%" height="100%">
            <mx:columns>
                <mx:DataGridColumn dataField="labelText" headerText="" visible="{!readOnly}" width="100">
                    <mx:itemRenderer>
                        <mx:Component>
                            <renderers:LinkRendererWithEvent/>
                        </mx:Component>
                    </mx:itemRenderer>
                </mx:DataGridColumn>                    
            </mx:columns>
        </mx:DataGrid>

private function onClick(event:MouseEvent):void
            {
                if (event.target is LinkRendererWithEvent)
                {
                    var linkRenderer:LinkRendererWithEvent = event.target as LinkRendererWithEvent;
                    if (linkRenderer.linkBut.label == "Add")
                    {

                    }
                }
            }

LinkRendererWithEvent.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" doubleClickEnabled="true" doubleClick="doubleClickHandler()" 
    implements="mx.controls.listClasses.IDropInListItemRenderer">
    <mx:Script>
        <![CDATA[
            import mx.controls.Button;
            import mx.controls.DataGrid;
            import mx.events.FlexEvent;
            import com.barcap.customui.constant.NotificationNames;
            import com.barcap.customui.ApplicationFacade;
            import mx.controls.dataGridClasses.DataGridListData;
            import flash.events.Event;
            import mx.controls.listClasses.BaseListData;
            import mx.controls.dataGridClasses.DataGridListData;
            protected var _listData:DataGridListData;

            [Bindable]
            public var labelField:String;
            public var notificationName:String;


            override public function setFocus():void
            {
                trace("called ");
            }

            private function clickHandler(event:MouseEvent):void
            {
                dispatchEvent(event);
            }

            private function doubleClickHandler():void
            {
                owner.dispatchEvent(new MouseEvent(MouseEvent.DOUBLE_CLICK, false, false));
            }

            override public function set data(value:Object):void
            {
                super.data = value;
                setIt(value);
            }

            public function get listData():BaseListData
            {
                return _listData;
            }

            public function set listData(value:BaseListData):void
            {
                _listData = DataGridListData(value);
                invalidateProperties();
            }

            private function setIt(value:Object):void
            {
                if (value && _listData)
                {
                    linkBut.label = value[_listData.dataField];
                }
                else
                {
                    linkBut.label = "";
                }
            }

            override public function drawFocus(isFocused:Boolean):void
            {
                trace("Enter drawFocus");
            }
        ]]>
    </mx:Script>
    <mx:LinkButton id="linkBut" textDecoration="underline" click="clickHandler(event)"/>
</mx:VBox>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜