简体   繁体   中英

How to access RadMenuItem added during runtime from Javascript / Jquery?

I am adding RadMenuItem to ContextMenu during runtime to Telerik RadFileExplorer like below: I want to know how i can access this radmenuitem button using JS/ Jquery. I want to enable/disable this button at client side:

RadMenuItem lastModifiedDate = new RadMenuItem("Last Modified Date");
lastModifiedDate.PostBack = false;               
lastModifiedDate.Value = "LastModifiedDate";
FileExplorer.TreeView.ContextMenus[0].Items.Add(lastModifiedDate);
FileExplorer.GridContextMenu.Items.Add(lastModifiedDate.Clone());

aspx:

 <telerik:RadFileExplorer runat="server" ID="FileExplorer" </telerik:RadFileExplorer>

Updated Code:

function attachHandlers(explorer, args) {
            var toolbar = explorer.get_toolbar();
            toolbar.add_buttonClicked(toolbarClicked);
            //support for grid context menu
            var gridContextMenu = explorer.get_gridContextMenu();  
            var menuItem = gridContextMenu.get_items().getItem(0).set_enabled(false);       
            gridContextMenu.add_itemClicked(gridContextMenuClicked); 
           
        }

 function gridContextMenuClicked(toolbar, args)
            {          
             var buttonValue = args.get_item().get_value();
             if (buttonValue == "LastModifiedDate")
             {
                //Do Something          
               
             } 
         }

function toolbarClicked(toolbar, args) {              
            if (args.get_item().get_value() == "folderCommand") 
            {
                // Do something
            }
        } 

    

Have you checked this article: https://docs.telerik.com/devtools/as.net-ajax/controls/fileexplorer/how-to/adding-custom-command-buttons

Basically, you subscribe to the OnClientLoad event of the radFileExplorer:

<telerik:RadFileExplorer RenderMode="Lightweight" ID="RadFileExplorer1" runat="server" OnClientLoad="attachHandlers">
</telerik:RadFileExplorer>

And in its event handler, you can get access to the context menu (and its items) like this:

<script>
function attachHandlers(explorer, args)
{
    //support for grid context menu
    var gridContextMenu = explorer.get_gridContextMenu();

    // disable the menu item if some conditions are met
    var menuItem = gridContextMenu.get_items().getItem(0).disable();
}
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM