You can try it.
Required file:
jquery-1.11.3.js
bootstrap-datepicker.min.js
bootstrap-datepicker.css
bootstrap.min.css
HTML
<div class="container">
<div class="row">
<div class='col-md-3'>
Week Start <select id="cweek">
<option value='0'> 0 </option>
<option value='1'> 1 </option>
<option value='2'> 2 </option>
<option value='3'> 3 </option>
<option value='4'> 4 </option>
<option value='5'> 5 </option>
<option value='6'> 6 </option>
<option value='7'> 7 </option>
</select>
</div>
<div class='col-md-3'>
Copy <select name='cweek_number' id='cweek_number'>
<option value='1'> 1 Week </option>
<option value='2'> 2 Week </option>
<option value='3'> 3 Week </option>
<option value='4'> 4 Week </option>
</select> from
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="from_cal"></div>
</div>
<div class="row">
<div class="to_cal"></div>
</div>
</div>
</div>
js
var weekOfStart = 0;
var startDate;
var endDate;
var toCal_startDate;
var toCal_endDate;
var setNumberOfWeek = 1;
var from_cal = '.from_cal';
var to_cal = '.to_cal';
var obj = $(from_cal).datepicker({
weekStart:weekOfStart,
maxViewMode: 0,
onSelect: function (date) {
},
beforeShowDay: function(date)
{
var cssClass = '';
if(date >= startDate && date <= endDate)
cssClass = 'oui-state-hover';
return [true, cssClass];
}
// startDate: new Date()
});
$(from_cal).on('changeDate', function(evt) {
var date = evt.date;
var dayAdjustment = date.getDay() - weekOfStart;
if (dayAdjustment < 0) {
dayAdjustment += 7;
}
if(setNumberOfWeek > 1)
{
weekLast = 7*(setNumberOfWeek-1);
}
else {
weekLast = 0;
}
startDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - dayAdjustment);
endDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - dayAdjustment + (6+weekLast));
// console.log(startDate);
// console.log(endDate);
$(this).find('.active').closest('tr').addClass('oui-selected');
if(setNumberOfWeek > 1)
{
$(this).find('.active').closest('tr').nextAll().slice(0, (setNumberOfWeek-1)).addClass('oui-selected');
}
});
$(from_cal).on('mousemove', '.table-condensed tr', function () {
$(this).find('td').addClass('oui-state-hover');
if(setNumberOfWeek > 1)
{
$(this).nextAll().slice(0, (setNumberOfWeek-1)).find('td').addClass('oui-state-hover');
}
});
$(from_cal).on('mouseleave', '.table-condensed tr', function () {
$(this).find('td').removeClass('oui-state-hover');
$(this).nextAll().find('td').removeClass('oui-state-hover');
});
$(from_cal).find('td').on('click', function(){
console.log('ok');
});
obj.datepicker();
// To date Calendar code
var toCalObj = $(to_cal).datepicker({
weekStart:weekOfStart,
maxViewMode: 0,
// startDate: new Date()
});
toCalObj.datepicker();
$(to_cal).on('mousemove', '.table-condensed tr', function () {
$(this).find('td').addClass('kui-state-hover');
if(setNumberOfWeek > 1)
{
$(this).nextAll().slice(0, (setNumberOfWeek-1)).find('td').addClass('kui-state-hover');
}
});
$(to_cal).on('mouseleave', '.table-condensed tr', function () {
$(this).find('td').removeClass('kui-state-hover');
$(this).nextAll().find('td').removeClass('kui-state-hover');
});
$(to_cal).on('changeDate', function(evt) {
var date = evt.date;
var dayAdjustment = date.getDay() - weekOfStart;
if (dayAdjustment < 0) {
dayAdjustment += 7;
}
if(setNumberOfWeek > 1)
{
weekLast = 7*(setNumberOfWeek-1);
}
else {
weekLast = 0;
}
toCal_startDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - dayAdjustment);
toCal_endDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - dayAdjustment + (6+weekLast));
console.log(toCal_startDate);
console.log(toCal_endDate);
$(this).find('.active').closest('tr').addClass('oui-selected');
if(setNumberOfWeek > 1)
{
$(this).find('.active').closest('tr').nextAll().slice(0, (setNumberOfWeek-1)).addClass('oui-selected');
}
// console.log(date.getDay());
});
//comman code
$('#cweek').change(function()
{
weekOfStart = $('#cweek').val();
obj.datepicker('destroy');
toCalObj.datepicker('destroy');
obj.datepicker({weekStart:$('#cweek').val(),maxViewMode:0}).datepicker('update');
toCalObj.datepicker({weekStart:$('#cweek').val(),maxViewMode:0}).datepicker('update');
});
$('#cweek_number').change(function()
{
setNumberOfWeek = $('#cweek_number').val();
obj.datepicker('destroy');
toCalObj.datepicker('destroy');
obj.datepicker({weekStart:$('#cweek').val(),maxViewMode:0}).datepicker('update');
toCalObj.datepicker({weekStart:$('#cweek').val(),maxViewMode:0}).datepicker('update');
});
$('.table-condensed').addClass('table');
Screen Shot
JSFiddle link https://jsfiddle.net/shivamanhar/ddphp8jx/9/
<input type="week">
on the default browser datepicker should do this for you. – Mapes<input type="week">
is, it does not work in Firefox (tested with v40.0.3). – Grindelia