JqGrid PHP: how to implement a righ-click context-

2019-09-20 16:05发布

How can I implement a righ-click context-menu in JqGrid for PHP ?

I am trying this solution by Oleg, but it is not working. I would like to get this:

enter image description here


grid.php snippet:

$rightclick = <<<RIGHTCLICK
    function () {
    $("tr.jqgrow", this).contextMenu('myMenu1', {
        bindings: {
            'edit': function (trigger) {
                // trigger is the DOM element ("tr.jqgrow") which are triggered
                grid.editGridRow(trigger.id, editSettings);
            },
            'add': function ( /*trigger*/ ) {
                grid.editGridRow("new", addSettings);
            },
            'del': function (trigger) {
                if ($('#del').hasClass('ui-state-disabled') === false) {
                    // disabled item can do be choosed
                    grid.delGridRow(trigger.id, delSettings);
                }
            }
        },
        onContextMenu: function (event /*, menu*/ ) {
            var rowId = $(event.target).closest("tr.jqgrow").attr("id");
            //grid.setSelection(rowId);
            // disable menu for rows with even rowids
            $('#del').attr("disabled", Number(rowId) % 2 === 0);
            if (Number(rowId) % 2 === 0) {
                $('#del').attr("disabled", "disabled").addClass('ui-state-disabled');
            } else {
                $('#del').removeAttr("disabled").removeClass('ui-state-disabled');
            }
            return true;
        }
    });
}
RIGHTCLICK;

$grid->setGridEvent('loadComplete ', $rightclick);

Is there any way to get a context menu in JqGrid for PHP ?

1条回答
戒情不戒烟
2楼-- · 2019-09-20 16:51

First of all your code have unneeded space: 'loadComplete ' instead of 'loadComplete'.

I can repeat one more time that I don't use PHP myself and don't use setGridEvent of JqGrid for PHP too. So I can only guess that $grid->setGridEvent probably don't forward this correctly. In the case you can use setGridParam to set callback dynamically (see the answer) or to use jqGridLoadComplete event instead of loadComplete callback (see the answer).

查看更多
登录 后发表回答