Kendo UI Context Menu mention to exclude element in filter

1.4k Views Asked by At

I'm using Kendo UI Context Menu in Kendo UI Grid (the JavaScript one not MVC). It provides a filter attribute using which I'm making the context menu to open when user selects a row of grid. Now I need to add a link in a cell of grid using template which I have done but on click of that link I need a JavaScript function to run instead of opening context menu. Below is the snip showing rows and blue link which instead of calling JavaScript function is opening Context Menu. The context menu is set to open on left click instead of right because client wanted it to be like this for iPad.

Rows, Link and Context Menu

Is there anyway to bypass context menu from opening if that link is clicked, may be best would be to exclude the link or anchor tag while mentioning filter property of context menu. I have mentioned menu like this:

$("#menu").kendoContextMenu({
 showOn: "click",
 orientation: "vertical",
 target: "#mainGrid",
 filter: "td[role='gridcell']",
});
1

There are 1 best solutions below

1
On BEST ANSWER

The click itself happens in the anchor element first, then it propagates to the td element, which calls the menu. So you can prevent the event to trigger the td inside the a event:

$("#mainGrid").on("click", "a", function(e) {
    e.stopPropagation();
}); 

stopPropagation() will keep the anchor job but will prevent other elements over the anchor to trigger their events. This code will work for any anchor in your grid.

Demo