show custom toolbar button only when one item is selected

I have a custom toolbar button that performs an action that only works on one file. How can I have the toolbar button automatically hide when zero or 2+ items are selected, and show when 1 item is selected?


1 Reply

SM Shalini Maragathavel Syncfusion Team August 20, 2021 11:59 AM UTC

Hi Jay, 

Greetings from Syncfusion support.
 
Based on your query, we could understand that you need to show/hide the custom toolbar item based on the selected files count in the File Manager. You can achieve your requirement by setting the display property as none/block to the custom toolbar item based on the selected files count in fileSelect event of File Manager component as demonstrated in the below code snippet, 
 
 
Index.js

var fileObject = new ej.filemanager.FileManager({
 
            ajaxSettings: { 
            }, 
            toolbarSettings:{items: ['Custom']}, 
            toolbarClick:toolbarClick, 
            fileSelect:fileSelection 
    }); 
    // event for custom toolbar item 
function toolbarClick(args) { 
    if (args.item.text === 'Custom') { 
        alert('You have clicked custom toolbar item') 
    } 
} 
function fileSelection(args){ 
    if(fileObject.getSelectedFiles().length!=1){   
    //to hide the custom toolbar when more than one files are selected  
        document.getElementById(this.element.id+'_tb_custom').style.display="none"; 
    } 
    else{ 
  //to show the custom toolbar when only one file is selected 
        document.getElementById(this.element.id+'_tb_custom').style.display="block";   
    } 
   
}
--------------------------------------------------------------
Index.html

   <style>
 
  .e-filemanager #filemanager_tb_custom { 
                display: none;  //to hide the custom toolbar at initial rendering. 
            } 
    </style> 
 

Please find the below sample for your reference.
 
  
                  
Please get back to us if you need any further assistance.  
  

Regards, 
 
Shalini M. 


Loader.
Up arrow icon