Available only in PRO Edition
Since 4.0
The widget is available in the Webix Pro edition.
DateRange is a UI-related widget based on Calendar and inherited from Layout.
This interactive tool includes several calendars and allows selecting a date range. You can also pick the time by using the timepicker at the bottom of the widget.
Related sample: DateRange: Basic
The code below will create the DateRange widget on the page:
webix.ui({
view:"daterange",
calendarCount:4,
icons:true,
timepicker:true,
value:{
start: new Date(),
end: webix.Date.add(new Date(), 2, "month")
}
});
Main properties
Setting and getting selected range
As a parameter, takes an object with the start and end properties that contain the start and end Date object of the range.
$$("daterange1").setValue({start:new Date(2016,9,30), end:new Date(2016,10,2)});
The returned object is non-formatted and consists of the start and end properties for start and end dates correspondingly.
$$("daterange1").getValue();
// -> {start: Sun Oct 30 2016 00:00:00 GMT+0300 (Russia Standard Time),
// end: Wed Nov 02 2016 00:00:00 GMT+0300 (Russia Standard Time)}
You can set specific configuration for all calendars of the DateRange widget. You should use the calendar property for this purpose.
It is an object that can contain the available Calendar properties:
webix.ui({
view:"daterange",
//calendar properties
calendar:{
weekNumber:true
}
});
DateRange can be shown by user request, e.g. when a user wants to pick a date range and time to fill the form. In this case, you can make use of the DateRangePicker control.
Thus, you won't have to initialize DateRange, as it will appear when you click the DateRangePicker icon.
webix.ui({
view:"form",
elements:[
{view:"daterangepicker", name: "default", label: 'Default'}
]
});
Related sample: DateRange Picker
You can add and customize the DateRange icons with the help of the icons parameter. The default icons are "Today" and "Clear".
The Today icon allows selecting the current date. The Clear icon removes date selection.
These icons are optional and specified in the icons array. The code below renders a daterange with "Today" and "Clear" icons:
webix.ui({
cols:[
{
view: 'daterange',
icons: true,
}
]
});
To hide the icons, you should set the icons property to false.
The default icons configuration is specified as follows:
webix.ui({
cols:[{
view:"daterange",
icons:[
//default "today" icon
{
template:function(){
return "<span class='webix_cal_icon_today webix_cal_icon'>"
+webix.i18n.calendar.today
+"</span>"
},
on_click:{
"webix_cal_icon_today":function(){
this.addToRange(new Date());
this.callEvent("onTodaySet",[this.getValue()]);
}
}
},
//default "clear" icon
{
template:function(){
return "<span class='webix_cal_icon_clear webix_cal_icon'>"
+webix.i18n.calendar.clear
+"</span>"
},
on_click:{
"webix_cal_icon_clear":function(){
this.setValue("");
this.callEvent("onDateClear", []);
}
}
}
]
}]
});
You can also redefine the default icons or add custom ones. For example, let's add the "Custom week" icon as shown below:
To add a custom icon, you need to specify it in the icons array. For our icon, the code can be as follows:
webix.ui({
cols:[
{
view:"daterange",
icons:[
{
template:function(){
return "<span class='webix_cal_icon_week webix_cal_icon'>Current week</span>"
},
on_click:{
"webix_cal_icon_week":function(){
this.setValue({
start:new Date(),
end:webix.Date.add(new Date(), 1, "week")
});
}
}
}]
}]
});
Related sample: DateRange: Custom Icons
Back to top