Thursday, July 11, 2013

How to disable some context menu items on Telerik TreeView

There is an event named "OnClientContextMenuShowing" for Rad Treeview that calls javascipt function and passes 2 arguments "sender, args".
The Args parameter contains The current selected TreeNode and Context Menu Items.
You can enable or disable any Context menu item based on any attributes for the Current Selected Tree Node.

Here is a code snippet for the javascript function that demonstrate how can you get the current select Tree Node and the Context menu Items and how can you disable the items.
function onClientContextMenuShowing(sender, args) {
            var treeNode = args.get_node();
            if (treeNode._attributes != undefined) {
                if (treeNode._attributes._keys[0] == 'BoolFlag') {
                    // 0 refer to the Context Menu item index
                    args.get_menu().get_items().getItem(0).set_enabled(false);
                    args.get_menu().get_items().getItem(1).set_enabled(false);
                    args.get_menu().get_items().getItem(3).set_enabled(false);
                }
            }
        }

Source: https://www.nilebits.com/blog/2011/09/how-to-disable-some-context-menu-items-on-telerik-treeview/

No comments:

Post a Comment