JQgrid中上下文菜单项的自定义值 [英] Custom values to Context Menu Items in JQgrid

查看:66
本文介绍了JQgrid中上下文菜单项的自定义值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Oleg的链接演示创建上下文菜单.有没有一种方法可以将一些动态值传递给rowID以外的每一行.一种方法是为每行设置隐藏值并获取那些隐藏的列值,但不确定如何实现此功能.感谢您的帮助或建议.

I am using this link from Oleg and Demo to create context menu. Is there a way to pass some dynamic values to each row apart from rowId. May be one way is to set hidden values for each row and get those hidden column values but not sure how to implement this functionality. Thanks for any help or suggestions..

    loadComplete: function(data) {
        // Fix the Grid Width...
        fixGridWidth($("#grid"));
        // Context Menu
        $("tr.jqgrow", this).contextMenu('contextMenu', {
            bindings: {
                'abc1': function(trigger) {
        // would like to pass some custom values
                },
                'abc2': function(trigger) {
            // open a link in new window using a hyperlink
                },
                'abc3': function(trigger) {
            // custom logic
                }
            },
            onContextMenu : function(event, menu) {
                //var rowId = $(event.target).parent("tr").attr("id");
                //var grid = $("#grid");
                //grid.setSelection(rowId);                                    
                //return true;                                    
             }
        });

推荐答案

您可以使用已将id初始化为行ID的trigger参数.因此,您可以使用getCellgetRowData.例如,abc1方法可以如下所示

You can use trigger parameter which has id initialized as the rowid. So you can use getCell or getRowData. For example the abc1 method can be like the following

loadComplete: function () {
    var $this = $(this); // it will be the same like $("#grid")
    $("tr.jqgrow", this).contextMenu('contextMenu', {
        bindings: {
            abc1: function(trigger) {
                var rowData = $(this).jqGrid('getRowData', trigger.id);
                // now you can access any data from the row including
                // hidden columns with the syntax: rowData.colName
                // where colName in the value of 'name' property of
                // the column
            },
            ...
        },
        onContextMenu : function(event, menu) {
            ...
        },
        // next settings 
        menuStyle: {
            backgroundColor: '#fcfdfd',
            border: '1px solid #a6c9e2',
            maxWidth: '600px', // to be sure
            width: '100%' // to have good width of the menu
        },
        itemHoverStyle: {
            border: '1px solid #79b7e7',
            color: '#1d5987',
            backgroundColor: '#d0e5f5'
        }
    });

请参见此处使用menuStyleitemHoverStyle会稍微改善上下文菜单的可见性.该演示来自

see here one more demo which uses menuStyle and itemHoverStyle which improve a little the visibility of the context menu. The demo is from the bug request which I recently posted.

这篇关于JQgrid中上下文菜单项的自定义值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆