• 【Bootstrap】daterangepicker 插件的使用


    Configuration options 配置

    配置名称 英文描述
    startDate: (Date or string) The beginning date of the initially selected date range. If you provide a string, it must match the date format string set in your locale setting.
    endDate: (Date or string) The end date of the initially selected date range.
    minDate: (Date or string) The earliest date a user may select.
    maxDate: (Date or string) The latest date a user may select.
    maxSpan: (object) The maximum span between the selected start and end dates. Check off maxSpan in the configuration generator for an example of how to use this. You can provide any object the moment library would let you add to a date.
    showDropdowns: (true/false) Show year and month select boxes above calendars to jump to a specific month and year.
    minYear: (number) The minimum year shown in the dropdowns when showDropdowns is set to true.
    maxYear: (number) The maximum year shown in the dropdowns when showDropdowns is set to true.
    showWeekNumbers: (true/false) Show localized week numbers at the start of each week on the calendars.
    showISOWeekNumbers: (true/false) Show ISO week numbers at the start of each week on the calendars.
    timePicker: (true/false) Adds select boxes to choose times in addition to dates.
    timePickerIncrement: (number) Increment of the minutes selection list for times (i.e. 30 to allow only selection of times ending in 0 or 30).
    timePicker24Hour: (true/false) Use 24-hour instead of 12-hour times, removing the AM/PM selection.
    timePickerSeconds: (true/false) Show seconds in the timePicker.
    ranges: (object) Set predefined date ranges the user can select from. Each key is the label for the range, and its value an array with two dates representing the bounds of the range. Click ranges in the configuration generator for examples.
    showCustomRangeLabel: (true/false) Displays "Custom Range" at the end of the list of predefined ranges, when the ranges option is used. This option will be highlighted whenever the current date range selection does not match one of the predefined ranges. Clicking it will display the calendars to select a new range.
    alwaysShowCalendars: (true/false) Normally, if you use the ranges option to specify pre-defined date ranges, calendars for choosing a custom date range are not shown until the user clicks "Custom Range". When this option is set to true, the calendars for choosing a custom date range are always shown instead.
    opens: ('left'/'right'/'center') Whether the picker appears aligned to the left, to the right, or centered under the HTML element it's attached to.
    drops: ('down'/'up'/'auto') Whether the picker appears below (default) or above the HTML element it's attached to.
    buttonClasses: (string) CSS class names that will be added to both the apply and cancel buttons.
    applyButtonClasses: (string) CSS class names that will be added only to the apply button.
    cancelButtonClasses: (string) CSS class names that will be added only to the cancel button.
    locale: (object) Allows you to provide localized strings for buttons and labels, customize the date format, and change the first day of week for the calendars. Check off locale in the configuration generator to see how to customize these options.
    singleDatePicker: (true/false) Show only a single calendar to choose one date, instead of a range picker with two calendars. The start and end dates provided to your callback will be the same single date chosen.
    autoApply: (true/false) Hide the apply and cancel buttons, and automatically apply a new date range as soon as two dates are clicked.
    linkedCalendars: (true/false) When enabled, the two calendars displayed will always be for two sequential months (i.e. January and February), and both will be advanced when clicking the left or right arrows above the calendars. When disabled, the two calendars can be individually advanced and display any month/year.
    isInvalidDate: (function) A function that is passed each date in the two calendars before they are displayed, and may return true or false to indicate whether that date should be available for selection or not.
    isCustomDate: (function) A function that is passed each date in the two calendars before they are displayed, and may return a string or array of CSS class names to apply to that date's calendar cell.
    autoUpdateInput: (true/false) Indicates whether the date range picker should automatically update the value of the <input> element it's attached to at initialization and when the selected dates change.
    parentEl: (string) jQuery selector of the parent element that the date range picker will be added to, if not provided this will be 'body'

    Methods 方法

     // change the selected date range of that picker
    $('#daterange').data('daterangepicker').setStartDate('03/01/2014');
    $('#daterange').data('daterangepicker').setEndDate('03/31/2014');
    
    方法名 描述
    setStartDate(Date or string): Sets the date range picker's currently selected start date to the provided date
    setEndDate(Date or string): Sets the date range picker's currently selected end date to the provided date

    Event 事件

     $('#daterange').on('cancel.daterangepicker', function(ev, picker) {
            // do something, like clearing an input
     });
    
    事件名称 描述
    show.daterangepicker: Triggered when the picker is shown
    hide.daterangepicker: Triggered when the picker is hidden
    showCalendar.daterangepicker: Triggered when the calendar(s) are shown
    hideCalendar.daterangepicker: Triggered when the calendar(s) are hidden
    apply.daterangepicker: Triggered when the apply button is clicked, or when a predefined range is clicked
    cancel.daterangepicker: Triggered when the cancel button is clicked

    locale 和 range 配置
    $('#demo').daterangepicker({
        "singleDatePicker": true,
        "showDropdowns": true,
        "minYear": 2020,
        "maxYear": 2021,
        "showWeekNumbers": true,
        "showISOWeekNumbers": true,
        "timePicker": true,
        "timePicker24Hour": true,
        "timePickerSeconds": true,
        "autoApply": true,
        "maxSpan": {
            "days": 7
        },
        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')]
        },
        "locale": {
            "format": "MM/DD/YYYY",
            "separator": " - ",
            "applyLabel": "Apply",
            "cancelLabel": "Cancel",
            "fromLabel": "From",
            "toLabel": "To",
            "customRangeLabel": "Custom",
            "weekLabel": "W",
            "daysOfWeek": [
                "Su",
                "Mo",
                "Tu",
                "We",
                "Th",
                "Fr",
                "Sa"
            ],
            "monthNames": [
                "January",
                "February",
                "March",
                "April",
                "May",
                "June",
                "July",
                "August",
                "September",
                "October",
                "November",
                "December"
            ],
            "firstDay": 1
        },
        "alwaysShowCalendars": true,
        "startDate": "05/21/2020",
        "endDate": "05/27/2020"
    }, function(start, end, label) {
      console.log('New date range selected: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' (predefined range: ' + label + ')');
    });
    
  • 相关阅读:
    主流负载均衡器LVS、Nginx、HAProxy介绍
    shell脚本加密软件shc
    Linux系统安全配置相关
    Linux系统split对tar文件进行分片和压缩
    kubernetes组件详解和创建POD流程
    构建RPM之SPEC详解
    Python推荐系统框架:RecQ
    Python常用库-Psutil
    使用NLP从文章中自动提取关键字
    模糊字符串匹配:FuzzyWuzzy
  • 原文地址:https://www.cnblogs.com/-xk94/p/12973147.html
Copyright © 2020-2023  润新知