Hi, I have a ListView that is the target of a ContextMenu, when you right-click on a ListView item the ContextMenu opens. The next action is the user selecting a ContextMenu option. I am trying to access the data for the ListView item that was right clicked to open the ContextMenu.
I can do this if I bind a double-click event handler to the each ListView item and open the ContextMenu in JavaScript.
I figured that if you are opening a ContextMenu for a ListView item there should be a direct way to access that items data. Is there any way to do this with the right-click event or within the ContextMenu select event handler?
I can do this if I bind a double-click event handler to the each ListView item and open the ContextMenu in JavaScript.
@(Html.Kendo().ListView<SchedulerMVC.Models.EmployeeViewModel>()
.Name(
"listview-context-menu"
)
.TagName(
"div"
)
.ClientTemplateId(
"template"
)
.DataSource(dataSource =>
{
dataSource.Read(read => read.Action(
"Data"
,
"ContextMenu"
).Type(HttpVerbs.Get));
dataSource.PageSize(5);
})
.Selectable()
.Events(e =>
{
e.DataBound(
"setItemDoubleClickEvent"
);
})
)
@(Html.Kendo().ContextMenu()
.Name(
"context-menu"
)
.Target(
"#listview-context-menu"
)
.Orientation(ContextMenuOrientation.Vertical)
.Items(items =>
{
items.Add().Text(
"MenuItem"
).SpriteCssClasses(
"k-icon k-i-tick"
);
})
.Events(events => events.Select(
"selectContext"
))
)
// ListView DoubleClick
function setItemDoubleClickEvent() {
var items = $(
".product"
);
items.dblclick(function (e) {
var listView = $(
"#listview-context-menu"
).data(
"kendoListView"
);
var contextMenu = $(
"#context-menu"
).data(
"kendoContextMenu"
);
var uid = $(
this
).data(
"uid"
);
var item = listView.dataSource.getByUid(uid);
contextMenu.open(e.clientX, e.clientY);
});
}
I figured that if you are opening a ContextMenu for a ListView item there should be a direct way to access that items data. Is there any way to do this with the right-click event or within the ContextMenu select event handler?