Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If there is no data, there won't be any row or itemRenderer and hence technically there is no row index. The <code>e.target</code> would contain the <code>ListBaseContentHolder</code> and <code>e.currentTarget</code> would contain the DataGrid itself. However you can use the mouse-y position to calculate what row would have been present at the clicked location. Here is a dirty little trick to do it - it's not thoroughly tested and hence might fail for edge cases.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:local="*" creationComplete="create();"&gt; &lt;mx:DataGrid id="myGrid" editable="true" click="clickEvent(event)" variableRowHeight="true" &gt; &lt;mx:columns&gt; &lt;mx:DataGridColumn dataField="d"/&gt; &lt;mx:DataGridColumn/&gt; &lt;/mx:columns&gt; &lt;/mx:DataGrid&gt; &lt;mx:Script&gt; &lt;![CDATA[ import mx.controls.listClasses.ListRowInfo; import mx.controls.listClasses.ListBaseContentHolder; private function clickEvent(e:MouseEvent):void { if(!(e.target is ListBaseContentHolder)) return; var holder:ListBaseContentHolder = ListBaseContentHolder(e.target); var rowIndex:Number = -1; var length:Number = holder.rowInfo.length; var rowInfo:ListRowInfo; for(var i:Number = 0; i &lt; length; i++) { rowInfo = holder.rowInfo[i]; if(e.localY &gt; rowInfo.y &amp;&amp; e.localY &lt; rowInfo.y + rowInfo.height) { rowIndex = i; break; } } trace("Clicked on " + rowIndex); } private function create():void { myGrid.dataProvider = [{d:"A"},{d:"B"}]; } ]]&gt; &lt;/mx:Script&gt; &lt;/mx:Application&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload