how to change bootstrap datepicker month view to display quarters

前端 未结 3 430
情书的邮戳
情书的邮戳 2020-12-09 17:35

I have an application where i have to submit monthly reports and quarterly reports. I am using the bootstrap-datepicker for the monthly report, and I want to keep the same s

相关标签:
3条回答
  • 2020-12-09 18:12

    a litte improvement and fix a issue when changing quarter typing in the input.

    remove

    .on("show", function(event) {
      $(".month").each(function(index, element) {
      if (index > 3) $(element).hide();
      });
     });
    

    add css

     .datepicker-months table tbody tr td span:nth-child(1n + 5) {
     background: red;
     display: none;
     }
    
    0 讨论(0)
  • 2020-12-09 18:32

    You could 'invent' another language:

    $.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();
      });
    
    });
    

    With CSS:

    .datepicker table tr td span {
      width: 100%;
    }
    

    Example: http://jsfiddle.net/4mwk0d5L/1/

    0 讨论(0)
  • 2020-12-09 18:36

    React Datepikcer has Quarter Picker option https://reactdatepicker.com/

    0 讨论(0)
提交回复
热议问题