开发者

JQGrid context menu for each cell

I use context menu to allow user do different actions on cell in JQGrid:

function showContextMenu(rowId)
{
    menu1 = [ {'View':function(menuItem,menu) { alert("You clicked View!"); } },
              $.contextMenu.separator, 
              {'Upload':function(menuItem,menu) { alert("You clicked Upload!"); }},
                $.contextMenu.separator,
                {'Remove':funct开发者_如何学Goion(menuItem,menu) { alert("You clicked Remove!"); }}
               ];


    $('#' + rowId).contextMenu(menu1,{theme:'vista'}); 

Event

onRightClickRow : function(rowid,iRow,iCol,e){
     showContextMenu(rowid,iCol);
}

It works, but clumsy: problem that it needs to do double right click - because on first click (if I have understand correct) - bind function and only on second - display menu. I have try to use

gridComplete : function {
 var dataIds = $('#list').jqGrid('getDataIDs');
for (var i = 0;i < dataIds.length; i++) {
showContextMenu(dataIds[i]);
 }

But in this case I cannot receive iCol. What solution can be? Thanks.


You must specify values ​​for the rows and cells.

var dataIds = jQuery('#list').jqGrid('getDataIDs');
 var countCols = jQuery('#list').jqGrid('getGridParam', 'colNames').length;
 for (var i = 0;i < dataIds.length ; i++) {
    for (j=0;j<= countCols;j++)
       showContextMenu(dataIds[i],i+1,j);
 }

And change the function

function showContextMenu(rowid,iRow,iCol){
        menu1 = [ {'Yahoooo!':function(menuItem,menu) { 
        alert(rowid+" — "+iRow+" — "+iCol);
        } }];
jQuery("tr#"+rowid+" td").eq(iCol).contextMenu(menu1,{theme:'osx'});};
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜