Search results

Sort the Selected Files in ASP.NET Core Uploader control

You can sort the selected files in uploader control by using the selected event. Refer to the following example.

tagHelper
sorting.cs
@{
    var asyncSettings = new Syncfusion.EJ2.Inputs.UploaderAsyncSettings { SaveUrl = "https://ej2.syncfusion.com/services/api/uploadbox/Save", RemoveUrl = "https://ej2.syncfusion.com/services/api/uploadbox/Remove" };
}
<div class="control_wrapper">
    <ejs-uploader id="UploadFiles" selected="onSelect" asyncSettings="@asyncSettings">
    </ejs-uploader>
</div>
<script>
    var initial = true
    function onSelect(args) {
        if (initial) { initial = false; return; }
        args.isModified = true;
        var uploadObj = document.getElementById("UploadFiles").ej2_instances[0];
        let oldFiles = uploadObj.getFilesData();
        let filesData = args.filesData.concat(oldFiles);
        let modifiedData = sortFileList(filesData);
        args.modifiedFilesData = modifiedData;
    }

    function sortFileList(filesData) {
        let files = filesData;
        let fileNames = [];
        for (let i = 0; i < files.length; i++) {
            fileNames.push(files[i].name);
        }
        let sortedFileNames = fileNames.sort();
        let sortedFilesData = [];
        let index = 0;
        for (let name of sortedFileNames) {
            for (let i = 0; i < files.length; i++) {
                if (name === files[i].name) {
                    sortedFilesData.push(files[i]);
                }
            }
        }
        return sortedFilesData;
    }
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace EJ2CoreSampleBrowser.Controllers.TextBoxes
{
    public partial class UploaderController : Controller
    {
        public ActionResult DefaultFunctionalities()
        {
            return View();
        }
    }
}