Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_Related Related Topics sp_TopicIcon
small bug fixes in jquery.contextmenu.js plugin
04/12/2011
17:47
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hello Tony,

I suggest to make small bug fixes in the jquery.contextmenu.js included in jqGrid as plugin.

1) trigger variable defined in the line 21 will be never used. It can be removed.

2) parameter options from the line 91 will be never used in the body of the function display. It can be also removed.

3) parameter e from the line 112 will be also never used and can be removed.

4) The most important bug is that the variable currentTarget defined in the line 21 will be never assigned and undefined value are used in the line 114 as the second parameter of func function invocation. I suggest to include inside of the oby of $(this).bind('contextmenu', function(e) { (for example after the line 84) the assignment

currentTarget = e.target;

You can download the modified version of the jquery.contextmenu.js file here.

After the fix one will have inside of any functions inside of bindings the parameter currentTarget assigned to the DOM element at which the context menu was opened. So instead of binding contextMenu to every row of the grid (call of $("tr.jqgrow", this).contextMenu('myMenu1', {…}) inside of loadComplete every time when grid contain will be rebuild) one will be able to call $('#list').contextMenu('myMenu1', {…}) only once. So the code coule be about the following:

var grid = $('#list');
grid.contextMenu('myMenu1', {
    bindings: {
        edit: function (trigger, currentTarget) {
            var rowId = $(currentTarget).closest("tr.jqgrow").attr("id");
            grid.jqGrid('editGridRow', rowId, editSettings);
        },
        add: function () {
            grid.jqGrid('editGridRow', "new", addSettings);
        },
        del: function (trigger, currentTarget) {
            var rowId = $(currentTarget).closest("tr.jqgrow").attr("id");
            grid.jqGrid('delGridRow', rowId, delSettings);
        }
    },
    onContextMenu: function (e) {
        var rowId = $(e.target).closest("tr.jqgrow").attr("id");
        if (!rowId) {
            return false; // no contex menu on rows having no "jqgrow" class
        }
        grid.jqGrid('setSelection', rowId);
        return true;
    }
}); 

where editSettings, addSettings and delSettings can be dfined above. See the demo.

Best regards
Oleg

05/12/2011
18:23
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Thanks Oleg,

Will check this.

Best Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

11/12/2011
00:46
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hello Tony,

The next problem in the context menu that it returns always false from the contextmenu event (see here). I suggest to make the following small modification in the code

$(this).bind('contextmenu', function(e) {
  // Check if onContextMenu() defined
  var bShowContext = (!!hash[index].onContextMenu) ? hash[index].onContextMenu(e) : true;
  currentTarget = e.target;
  if (bShowContext) {
    display(index, this, e, options);
    return false;
  }
}); 

You can find additional information in the answer.

Best regards
Oleg 

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
35 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information