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

ContextMenu for ListBox

1 Answer 35 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 18 Apr 2018, 02:58 AM

I have a number List Boxes with a single context menu that is shared across them.

The context menu correctly displays when I right click the list box item but it doesn't seem to set the target value of the Select or Open events.

The menu configuration is:

@(Html.Kendo().ContextMenu()
        .Name("listbox_contextmenu")
        .Target("[role=listbox]")
        .Filter("[role=option]")
        .Orientation(ContextMenuOrientation.Vertical)
        .Animation(animation =>
        {
            animation.Open(open =>
            {
                open.Fade(FadeDirection.In);
                open.Duration(500);
            });
        })
        .Items(items =>
        {
            items.Add().Text("Escalate to Management");
            items.Add().Separator(true);
            items.Add().Text("Email Allocated User");
        })
        .Events(events =>
        {
            events.Open("contextMenuOpen").Select("contextMenuSelect");
        })
)

 

The java script function do nothing at the moment:

function contextMenuOpen(e) {
    alert('e.item is ' + JSON.stringify($(e.item)));
    alert('e.target is ' + JSON.stringify($(e.target)));
}
function contextMenuSelect(e) {
    alert('e.item is ' + JSON.stringify($(e.item)));
    alert('e.target is ' + JSON.stringify($(e.target)));
}

 

I'm hoping you can point out what I'm doing wrong here.

Many Thanks,

Rob

1 Answer, 1 is accepted

Sort by
0
Neli
Telerik team
answered on 20 Apr 2018, 03:47 PM
Hi Rob,

When the ContextMenu is opened or an item is selected e.item and e.target are returned as an HtmlElements. I used the provided code and the elements are returned correctly on my side. (screencast)

If you need to convert the returned elements to Json you could take a look of the following article from StackOverflow.

Attached you will find a sample project. On open or select in the contextMenu, the e.item and e.target are console logged. 

Regards,
Neli
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Menu
Asked by
Rob
Top achievements
Rank 1
Answers by
Neli
Telerik team
Share this question
or