Dojo: how to get row data in grid's context menu item handler?

Shrike picture Shrike · Jul 6, 2010 · Viewed 9.8k times · Source

I'm using Dojo 1.4.

Given a dojox.grid.DataGrid in markup:

<table jsId="grid1" dojoType="dojox.grid.DataGrid" 
       structure="layout"
       delayScroll="true" 
       columnReordering="true" 
       selectable="true"
       onRowDblClick="onRowDblClick"
       onRowContextMenu="onRowContextMenu"
       headerMenu="grid1_headerMenu"
       >
  <div dojoType="dijit.Menu" id="grid1_rowMenu" jsId="grid1_rowMenu" style="display: none;">
    <div dojoType="dijit.MenuItem" onClick="gridRowContextMenu_onClick">Edit</div>
  </div>
</table>

I haven't found a better way to show grid's contex menu that this one:

function onRowContextMenu(e) {
       grid1_rowMenu.bindDomNode(e.grid.domNode);
}

It works, menu pops up and function 'gridRowContextMenu_onClick' has being called.

function gridRowContextMenu_onClick(e) {
  // how to get a row data???
}

My question is how inside menuitem's onClick handler (gridRowContextMenu_onClick) can I get original row for which menu was poped up?

Answer

rika-t picture rika-t · Sep 9, 2010

You can use the event grid object:

 var item = e.grid.getItem(e.rowIndex);