Kendo dynamic context menu

5 posts, 0 answers
  1. Anamika
    Anamika avatar
    124 posts
    Member since:
    Mar 2014

    Posted 22 Oct 2014 Link to this post

    Hello,
    I have a context menu displayed on right clicking kendo grid like this.
    @(Html.Kendo().ContextMenu()
            .Name("menuGrid")
            .Target("#Grid_ObjActivity")
            .Orientation(ContextMenuOrientation.Vertical)
            .Animation(animation =>
            {
                animation.Open(open =>
                {
                    open.Fade(FadeDirection.In);
                    open.Duration(500);
                });
            })
            .Items(items =>
            {

                items.Add()
                   .Text("Herunterladen")
                   .ImageUrl(Url.Content("~/Images/Download.png"));
                items.Add()
                  .Text("Löschen")
                  .ImageUrl(Url.Content("~/Images/Delete.png"));

            })
            .Events(e => e.Select("ContextClick"))

        )

    This is ok but i would like to have the items added dynamically depending on type of row clicked on grid. Each row in grid has a different type and right clicking show a different context menu with different action.

    How can i achieve this in my razor view.

    Thanks

    Anamika
  2. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 24 Oct 2014 Link to this post

    Hello Anamika,

    It is possible to use the setOptions method to set the dataSource option in the open event in order to show different items for each row. I created an example that demonstrates this scenario.


    Regards,
    Daniel
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Matt
    Matt avatar
    2 posts
    Member since:
    Nov 2014

    Posted 25 Mar 2015 in reply to Daniel Link to this post

    Hi Daniel,
    Any reason that, if I attempt to add a submenu to any of the dynamically created menu items, they won't appear?

    See example.  The parent item will only flicker, w/ the child item never appearing.

    Thanks.
  5. Matt
    Matt avatar
    2 posts
    Member since:
    Nov 2014

    Posted 25 Mar 2015 in reply to Daniel Link to this post

    Hi Daniel,
    Any reason that, when attempting to add a sub-menu to the dynamically created menu, it doesn't show?

    See example.  The parent menu will flicker when hovered over, but never shows it's children.

    Thanks.
  6. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 27 Mar 2015 Link to this post

    Hello Matt,

    Because the open event will be triggered when opening the sub items. You can check what is the item parameter before setting the items in order to avoid the problem e.g.
    function onOpen(e) {            
        if ($(e.item).is("li")) {
            return;
        }
        ...


    Regards,
    Daniel
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top
UI for ASP.NET MVC is VS 2017 Ready