-
AI-powered Extensions
-
Data Grid
-
Tree List
-
Chat
-
HTML Editor
-
Form
-
-
Data Grids / Data Management
-
Data Grid
- Overview
-
Data Binding
-
Filtering
- Sorting
-
Editing
-
Grouping
-
Selection
- Focused Row
- Paging
-
Scrolling
-
Columns
- AI Assistant
-
Master-Detail
-
Data Summaries
-
Drag & Drop
-
Export to PDF
-
Export to Excel
- Appearance
-
Customization
- State Persistence
-
Adaptability
-
Keyboard Navigation
- Right-To-Left Support
-
Tree List
- Overview
-
Data Binding
-
Filtering
- Sorting
-
Editing
-
Selection
- Focused Row
- Paging
-
Columns
- Drag & Drop
- State Persistence
- Adaptability
-
Keyboard Navigation
-
Card View
-
Pivot Grid
- Overview
-
Data Binding
-
Field Management
-
Data Summaries
- Drill Down
- Filtering
-
Scrolling
-
Export to Excel
- Chart Integration
- Customization
- State Persistence
-
Filter Builder
-
-
Data Visualization
-
Charts
- Overview
-
Data Binding
-
Common Concepts
-
Axis
-
Aggregation
-
Tooltips
-
Selection
-
Customization
-
Zooming
-
Export
-
-
Area Charts
-
Bar Charts
- Bullet Charts
-
Doughnut Charts
-
Financial Charts
-
Funnel and Pyramid Charts
-
Line Charts
- Pareto Chart
-
Pie Charts
-
Point Charts
-
Polar and Radar Charts
-
Range Charts
- Sankey Chart
-
Sparkline Charts
-
Tree Map
-
Gauges
- Overview
-
Runtime update
-
Bar Gauge
-
Circular Gauge
-
Linear Gauge
-
Diagram
- Overview
-
Data Binding
-
Featured Shapes
-
Custom Shapes
-
Document Capabilities
-
User Interaction
- UI Customization
- Adaptability
-
-
Scheduling / Planning
-
Scheduler
- Overview
-
Data Binding
-
Views
-
Appointments
-
Timetable
- Editing
-
Grouping
- Virtual Scrolling
- Drag & Drop
-
Customization
- Adaptability
-
Gantt
- Overview
- Data Binding
-
Filtering
- Sorting
- Strip Lines
- Export to PDF
- Validation
-
Customization
-
-
Messaging
-
WYSIWYG Editor
-
Forms
-
Data Editors
- Overview
-
Common Concepts
-
Calendar
- Check Box
- Color Box
-
Date Box
-
Date Range Box
-
Number Box
- Radio Group
-
Range Selector
- Range Slider
- Slider
- Switch
- Text Area
- Text Box
-
Drop-Downs
- Autocomplete
-
Drop Down Box
-
Select Box
-
Tag Box
-
Lookup
-
Buttons
-
File Upload / File Management
-
File Manager
- Overview
-
File System Types
-
Customization
-
File Uploader
-
-
Popup and Notifications
-
Navigation
- Overview
- Accordion
-
Action Sheet
-
Context Menu
-
Menu
- Multi View
-
Drawer
-
Tab Panel
-
Tabs
-
Toolbar
-
Stepper
- Pagination
-
List
-
Tree View
- Right-to-Left Support
-
Layout
-
Tile View
- Splitter
-
Gallery
- Scroll View
- Box
- Responsive Box
-
-
Interactive Wrappers
-
Sortable
- Resizable
-
-
Progress Indicators
-
Maps
- Overview
-
Map
-
Vector Map
-
Data Binding
- Multiple Layers
-
Markers
- Legend
-
Zooming and Panning
-
Customization
-
-
Localization
Related Demos:
Your search did not match any results.
Angular File Uploader - Custom Drop Zone
The FileUploader component supports the drag-and-drop functionality to upload files.
In this demo, the dropZone property specifies the HTML element in which you can drag and drop files for upload. The dropZoneEnter and dropZoneLeave events allow you to customize the drop zone when the mouse pointer enters and leaves this zone while dragging the file.
Backend API
<div class="widget-container flex-box">
<span>Profile Picture</span>
<div
id="dropzone-external"
class="flex-box"
[class]="isDropZoneActive ? 'dropzone-active' : null"
>
@if (imageSource) {
<img id="dropzone-image" [src]="imageSource" alt="" />
} @if (textVisible) {
<div id="dropzone-text" class="flex-box">
<span>Drag & Drop the desired file</span>
<span>…or click to browse for a file instead.</span>
</div>
}
<dx-progress-bar
#uploadProgress
[min]="0"
[max]="100"
width="30%"
[showStatus]="false"
[visible]="progressVisible"
[value]="progressValue"
></dx-progress-bar>
</div>
<dx-file-uploader
#fileUploader
dialogTrigger="#dropzone-external"
dropZone="#dropzone-external"
[multiple]="false"
[allowedFileExtensions]="allowedFileExtensions"
uploadMode="instantly"
uploadUrl="https://js.devexpress.com/Demos/NetCore/FileUploader/Upload"
[visible]="false"
(onDropZoneEnter)="onDropZoneEnter($event)"
(onDropZoneLeave)="onDropZoneLeave($event)"
(onUploaded)="onUploaded($event)"
(onProgress)="onProgress($event)"
(onUploadStarted)="onUploadStarted()"
></dx-file-uploader>
</div>
import { bootstrapApplication } from '@angular/platform-browser';
import {
ChangeDetectorRef, Component, enableProdMode, provideZoneChangeDetection,
} from '@angular/core';
import { DxFileUploaderModule, DxProgressBarModule } from 'devextreme-angular';
import 'anti-forgery';
if (!/localhost/.test(document.location.host)) {
enableProdMode();
}
@Component({
selector: 'demo-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
imports: [
DxFileUploaderModule,
DxProgressBarModule,
],
})
export class AppComponent {
isDropZoneActive = false;
imageSource = '';
textVisible = true;
progressVisible = false;
progressValue = 0;
allowedFileExtensions: string[] = ['.jpg', '.jpeg', '.gif', '.png'];
constructor(private changeDetectorRef: ChangeDetectorRef) {
this.onDropZoneEnter = this.onDropZoneEnter.bind(this);
this.onDropZoneLeave = this.onDropZoneLeave.bind(this);
this.onUploaded = this.onUploaded.bind(this);
this.onProgress = this.onProgress.bind(this);
this.onUploadStarted = this.onUploadStarted.bind(this);
}
onDropZoneEnter({ component, dropZoneElement, event }) {
if (dropZoneElement.id === 'dropzone-external') {
const items = event.originalEvent.dataTransfer.items;
const allowedFileExtensions = component.option('allowedFileExtensions');
const draggedFileExtension = `.${items[0].type.replace(/^image\//, '')}`;
const isSingleFileDragged = items.length === 1;
const isValidFileExtension = allowedFileExtensions.includes(draggedFileExtension);
if (isSingleFileDragged && isValidFileExtension) {
this.isDropZoneActive = true;
}
}
}
onDropZoneLeave(e) {
if (e.dropZoneElement.id === 'dropzone-external') { this.isDropZoneActive = false; }
}
onUploaded(e) {
const file = e.file;
const fileReader = new FileReader();
fileReader.onload = () => {
this.isDropZoneActive = false;
this.imageSource = fileReader.result as string;
this.changeDetectorRef.detectChanges();
};
fileReader.readAsDataURL(file);
this.textVisible = false;
this.progressVisible = false;
this.progressValue = 0;
}
onProgress(e) {
this.progressValue = e.bytesLoaded / e.bytesTotal * 100;
}
onUploadStarted() {
this.imageSource = '';
this.progressVisible = true;
}
}
bootstrapApplication(AppComponent, {
providers: [
provideZoneChangeDetection({ eventCoalescing: true, runCoalescing: true }),
],
});
::ng-deep #dropzone-external {
width: 350px;
height: 350px;
background-color: rgba(0,0,0,0.08);
border-width: 2px;
border-style: dashed;
padding: 10px;
border-color: var(--dx-color-border);
}
::ng-deep #dropzone-external > * {
pointer-events: none;
}
::ng-deep #dropzone-external.dropzone-active {
border-style: solid;
border-color: var(--dx-color-primary);
}
::ng-deep .widget-container > span {
font-size: 22px;
font-weight: bold;
margin-bottom: 16px;
}
::ng-deep #dropzone-image {
max-width: 100%;
max-height: 100%;
}
::ng-deep #upload-progress {
display: flex;
margin-top: 10px;
}
::ng-deep .flex-box {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>DevExtreme Demo</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0" />
<link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/26.1.5/css/dx.light.css" />
</head>
<body class="dx-viewport">
<div class="demo-container">
<demo-app>Loading...</demo-app>
</div>
<script src="https://cdn.jsdelivr.net/npm/zone.js@0.16.2/bundles/zone.umd.js"></script>
<script src="./bundle.js" type="module"></script>
</body>
</html>
Allowed file extensions: .jpg, .jpeg, .gif, .png
Maximum file size: 4 MB