admin管理员组文章数量:1315336
I'm using Bootstrap Daterange Picker, which uses the following range options :
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.
Jsfiddle Url: /
I'm using Bootstrap Daterange Picker, which uses the following range options :
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.
Jsfiddle Url: https://jsfiddle/renishar/wnuy6ypc/
Share Improve this question asked Dec 6, 2016 at 10:34 ReNiSh ARReNiSh AR 2,8522 gold badges33 silver badges43 bronze badges 3-
1
Set the startDate and endDate options to the respective value of
This month
. Call cb function after initialise your datepicker to set the first value => jsfiddle/wnuy6ypc/6 – Fefux Commented Dec 6, 2016 at 10:55 - wow, thank you, can u post it as answer. – ReNiSh AR Commented Dec 6, 2016 at 11:07
- also 1 need is there any way to call: 'apply.daterangepicker' event in startup – ReNiSh AR Commented Dec 6, 2016 at 11:07
1 Answer
Reset to default 7Just set the startDate and endDate options to the respective value of This month.
Also call cb function after initialise your datepicker to set the first value
See here : https://jsfiddle/wnuy6ypc/6
var dat_opt = {
...,
startDate: moment().startOf('month'),
endDate: moment().endOf('month'),
ranges: {
...
},
}
EDIT : After initialisation add jQuery('.daterange').trigger("apply.daterangepicker");
本文标签: javascriptSelecting 39This Month39 range by default in bootstrap daterangepickerStack Overflow
版权声明:本文标题:javascript - Selecting 'This Month' range by default in bootstrap daterangepicker - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741976780a2408169.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论