How do I get Attributes on server or client and change contextmenu items?

3 posts, 0 answers
  1. Steve White
    Steve White avatar
    26 posts
    Member since:
    Sep 2009

    Posted 12 Jan 2010 Link to this post

    In my CustomProvider I've added an Attribute to a FileItem and I'm displaying it in the Grid as a new column. This Attribute is based on business logic and shows the status of the File (checked-out/in). The column is called 'Status' and when checked out the row displays 'Locked'.

    Couple of things:
    1) how do I change the backbround on any grid rows that are 'Locked'? In other words how do I get the Attribute server-side?
    2) when the user selects the 'Locked' row I want to disable some elements in the Toolbar as well as the selected grid row contextmenu. Specifically, I want to grey-out the 'Delete' item in the contextmenu when a file is checked out.

    I have added 2 ToolBar items to the Explorer: 'Check Out' and 'Edit File'. If the selected item is already checked out, I want to change the 'Check Out' ToolBar item to 'Check In' (of course I'll need to run a security check to make sure the person who has the file checked out is the same as the current user).

    I've tried using ExplorerPopulated and I can correctly get the 'Locked' item as below, but I'm stuck on how to do 1) and 2) above.

        Private Sub DocumentExplorer_ExplorerPopulated(ByVal sender As ObjectByVal e As RadFileExplorerPopulatedEventArgs) 
            Dim items As List(Of Widgets.FileBrowserItem) = e.List 
            'Dim isGridPopulated As Boolean = items.Exists(Function(it) (TypeOf it Is Widgets.FileItem)) 
            'If (isGridPopulated) Then 
            Dim i As Integer = 0 
            While i < items.Count 
                If TypeOf items(i) Is Widgets.FileItem Then 
                    If items(i).Attributes("Status").ToString = "Locked" Then 
                        ' how do I get the contextmenu here so I can grey out some of the items? 
                        ' also the comment line below seems to have no effect!!!!!!!! 
                        'items(i).Permissions = Widgets.PathPermissions.Read 
                    End If 
                End If 
                i += 1 
            End While 
            'End If 
        End Sub 


  2. Fiko
    Fiko avatar
    1406 posts

    Posted 15 Jan 2010 Link to this post

    Hello Steve,

    In reference to your questions:
    1. I have already answered your question in this forum thread.
    2. You need to implement these steps in order to achieve the result:
      • Attach a handler to the OnClientItemSelected event of the RadFileExplorer. In the handler get reference to the RadToolBar control (oFileExplorer.get_toolbar()) and then use the RadToolBar's client-side API in order to change manipulate its buttons.
      • Attach a handler to the GridContextMenu's OnClientShown event as shown bellow:
        protected void Page_Load(object sender, EventArgs e)
            RadFileExplorer1.GridContextMenu.OnClientShown = "GridContextMenuShowing";

        The implementation of the handler:
        <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
            <script type="text/javascript">
                function GridContextMenuShowing(oMenu, args)
                    var oExplorer = $find("<%= RadFileExplorer1.ClientID %>");
                    var text = args.get_targetElement().innerText;
                    var dataItem = oExplorer.get_grid().get_masterTableView().get_selectedItems()[0].get_dataItem();
                    var s = new String();
                    if (dataItem["Status"] == "Locked")
                        var deleteMenuItem = oMenu.findItemByValue("Delete");

    I hope this helps.

    Sincerely yours,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Steve White
    Steve White avatar
    26 posts
    Member since:
    Sep 2009

    Posted 15 Jan 2010 Link to this post

    Thanks Fiko, I got it working on ItemSelected like this:

        function OnClientItemSelected(sender, args) { 
            var toolbar = sender.get_toolbar(); 
            var lockButton = toolbar.findItemByValue("Checkout"); 
            var item = args.get_item(); 
            var gridContextMenu = sender.get_gridContextMenu(); 
            var checkInItem = gridContextMenu.findItemByText("Check In"); 
            if (item.get_type() == Telerik.Web.UI.FileExplorerItemType.File) { 
                var oGrid = sender.get_grid(); 
                var mastertableView = oGrid.get_masterTableView(); 
                var selectedItems = mastertableView.get_selectedItems(); 
                var status = selectedItems[0].get_dataItem().Attributes["Status"]; 
                if (status == "Locked") { 
                else { 

    It's good to know there are other ways of getting Attributes, like you showed.
Back to Top