2015-07-13 38 views
12

我有一個應用程序,我必須提交月度報告和季度報告。我爲月度報告使用了bootstrap-datepicker,並且我希望在應用程序中保持相同的標準,因此如果我避免使用選擇框來顯示宿舍,那將是非常好的。 這是當你在月視圖模式是什麼引導提供如何更改引導日期選擇器月視圖來顯示宿舍

Month View Bootstrap Datepicker

這就是我想要當它選擇做

Quarterly View

,所有3個月季度會被選中。

我檢查了bootstrap-datepicker.js文件,我只看到表生成代碼爲:

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">&#171;</th>'+ 
          '<th colspan="5" class="datepicker-switch"></th>'+ 
          '<th class="next">&#187;</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>' 

所有幫助表示讚賞

+1

是不是矯枉過正使用這個插件來選擇宿舍?畢竟一季度只是一年的數字和季度數字。如果是針對季度的本地化月份名稱顯示(如果Q1,Q2,Q3,Q4不夠好),那麼您可以使用moment.js,您可能已經使用了此功能並結合日期範圍 - 選擇器... – Jos

回答

6

你可以 '創造' 另一種語言:

$.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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Feb&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mar", "Apr&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;May&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Jun", "Jul&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Aug&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sep", "Oct&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Nov&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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%; 
} 

例子:http://jsfiddle.net/4mwk0d5L/1/

+0

我最終做了類似的事情,但你的方法更簡單。感謝你的回答 :) – xhulio

相關問題