doonot doonot - 1 month ago 12
Java Question

Showing menu when right clicking on a item of a tree view

I have a treeview and I wanted to add right click support for the different items. This is how I did it:

http://jsfiddle.net/doonot/xWjSz/

The menu is shown only for the first root module (after right click), but not for the rest of the root modules. Can you tell me what I have to change, in order to get the menu for all root modules?

Thanks a lot, I much appreciate your answer.

Answer Source

Hiya Please see this demo http://jsfiddle.net/hYJPv/1/ or http://jsfiddle.net/hYJPv/ (Fixed the issue) or diff approach here http://jsfiddle.net/UeqBk/for_Dooonot_from_Tats_innit/

on rightclick you will get an alert.

code

$(document).ready(function()
{
    // If you want to disable showing the context menu when right clicking
    // on the document, the code below would do the trick.
    $(document).bind("contextmenu",function(e)
    {
        alert('right click capture');
        return false;
    }); 

    var $tree = $("#tree").kendoTreeView(
    {
        select: function (event)
        {
            var $item = $(event.node);
            console.log( $item );
            alert( "selected" );
        }
    });


    // Find the item you want to select...
    var $selected = $('#selected');
    var $treePath = $selected.parentsUntil($tree, "li");

    var treeView = $tree.data('kendoTreeView');

    // Expand the tree in order to show the selected item
    treeView.expand( $treePath );

    // Gotta make both calls...
    treeView.select( $selected );
    treeView.trigger( 'select', {node: $selected} );
});
‚Äč