-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 ?

Community
  • 1
  • 1
Jess Stone
  • 677
  • 8
  • 21
  • Do you solved [your previous problem](http://stackoverflow.com/q/21522699/315935) with usage `this` inside of callback function which you set by `setGridEvent`? Probably you have the same problem here? – Oleg Feb 03 '14 at 16:31

1 Answers1

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

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • thank you @Oleg, I changed it to `loadComplete` without the space. Though, I am now getting this error: `Uncaught TypeError: Object # has no method 'editGridRow'` – Jess Stone Feb 04 '14 at 08:52
  • 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!) – Jess Stone Feb 04 '14 at 09:23
  • 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);` – Jess Stone Feb 04 '14 at 13:44
  • @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! – Oleg Feb 04 '14 at 13:57