InputDateRange
InputDateRange
Overview
The InputDateRange control extends the InputDate control and configures it to allow editing date ranges.
Features
The current range is from 4/10/2025 to 4/13/2025.
Settings
Description
This sample shows the basic usage of the InputDateRange control.
You may specify custom date ranges that the user can pick from, or they can use the multi-month calendar in the drop-down to select date ranges with the mouse or keyboard.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using MvcExplorer.Models; namespace MvcExplorer.Controllers { public partial class InputDateRangeController : Controller { public ActionResult Index() { ViewBag.DemoSettings = true ; return View(); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | @ { var today = DateTime.Now.Date; var rangeEnd = today.AddDays(3); } @section Scripts{ <script> // Get predefined date ranges function getPredefinedRanges() { let dt = wijmo.DateTime, now = new Date(); return { // Custom 'Custom Range' : null , // Days //'Today': [now, now], //'Yesterday': [dt.addDays(now, -1), dt.addDays(now, -1)], //'Tomorrow': [dt.addDays(now, +1), dt.addDays(now, +1)], // Weeks 'This Week' : [dt.weekFirst(now), dt.weekLast(now)], 'Last Week' : [dt.weekFirst(dt.addDays(now, -7)), dt.weekLast(dt.addDays(now, -7))], 'Next Week' : [dt.weekFirst(dt.addDays(now, +7)), dt.weekLast(dt.addDays(now, +7))], // Months 'This Month' : [dt.monthFirst(now), dt.monthLast(now)], 'Last Month' : [dt.monthFirst(dt.addMonths(now, -1)), dt.monthLast(dt.addMonths(now, -1))], 'Next Month' : [dt.monthFirst(dt.addMonths(now, +1)), dt.monthLast(dt.addMonths(now, +1))], // Years 'This Year' : [dt.yearFirst(now), dt.yearLast(now)], 'Last Year' : [dt.addYears(dt.yearFirst(now), -1), dt.addYears(dt.yearLast(now), -1)], 'Next Year' : [dt.addYears(dt.yearFirst(now), +1), dt.addYears(dt.yearLast(now), +1)], }; } function dateRangeChanged(s) { // Show date ranges let el = document.querySelector( '#showRange' ); el.innerHTML = wijmo.format( '@Html.Raw(Resources.InputDateRange.Index_ShowRange)' , s); } function monthCountChanged(sender) { let inputDateRange = wijmo.Control.getControl( "#demoControl" ); inputDateRange.monthCount = sender.value; } function weeksBeforeChanged(sender) { let inputDateRange = wijmo.Control.getControl( "#demoControl" ); inputDateRange.weeksBefore = sender.value; } function weeksAfterChanged(sender) { let inputDateRange = wijmo.Control.getControl( "#demoControl" ); inputDateRange.weeksAfter = sender.value; } function closeOnSelectionChanged(sender) { let inputDateRange = wijmo.Control.getControl( "#demoControl" ); inputDateRange.closeOnSelection = sender. checked ; } </script> } < style > .settings > div { margin-bottom: 0.5em; } .settings label { width: 10em; text-align: right; margin-right: 0.5em; float : left; font-weight: normal; line-height: 2em; } .settings input { height: 1.8em; } .settings .wj-inputnumber { width: 10em; } .wj-inputdate-dropdown > .wj-listbox { max-height: initial; } </ style > < p > < div id = "demoControl" ></ div > </ p > < p > < span id = "showRange" ></ span > </ p > @ (Html.C1().InputDateRange().Id( "demoControl" ) .AlwaysShowCalendar( true ) .CloseOnSelection( true ) .MonthCount(2) .WeeksBefore(0) .WeeksAfter(0) .PredefinedRanges( "getPredefinedRanges" ) .OnClientValueChanged( "dateRangeChanged" ) .OnClientRangeEndChanged( "dateRangeChanged" ) .Value(today) .RangeEnd(rangeEnd) ) @section Settings{ < div class = "settings" > < div > < label for = "monthCount" >Month Count</ label > @ (Html.C1().InputNumber().Id( "monthCount" ).Min(1).Step(1).Value(2).OnClientValueChanged( "monthCountChanged" ).Width(150)) </ div > < div > < label for = "weeksBefore" >Weeks Before</ label > @ (Html.C1().InputNumber().Id( "weeksBefore" ).Min(0).Step(1).Value(0).OnClientValueChanged( "weeksBeforeChanged" ).Width(150)) </ div > < div > < label for = "weeksAfter" >Weeks After</ label > @ (Html.C1().InputNumber().Id( "weeksAfter" ).Min(0).Step(1).Value(0).OnClientValueChanged( "weeksAfterChanged" ).Width(150)) </ div > < div > < label for = "closeOnSelection" >Close On Selection</ label > < input type = "checkbox" id = "closeOnSelection" onchange = "closeOnSelectionChanged(this)" checked /> </ div > </ div > } @section Summary{ < p > @Html .Raw(Resources.InputDateRange.Index_Text0)</ p > } @section Description{ < p > @Html .Raw(Resources.InputDateRange.Index_Text1)</ p > < p > @Html .Raw(Resources.InputDateRange.Index_Text2)</ p > } |