We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

is there any API to display number of items in a folder next to folder name in Navigation pane?

We want to display number of items/files/folders in a folder next to it's name in navigation pane. is there any API to acheive this? 

3 Replies

SA Shameer Ali Baig Sulaiman Ali Baig Syncfusion Team January 30, 2020 11:55 AM UTC

Hi Mahesh, 
 
Greetings from Syncfusion support. 
 
We have checked your requirement to display the files/folders count in navigation pane of EJ2 File Manager. To achieve your requirement, you can pass the additional parameter (file count) from server side and process the variable in client side using fileLoad() event. 
 
Refer the below code snippet for server side (controller side). 

  public ActionResult FileOperations(FileManagerDirectoryContent args) 
        { 
            switch (args.Action) 
            { 
                case "read": 
                    return Json( JsonConvert.SerializeObject(this.getFiles(args), new JsonSerializerSettings { ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() } })); 
            } 
            return null; 
        } 
public FileResponse getFiles(FileManagerDirectoryContent args) 
        { 
            FileResponse readResponse = new FileResponse(); 
            try 
            { 
                var value = operation.GetFiles(args.Path, args.ShowHiddenItems); 
                DirectoryContent cwd = new DirectoryContent(); 
                readResponse.CWD = JsonConvert.DeserializeObject<DirectoryContent>(JsonConvert.SerializeObject(value.CWD)); 
                readResponse.CWD.FolderCount = Directory.GetDirectories(this.basepath).Length.ToString(); 
                readResponse.CWD.FileCount = Directory.GetFiles(this.basepath).Length.ToString(); 
                readResponse.CWD.File_Folder = (Int32.Parse(readResponse.CWD.FolderCount) + Int32.Parse(readResponse.CWD.FileCount)).ToString(); 
                readResponse.Files = JsonConvert.DeserializeObject<IEnumerable<DirectoryContent>>(JsonConvert.SerializeObject(value.Files)); 
                foreach (DirectoryContent file in readResponse.Files) 
                { 
                    //Get the count of Folder 
                    file.FolderCount = !file.IsFile ? Directory.GetDirectories(this.basepath + file.FilterPath + file.Name).Length.ToString(): "0"; 
                    // Get the count of File 
                    file.FileCount = !file.IsFile ? Directory.GetFiles(this.basepath + file.FilterPath + file.Name).Length.ToString(): "0"; 
                    // Get the file and folder count added 
                    file.File_Folder = !file.IsFile ? (Int32.Parse(file.FolderCount) + Int32.Parse(file.FileCount)).ToString(): "0"; 
                } 
                readResponse.Details = value.Details; 
                readResponse.Error = value.Error; 
                return readResponse; 
            } 
            catch 
            { 
                ErrorDetails er = new ErrorDetails(); 
                return readResponse; 
            } 
        } 

Refer the client-side code. 
 
                  function fileLoad(args) { 
        if (args.module == "NavigationPane") { 
            // Display both the file and folder count 
            //var element = args.element.querySelector(".e-list-text").innerText + "(" + args.fileDetails.file_Folder + ")"; 
            // Display the Files Count only 
            var element = args.element.querySelector(".e-list-text").innerText + "(" + args.fileDetails.fileCount + ")"; 
            // Display the Folder Count Only. 
            //var element = args.element.querySelector(".e-list-text").innerText + "(" + args.fileDetails.folderCount + ")"; 
            args.element.querySelector(".e-list-text").innerText = element; 
        } 
    } 

For your reference, we have prepared a sample. In that sample, we have displayed a fileCount/folderCount. Refer the sample link below. 
 
 
Please let us know, if you need any further assistance. 
 
Regards, 
Shameer Ali Baig S. 



UN Unknown Syncfusion Team January 31, 2020 01:24 PM UTC

Thank you


SA Shameer Ali Baig Sulaiman Ali Baig Syncfusion Team February 3, 2020 04:18 AM UTC

Hi Mahesh, 
  
Welcome. Please, get back to us if you need any other assistance. 
  
Regards, 
Shameer Ali Baig S. 


Loader.
Up arrow icon