JqGrid PHP: how to implement a righ-click context-menu?
Asked Answered
S

1

-1

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 ?

Spiffing answered 3/2, 2014 at 16:18 Comment(1)
Do you solved your previous problem with usage this inside of callback function which you set by setGridEvent? Probably you have the same problem here?Wagers
W
2

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).

Wagers answered 3/2, 2014 at 16:55 Comment(4)
thank you @Oleg, I changed it to loadComplete without the space. Though, I am now getting this error: Uncaught TypeError: Object #<HTMLTableElement> has no method 'editGridRow'Spiffing
to fix the error above i had to change grid.editGridRow(trigger.id, editSettings); into jQuery('#grid').jqGrid('editGridRow', '" + trigger.id + "'); Altough I am now getting an empty edit form! (looks like the code doesn't get the row id!)Spiffing
Ok I managed to get it working eventually! I had to change '" + trigger.id + "' to trigger.id. therefore the right code is: jQuery('#grid').jqGrid('editGridRow', trigger.id);Spiffing
@JessStone: One have to use $("#grid").jqGrid("method", ...) instead of $("#grid").method(...) if the option $.jgrid.no_legacy_api = true; are set. Other parts of your code which you posted seems be far from the main question which I answered. Such problems could be easy debugged and it's much more difficult to find errors during reading. In any way I'm glad to read that you code seems to work now. My congratulations!Wagers

© 2022 - 2024 — McMap. All rights reserved.