This is a migrated thread and some comments may be shown as answers.

How to apply Context Menu to specific Grid or ListView rows

2 Answers 207 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Paul Grothe
Top achievements
Rank 1
Paul Grothe asked on 04 Dec 2015, 08:50 PM

I am looking at the Context Menu demo at http://demos.telerik.com/aspnet-mvc/menu/context-menu

There are several buttons that are part of the context menu such as Reply, Reply All, Forward, etc.  However, they do not do anything so I do not see anything in the demo or anywhere else that demonstrates how you would wire this up to make a working application.

The first thing I am trying to figure out is if you wanted the reply button to work, how would you get the data from the row that the user is clicking on?

I tried something like this:

items.Add()
                .Text("Reply")
                .ImageUrl(Url.Content("~/content/web/toolbar/reply.png"))
                .Items(children =>
                {
                    children.Add().Text("Reply To Sender").ImageUrl(Url.Content("~/content/web/toolbar/reply.png")).Action("Reply", "WebMail", Model);
                    children.Add().Text("Reply To All").ImageUrl(Url.Content("~/content/web/toolbar/reply.png")).Action("ReplyAll", "WebMail", Model);
                });

Of course it doesn't work because Model would refer to the page's model.  How would I pass in data from the model that is applied on the row level?

The row level model for the demo is Kendo.Mvc.Examples.Models.WebMail.  Can you pass in this model or data from this model into the action link so that when the user clicks reply you can get the data for the mail item they clicked on?  Or if you accomplish this via javascript on the select event, is there an example somewhere of how that would be done?

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimiter Madjarov
Telerik team
answered on 07 Dec 2015, 01:00 PM

Hello Paul,

Indeed you could use the select event handler of the Context menu to retrieve the currently clicked item. Here is a short example that demonstrates the approach. The select event implementation is the same for the MVC widgets.

Regards,
Dimiter Madjarov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Paul Grothe
Top achievements
Rank 1
answered on 08 Dec 2015, 01:41 PM
Thanks Dimiter, that had the information I needed.  Setting the filter to the row element (filter: "tr[role='row']") was really key so that the row index would be returned in e.target
Tags
Menu
Asked by
Paul Grothe
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Paul Grothe
Top achievements
Rank 1
Share this question
or