DevExtreme v24.1 is now available.

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

Your search did not match any results.

Use Range Selection for 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
$(() => { const rangeSelector = $('#range-selector').dxRangeSelector({ margin: { top: 50, }, scale: { startValue: new Date(2011, 0, 1), endValue: new Date(2011, 11, 31), minorTickInterval: 'day', tickInterval: 'month', minorTick: { visible: false, }, marker: { visible: false }, label: { format: 'MMM', }, }, behavior: { valueChangeMode: 'onHandleMove', }, sliderMarker: { format: 'dd EEEE', }, title: 'Calculate the Working Days Count in a Date Period', onValueChanged(e) { 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); } $('#workingDaysCount').html(workingDaysCount.toFixed()); }, }).dxRangeSelector('instance'); $('#handle').dxSelectBox({ dataSource: ['onHandleMove', 'onHandleRelease'], inputAttr: { 'aria-label': 'Value Change Mode' }, width: 210, value: 'onHandleMove', onValueChanged(data) { rangeSelector.option('behavior.valueChangeMode', data.value); }, }); });
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" 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" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script>window.jQuery || document.write(decodeURIComponent('%3Cscript src="js/jquery.min.js"%3E%3C/script%3E'))</script> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/24.1.4/css/dx.light.css" /> <script src="js/dx.all.js"></script> <link rel="stylesheet" type="text/css" href="styles.css" /> <script src="index.js"></script> </head> <body class="dx-viewport"> <div class="demo-container"> <div id="range-selector-demo"> <div id="range-selector"></div> <h2>Working days count: <span id="workingDaysCount">260</span></h2> <div class="options"> <div class="caption">Options</div> <div class="option"> <span>Handle Range Changes</span> <div id="handle"></div> </div> </div> </div> </div> </body> </html>
#range-selector { height: 200px; } 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; } .option > .dx-widget { display: inline-block; vertical-align: middle; }