This is a migrated thread and some comments may be shown as answers.

Grey out Custom toolbar control

1 Answer 61 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
Muhammad
Top achievements
Rank 1
Muhammad asked on 21 Mar 2014, 06:54 AM
I have created a custom toolbar button for download, everything is working fine, now I would lke to know how can we greyed out the custom button when no file is selected.

Just like delete button gets greyed out when no file is selected.

Thanks

1 Answer, 1 is accepted

Sort by
0
Ianko
Telerik team
answered on 25 Mar 2014, 12:04 PM
Hello Muhammad,

The logic for enabling and disabling on desired flag should be further implemented. There is no built-in functionality that exposes available approach for such mater. Note that you should handle this on each event that is changing the path of the Explorer (e.g. OnClientItemSelected).

The following is just an example for how to implement a logic that disables or enables the custom button according to the item's Delete permission:

ASP.NET
<telerik:RadFileExplorer runat="server" ID="RadFileExplorer1"
    OnClientLoad="attachHandlers"
    OnClientItemSelected="OnClientItemSelected"
    OnClientFolderChange="OnClientFolderChange">
            <Configuration ViewPaths="~/Images" DeletePaths="~/Images/Folder1" />
        </telerik:RadFileExplorer>
 
<script type="text/javascript">
    function toolbarClicked(toolbar, args) {
        var buttonValue = args.get_item().get_value();
        if (buttonValue == "testCommand")
            alert("test button clicked");
    }
 
    function attachHandlers(explorer, args) {
        var toolbar = explorer.get_toolbar();
        toolbar.add_buttonClicked(toolbarClicked);
 
        setButtonEnableState(explorer, explorer.get_selectedItem().get_permissions(), "testCommand");
    }
 
    function OnClientItemSelected(explorer, args) {
        setButtonEnableState(explorer, args.get_item().get_permissions(), "testCommand");
    }
 
    function OnClientFolderChange(explorer, args) {
        setButtonEnableState(explorer, args.get_item().get_permissions(), "testCommand");
    }
 
    function setButtonEnableState(explorer, curDirPermissions, command) {
        var permissions = Telerik.Web.UI.FileExplorerItemPermissions;
        if (typeof (curDirPermissions) == 'undefined' || curDirPermissions == null)
            curDirPermissions = explorer.get_currentPermissions();
        var button = explorer.get_toolbar().findItemByValue(command);
 
        button.set_enabled((curDirPermissions & permissions.Delete) != 0);
    }
</script>

C#
protected void Page_Load(object sender, EventArgs e)
{
    RadToolBarButton customButton = new RadToolBarButton("test");
    customButton.CssClass = "test_button";
    customButton.Value = "testCommand";
    RadFileExplorer1.ToolBar.Items.Add(customButton);
}


Regards,
Ianko
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
Tags
FileExplorer
Asked by
Muhammad
Top achievements
Rank 1
Answers by
Ianko
Telerik team
Share this question
or