[Dojo-interest] Context menu for DataGrid cells

Michael Schuerig michael at schuerig.de
Fri Apr 3 16:02:49 EDT 2009


I have a grid listing movies, with one column, awards, containing just a 
star for each award the movie received. A context click on a cell in 
this column should pop up a menu showing (and leading to) more details 
of the individual awards.

I've got a working version, but there's a spot of bother as it looks 
like I have to use an internal method (dijit.Menu._openMyself()) to 
achieve my end.

grid.onCellContextMenu = function(e) {
  if (e.cell.field == "awards") {
    var movie = e.grid.getItem(e.rowIndex);
    if (movie.awards) {
      var awardsMenu = new dijit.Menu({targetNodeIds: e.cellNode});
      dojo.forEach(movie.awards, function(award) {
        awardsMenu.addChild(new dijit.MenuItem({
          label: award.title,
          onClick: function() {
            dojo.publish('award.selected', [award])
          }
        }));
      });
      awardsMenu.startup();
      dojo.connect(awardsMenu, 'onClose', function() {
        awardsMenu.uninitialize();
      });
      awardsMenu._openMyself(e); // spot of bother
    }
  }
};

In general, is this technique appropriate to display dynamic context 
menus on grids and trees?

Michael

-- 
Michael Schuerig
mailto:michael at schuerig.de
http://www.schuerig.de/michael/


More information about the Dojo-interest mailing list