1 Reply Latest reply on Dec 8, 2009 8:52 AM by Gregory Lafrance

    Accessing DataGrid currentTarget from a dataGridColumn button

    rcanulla Level 1

      I am trying to access the row item clicked from within a datagrib button. Any thoughts? It seems to only accept event or mouseevent...

       

                     public function onDeleteItem(e:Event):void{
                          trace(e.currentTarget.parent);     
                     }
      <mx:DataGridColumn headerText="Remove" width="60">
                                    <mx:itemRenderer>
                                         <mx:Component>
                                               <mx:Box horizontalAlign="center" verticalAlign="middle">     
                                                    <mx:Button skin="@Embed('assets/remove_icon.png')" 
                                                         buttonMode="true" scaleX=".6" scaleY=".6" click="outerDocument.onDeleteItem(event)" />           
                                               </mx:Box>
                                         </mx:Component>
                                    </mx:itemRenderer>
                               </mx:DataGridColumn>
      
      
        • 1. Re: Accessing DataGrid currentTarget from a dataGridColumn button
          Gregory Lafrance Level 6

          You need to access the dataProvider using the DataGrid selectedItem property.

           

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> 
            <mx:Script>
              <![CDATA[
                import mx.collections.ArrayCollection;
                
                [Bindable] private var ac:ArrayCollection = new ArrayCollection([
                  {test: "one"}, {test: "two"}, {test: "three"}, {test: "four"}, {test: "five"}
                ]);
                
                public function clickFunc():void{
                  txt.text = dg.selectedItem.test;
                }
              ]]>
            </mx:Script>
            <mx:DataGrid id="dg" dataProvider="{ac}">
              <mx:columns>
                <mx:DataGridColumn dataField="test">
                  <mx:itemRenderer>
                    <mx:Component>
                      <mx:Button label="Click Me" click="outerDocument.clickFunc();"/>
                    </mx:Component>
                  </mx:itemRenderer>
                </mx:DataGridColumn>
              </mx:columns>
            </mx:DataGrid>
            <mx:Text id="txt"/>
          </mx:Application>
          


          If this post answers your question or helps, please mark it as such.


          Greg Lafrance
          www.ChikaraDev.com

          Flex Development and Support Services