Custom values to Context Menu Items in JQgrid

前端 未结 1 1178
生来不讨喜
生来不讨喜 2020-12-22 00:49

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 valu

相关标签:
1条回答
  • 2020-12-22 01:29

    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'
            }
        });
    

    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.

    0 讨论(0)
提交回复
热议问题