0

I've been working with w2ui and grids, and I can't seem to figure out how to get the id of the context menu item clicked. I want to be able to assign different functions to each context menu item, but can't figure it out! I always have troubles with jquery, and this time is no different!

What I have currently is grabbing all of the row data fine. Have tried both onMenuClick and onClick directly on the menu items with no luck. Here is what I currently have written.

$('#grid').w2grid({
name: 'grid',
header: 'List of Names',
show: {
    toolbar: true,
    footer: true
},
records: users,
columns: [
    { field: 'recid', caption: 'ID', size: '50px', sortable: true, attr: 'align=center' },
    { field: 'lname', caption: 'Last Name', size: '30%', sortable: true, resizable: true },
    { field: 'fname', caption: 'First Name', size: '30%', sortable: true, resizable: true },
    { field: 'email', caption: 'Email', size: '40%', resizable: true },
    { field: 'sdate', caption: 'Start Date', size: '120px', resizable: true },
],
menu: [
    { id: 1, text: 'Select Item', icon: 'fa fa-star', onMenuClick: function(event){
        alert("button 1 clicked!");
    } },
    { id: 2, text: 'View Item', icon: 'fa fa-camera' }, 
    { id: 4, text: 'Delete Item', icon: 'fa fa-minus' }
],
searches: [
    { field: 'lname', caption: 'Last Name', type: 'text' },
    { field: 'fname', caption: 'First Name', type: 'text' },
    { field: 'email', caption: 'Email', type: 'text' },
],
sortData: [{ field: 'recid', direction: 'ASC' }],
onMenuClick: function(target, event) {
    var record = this.get(event.recid);
    var id = event.target;
    var menuid = target.id  //trying to get context menu id
    var fname = record.fname;
    var lname = record.lname;
    var email = record.email;
    event.onComplete = function () {
    alert("ID:" + id + "First Name: " + fname + "Last Name: " + lname + "Email: " + email +"menu ID: " + menuid);
    }
}
});

Any help would be greatly appreciated!

AndyRob7
  • 33
  • 1
  • 1
  • 5

1 Answers1

0

Figured it out! Thankfully didn't take too much time, but in order to pull the ID from the context menu item clicked you can use the following:

var menuid = event.menuItem.id;
AndyRob7
  • 33
  • 1
  • 1
  • 5