Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the option to show custom weeks #2185

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions daterangepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
firstDay: moment.localeData().firstDayOfWeek()
};

this.showCustomWeekNumbers = {};

this.callback = function() { };

//some state information
Expand Down Expand Up @@ -224,6 +226,12 @@
if (typeof options.showISOWeekNumbers === 'boolean')
this.showISOWeekNumbers = options.showISOWeekNumbers;

if (typeof options.showCustomWeekNumbers === 'object') {
this.showCustomWeekNumbers = options.showCustomWeekNumbers;
} else {
this.showCustomWeekNumbers = false;
}

if (typeof options.buttonClasses === 'string')
this.buttonClasses = options.buttonClasses;

Expand Down Expand Up @@ -616,6 +624,17 @@
this.calculateChosenLabel();
},

getCustomWeek: function (date) {
for (customWeeks in this.showCustomWeekNumbers) {
var startFirstWeek = moment(this.showCustomWeekNumbers[customWeeks][0]).startOf('week');
var endLastWeek = moment(this.showCustomWeekNumbers[customWeeks][1]).endOf('week');
if (date.isBetween(startFirstWeek, endLastWeek)) {;
return customWeeks + (date.diff(startFirstWeek, 'week') + 1);
}
}
return '';
},

renderCalendar: function(side) {

//
Expand Down Expand Up @@ -695,7 +714,7 @@
html += '<tr>';

// add empty cell for week number
if (this.showWeekNumbers || this.showISOWeekNumbers)
if (this.showWeekNumbers || this.showISOWeekNumbers || this.showCustomWeekNumbers)
html += '<th></th>';

if ((!minDate || minDate.isBefore(calendar.firstDay)) && (!this.linkedCalendars || side == 'left')) {
Expand Down Expand Up @@ -750,7 +769,7 @@
html += '<tr>';

// add week number label
if (this.showWeekNumbers || this.showISOWeekNumbers)
if (this.showWeekNumbers || this.showISOWeekNumbers || this.showCustomWeekNumbers)
html += '<th class="week">' + this.locale.weekLabel + '</th>';

$.each(this.locale.daysOfWeek, function(index, dayOfWeek) {
Expand Down Expand Up @@ -778,6 +797,9 @@
html += '<td class="week">' + calendar[row][0].week() + '</td>';
else if (this.showISOWeekNumbers)
html += '<td class="week">' + calendar[row][0].isoWeek() + '</td>';
else if (this.showCustomWeekNumbers) {
html += '<td class="week">' + this.getCustomWeek(calendar[row][0]) + '</td>'
}

for (var col = 0; col < 7; col++) {

Expand Down
17 changes: 16 additions & 1 deletion demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ <h1 style="margin: 0 0 20px 0">Configuration Builder</h1>

<div class="checkbox">
<label>
<input type="checkbox" id="timePicker" checked="checked"> timePicker
<input type="checkbox" id="showCustomWeekNumbers"> showCustomWeekNumbers (with example predefined ranges)
</label>
</div>

<div class="checkbox">
<label>
<input type="checkbox" id="timePicker"> timePicker
</label>
</div>

Expand Down Expand Up @@ -268,6 +274,15 @@ <h4>Configuration</h4>
if ($('#showWeekNumbers').is(':checked'))
options.showWeekNumbers = true;

if ($('#showCustomWeekNumbers').is(':checked')) {
options.showCustomWeekNumbers = {
'T1W': ['01/27/2021', '04/01/2021'],
'T2W': ['04/19/2021', '06/25/2021'],
'T3W': ['07/12/2021', '09/17/2021'],
'T4W': ['10/04/2021', '12/17/2021']
}
}

if ($('#showISOWeekNumbers').is(':checked'))
options.showISOWeekNumbers = true;

Expand Down