Get selected items and SelectionChanged event

Hy,

I have a custom toolbar button in FileManager. This button should be visible when any files are selected in FileManager and should be invisible when there are no selected files (similar as the built-in Delete button).

I try use fileSelect event:

 @{

     string[] items = new string[] { "Delete", "Download", "SortBy", "Refresh", "Selection", "View", "Details", "Custom" };
     string[] layout = new string[] { "SortBy", "View", "Refresh", "|", "Details", "|", "SelectAll" };
     string[] fileop = new string[] { "Delete", "Download", "|", "Details" };
 }
 <ejs-filemanager id="filemanager" view="Details"
                  created="onFileManagerCreated"
                  fileLoad="onFileLoad"
                  beforeSend="onBeforeSend"
                  toolbarClick="toolbarClick"
                  toolbarCreate="onCreate"
                  fileSelect="selectionChanged">
     <e-filemanager-ajaxsettings url="https://localhost:7042/api/FileManager/FileOperations"
                                 downloadUrl="https://localhost:7042/api/FileManager/Download"
                                 uploadUrl="https://localhost:7042/api/FileManager/Upload"
                                 getImageUrl="https://localhost:7042/api/FileManager/GetImage">
     </e-filemanager-ajaxsettings>
     <e-filemanager-toolbarsettings items="items">
     </e-filemanager-toolbarsettings>
     <e-filemanager-contextmenusettings file="fileop" layout="layout">
     </e-filemanager-contextmenusettings>
 </ejs-filemanager>


 <script>
     function selectionChanged(args) {
         const fileManagerInstance = $('#filemanager').get(0).ej2_instances[0];
         const selectedItems = fileManagerInstance.selectedItems;
         console.log("Selected Items:", selectedItems);
     }


The problem is, that the selectedItems collection is not updated now in this selectionChanged(args) method, so it returns the previous value (-1).

My question is:

- Which event can I use for get selected items count?

Thank you!


3 Replies

SA SureshRajan Alagarsamy Syncfusion Team December 6, 2024 12:30 PM UTC

Hi SZL,

We have reviewed your query and understand that you are looking to modify the toolbar items based on the selected items count in the File Manager component. After further review of the shared code snippet, we have prepared a sample incorporating the provided code. Upon testing the sample, we were able to correctly retrieve the updated selectedItems details within the fileSelect event handler.

We have attached the tested sample for your reference.

Sample: Attached as zip folder.

If the issue still persists, we recommend sharing the below requested details with us.
  1. Share an issue replication steps or issue replication video footage to better understand the reported problem.
  2. Share an issue replication sample with us or replicate the issue in attached sample.
These details will help us to validate the reported issue further and provide you with a prompt solution.

Regards,
Suresh.

Attachment: CoreFileManager_e91bf6e4.zip


SZ SZL replied to SureshRajan Alagarsamy December 6, 2024 02:31 PM UTC

Hi, thank you very much its working now in my project too.



SS Swetha Srikumar Syncfusion Team December 9, 2024 05:12 AM UTC

Glad to hear that the solution works for you.


Loader.
Up arrow icon