How can I help you?
Drag and drop in EJ2 TypeScript File Manager component
30 Jan 20264 minutes to read
The File Manager component supports moving files and folders within the file system using drag-and-drop. Enable or disable this feature using the allowDragAndDrop property of the File Manager.
The following events are raised during drag-and-drop operations:
-
fileDragStart- Triggered when file or folder dragging starts. -
fileDragging- Triggered while the file or folder is being dragged. -
fileDragStop- Triggered when the file or folder is about to be dropped on the target. -
fileDropped- Triggered after the file or folder has been dropped.
import { FileManager, Toolbar, NavigationPane, DetailsView } from '@syncfusion/ej2-filemanager';
FileManager.Inject(Toolbar, NavigationPane, DetailsView)
let hostUrl: string = 'https://ej2-aspcore-service.azurewebsites.net/';
// initialize File Manager control and add custom item to contextmenu
let filemanagerInstance: FileManager = new FileManager({
ajaxSettings: {
url: hostUrl + 'api/FileManager/FileOperations',
getImageUrl: hostUrl + 'api/FileManager/GetImage',
uploadUrl: hostUrl + 'api/FileManager/Upload',
downloadUrl: hostUrl + 'api/FileManager/Download'
},
allowDragAndDrop: true, // allowDragAndDrop is false by default.
// File Manager's file drag start event
fileDragStart: onFileDragStart,
// File Manager's file dragging event
fileDragging: onFileDragging,
// File Manager's file drag stop event
fileDragStop: onFileDragStop,
// File Manager's file drag stop event
fileDropped: onFileDropped,
height: '380px'
});
// render initialized File Manager
filemanagerInstance.appendTo('#filemanager');
// File Manager's file drag start event function
function onFileDragStart(args: any) {
console.log("File drag start");
}
// File Manager's file drag stop event function
function onFileDragStop(args: any) {
console.log("File drag stop");
}
// File Manager's file dragging event function
function onFileDragging(args: any) {
console.log("File dragging");
}
// File Manager's file dropped event function
function onFileDropped(args: any) {
console.log("File dropped");
}<!DOCTYPE html>
<html lang="en">
<head>
<title>Essential JS 2 File Manager</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 File Manager Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/33.2.3/ej2-base/styles/fluent2.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/33.2.3/ej2-inputs/styles/fluent2.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/33.2.3/ej2-popups/styles/fluent2.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/33.2.3/ej2-buttons/styles/fluent2.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/33.2.3/ej2-splitbuttons/styles/fluent2.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/33.2.3/ej2-layouts/styles/fluent2.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/33.2.3/ej2-navigations/styles/fluent2.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/33.2.3/ej2-grids/styles/fluent2.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/33.2.3/ej2-filemanager/styles/fluent2.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id="container">
<div id="filemanager"></div>
</div>
</body>
</html>#container {
visibility: hidden;
}
#loader {
color: #008cff;
height: 40px;
width: 30%;
position: absolute;
top: 45%;
left: 45%;
}