DevExtreme v26.1 is now available.

Explore our newest features/capabilities and share your thoughts with us.

Your search did not match any results.

Angular Range Selector - Calculation

The RangeSelector component allows you to handle changes of the currently selected range. For this purpose, the callback function is specified in the onValueChanged property. Select the function’s call mode using the «Handle Range Changes» drop-down menu.

Backend API
<div id="range-selector-demo"> <dx-range-selector id="range-selector" title="Calculate the Working Days Count in a Date Period" (onValueChanged)="onValueChanged($event)" > <dxo-range-selector-margin [top]="50"></dxo-range-selector-margin> <dxo-range-selector-scale [startValue]="startValue" [endValue]="endValue" minorTickInterval="day" tickInterval="month" > <dxo-range-selector-minor-tick [visible]="false" ></dxo-range-selector-minor-tick> <dxo-range-selector-marker [visible]="false"></dxo-range-selector-marker> <dxo-range-selector-label [customizeText]="customizeLabel" ></dxo-range-selector-label> </dxo-range-selector-scale> <dxo-range-selector-slider-marker [customizeText]="customizeSliderMarker"> </dxo-range-selector-slider-marker> <dxo-range-selector-behavior #beh valueChangeMode="onHandleMove"> </dxo-range-selector-behavior> </dx-range-selector> <h2>Working days count: {{ workingDaysCount.toFixed() }}</h2> <div class="options"> <div class="caption">Options</div> <div class="option"> <span>Handle Range Changes</span> <dx-select-box id="handle" [dataSource]="dataSource" [inputAttr]="{ 'aria-label': 'Value Change Mode' }" [width]="210" [(value)]="beh.valueChangeMode" ></dx-select-box> </div> </div> </div>
import { bootstrapApplication } from '@angular/platform-browser'; import { Component, enableProdMode, provideZoneChangeDetection } from '@angular/core'; import { DatePipe } from '@angular/common'; import { DxSelectBoxModule } from 'devextreme-angular'; import { DxRangeSelectorModule, DxRangeSelectorTypes } from 'devextreme-angular/ui/range-selector'; if (!/localhost/.test(document.location.host)) { enableProdMode(); } @Component({ selector: 'demo-app', templateUrl: './app.component.html', styleUrls: ['./app.component.css'], preserveWhitespaces: true, imports: [ DxRangeSelectorModule, DxSelectBoxModule, ], }) export class AppComponent { pipe = new DatePipe('en-US'); dataSource = ['onHandleMove', 'onHandleRelease']; workingDaysCount = 260; startValue = new Date(2011, 0, 1); endValue = new Date(2011, 11, 31); onValueChanged = (e: DxRangeSelectorTypes.ValueChangedEvent) => { const currentDate = new Date(e.value[0]); let workingDaysCount = 0; while (currentDate <= e.value[1]) { if (currentDate.getDay() > 0 && currentDate.getDay() < 6) { workingDaysCount += 1; } currentDate.setDate(currentDate.getDate() + 1); } this.workingDaysCount = workingDaysCount; }; customizeSliderMarker: DxRangeSelectorTypes.Properties['sliderMarker']['customizeText'] = ({ value }) => this.pipe.transform(value, 'dd EEEE'); customizeLabel: DxRangeSelectorTypes.Properties['scale']['label']['customizeText'] = ({ value }) => this.pipe.transform(value, 'MMM'); } bootstrapApplication(AppComponent, { providers: [ provideZoneChangeDetection({ eventCoalescing: true, runCoalescing: true }), ], });
::ng-deep #range-selector { height: 200px; } ::ng-deep h2 { text-align: center; } .options { padding: 20px; background-color: rgba(191, 191, 191, 0.15); position: absolute; bottom: 0; left: 0; right: 0; } .option { margin-top: 10px; } .caption { font-size: 18px; font-weight: 500; } .option > span { margin-right: 10px; } ::ng-deep .option > .dx-widget { display: inline-block; vertical-align: middle; }
<!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>