I'm using Bootstrap Daterange Picker, which uses the following range options :
我正在使用Bootstrap Daterange Picker,它使用以下范围选项:
ranges: {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
},
But when the page loads the selected value is empty.
但是当页面加载时,所选值为空。
I want to select the range 'This Month' by default when the page loads, in bootstrap daterangepicker.
我想在bootstrap daterangepicker中加载页面时默认选择“本月”范围。
Jsfiddle Url: https://jsfiddle.net/renishar/wnuy6ypc/
Jsfiddle Url:https://jsfiddle.net/renishar/wnuy6ypc/
1 个解决方案
#1
4
Just set the startDate and endDate options to the respective value of This month.
只需将startDate和endDate选项设置为本月的相应值即可。
Also call cb function after initialise your datepicker to set the first value
初始化datepicker后调用cb函数来设置第一个值
See here : https://jsfiddle.net/wnuy6ypc/6
见这里:https://jsfiddle.net/wnuy6ypc/6
var dat_opt = {
...,
startDate: moment().startOf('month'),
endDate: moment().endOf('month'),
ranges: {
...
},
}
EDIT : After initialisation add jQuery('.daterange').trigger("apply.daterangepicker");
编辑:初始化后添加jQuery('。daterange')。trigger(“apply.daterangepicker”);
#1
4
Just set the startDate and endDate options to the respective value of This month.
只需将startDate和endDate选项设置为本月的相应值即可。
Also call cb function after initialise your datepicker to set the first value
初始化datepicker后调用cb函数来设置第一个值
See here : https://jsfiddle.net/wnuy6ypc/6
见这里:https://jsfiddle.net/wnuy6ypc/6
var dat_opt = {
...,
startDate: moment().startOf('month'),
endDate: moment().endOf('month'),
ranges: {
...
},
}
EDIT : After initialisation add jQuery('.daterange').trigger("apply.daterangepicker");
编辑:初始化后添加jQuery('。daterange')。trigger(“apply.daterangepicker”);