如何更改 bootstrap datepicker 月视图以显示季度
how to change bootstrap datepicker month view to display quarters
我有一份申请,我必须提交月度报告和季度报告。我正在为月度报告使用 bootstrap-datepicker,并且我想在我的应用程序中保持相同的标准,因此如果我避免使用 select 框来显示季度,那就太好了。
这就是 bootstrap 在您处于月视图模式时提供的功能
这就是我想做的
selected 时,该季度的所有 3 个月都将 selected。
我检查了 bootstrap-datepicker.js
文件,我只看到 table 生成代码是:
DPGlobal.template = '<div class="datepicker">'+
'<div class="datepicker-days">'+
'<table class=" table-condensed">'+
DPGlobal.headTemplate+
'<tbody></tbody>'+
DPGlobal.footTemplate+
'</table>'+
'</div>'+
'<div class="datepicker-months">'+
'<table class="table-condensed">'+
DPGlobal.headTemplate+
DPGlobal.contTemplate+
DPGlobal.footTemplate+
'</table>'+
'</div>'+
'<div class="datepicker-years">'+
'<table class="table-condensed">'+
DPGlobal.headTemplate+
DPGlobal.contTemplate+
DPGlobal.footTemplate+
'</table>'+
'</div>'+
'</div>';
并且在 DPGlobal
变量中是模板:
headTemplate: '<thead>'+
'<tr>'+
'<th class="prev">«</th>'+
'<th colspan="5" class="datepicker-switch"></th>'+
'<th class="next">»</th>'+
'</tr>'+
'</thead>',
contTemplate: '<tbody><tr><td colspan="9"></td></tr></tbody>',
footTemplate: '<tfoot>'+
'<tr>'+
'<th colspan="7" class="today"></th>'+
'</tr>'+
'<tr>'+
'<th colspan="7" class="clear"></th>'+
'</tr>'+
'</tfoot>'
感谢所有帮助
您可以'invent'另一种语言:
$.fn.datepicker.dates['qtrs'] = {
days: ["Sunday", "Moonday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
daysShort: ["Sun", "Moon", "Tue", "Wed", "Thu", "Fri", "Sat"],
daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
months: ["Q1", "Q2", "Q3", "Q4", "", "", "", "", "", "", "", ""],
monthsShort: ["Jan Feb Mar", "Apr May Jun", "Jul Aug Sep", "Oct Nov Dec", "", "", "", "", "", "", "", ""],
today: "Today",
clear: "Clear",
format: "mm/dd/yyyy",
titleFormat: "MM yyyy",
/* Leverages same syntax as 'format' */
weekStart: 0
};
$('#example1').datepicker({
format: "MM yyyy",
minViewMode: 1,
autoclose: true,
language: "qtrs",
forceParse: false
}).on("show", function(event) {
$(".month").each(function(index, element) {
if (index > 3) $(element).hide();
});
});
与CSS:
.datepicker table tr td span {
width: 100%;
}
React Datepicker 有 Quarter Picker
选项
https://reactdatepicker.com/
稍作改进并解决了在输入中更改四分之一输入时出现的问题。
移除
.on("show", function(event) {
$(".month").each(function(index, element) {
if (index > 3) $(element).hide();
});
});
添加css
.datepicker-months table tbody tr td span:nth-child(1n + 5) {
background: red;
display: none;
}
我有一份申请,我必须提交月度报告和季度报告。我正在为月度报告使用 bootstrap-datepicker,并且我想在我的应用程序中保持相同的标准,因此如果我避免使用 select 框来显示季度,那就太好了。 这就是 bootstrap 在您处于月视图模式时提供的功能
这就是我想做的
selected 时,该季度的所有 3 个月都将 selected。
我检查了 bootstrap-datepicker.js
文件,我只看到 table 生成代码是:
DPGlobal.template = '<div class="datepicker">'+
'<div class="datepicker-days">'+
'<table class=" table-condensed">'+
DPGlobal.headTemplate+
'<tbody></tbody>'+
DPGlobal.footTemplate+
'</table>'+
'</div>'+
'<div class="datepicker-months">'+
'<table class="table-condensed">'+
DPGlobal.headTemplate+
DPGlobal.contTemplate+
DPGlobal.footTemplate+
'</table>'+
'</div>'+
'<div class="datepicker-years">'+
'<table class="table-condensed">'+
DPGlobal.headTemplate+
DPGlobal.contTemplate+
DPGlobal.footTemplate+
'</table>'+
'</div>'+
'</div>';
并且在 DPGlobal
变量中是模板:
headTemplate: '<thead>'+
'<tr>'+
'<th class="prev">«</th>'+
'<th colspan="5" class="datepicker-switch"></th>'+
'<th class="next">»</th>'+
'</tr>'+
'</thead>',
contTemplate: '<tbody><tr><td colspan="9"></td></tr></tbody>',
footTemplate: '<tfoot>'+
'<tr>'+
'<th colspan="7" class="today"></th>'+
'</tr>'+
'<tr>'+
'<th colspan="7" class="clear"></th>'+
'</tr>'+
'</tfoot>'
感谢所有帮助
您可以'invent'另一种语言:
$.fn.datepicker.dates['qtrs'] = {
days: ["Sunday", "Moonday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
daysShort: ["Sun", "Moon", "Tue", "Wed", "Thu", "Fri", "Sat"],
daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
months: ["Q1", "Q2", "Q3", "Q4", "", "", "", "", "", "", "", ""],
monthsShort: ["Jan Feb Mar", "Apr May Jun", "Jul Aug Sep", "Oct Nov Dec", "", "", "", "", "", "", "", ""],
today: "Today",
clear: "Clear",
format: "mm/dd/yyyy",
titleFormat: "MM yyyy",
/* Leverages same syntax as 'format' */
weekStart: 0
};
$('#example1').datepicker({
format: "MM yyyy",
minViewMode: 1,
autoclose: true,
language: "qtrs",
forceParse: false
}).on("show", function(event) {
$(".month").each(function(index, element) {
if (index > 3) $(element).hide();
});
});
与CSS:
.datepicker table tr td span {
width: 100%;
}
React Datepicker 有 Quarter Picker
选项
https://reactdatepicker.com/
稍作改进并解决了在输入中更改四分之一输入时出现的问题。
移除
.on("show", function(event) {
$(".month").each(function(index, element) {
if (index > 3) $(element).hide();
});
});
添加css
.datepicker-months table tbody tr td span:nth-child(1n + 5) {
background: red;
display: none;
}