javascript - Programmatically selecting a period of time in Fullcalendar -
i'm using fullcalendar in asp.net application.
if need select month, or year in fullcalendar, there method select. can pass startdate , enddate method , select period.
i need programmatically select weekends in month. need select week days in month.
how can achieve ?
what have tried far :
here demo.
so i've got answer (i needed similar , stumbled across when looking help). need think outside of fullcalendar , dom minute. fullcalendar uses momentjs, , come in handy (this wasn't included in example, , need following). first, need create array of either weekends or weekdays. did next 365 days (next full year).
example of array of weekends using momentjs:
$('#weekends').click(function() { weekend_array = new array(); var cal = $('#calendar').fullcalendar('getcalendar'); var curr_moment = moment(cal); for(k=0; k<365; k++) // next 365 days (next year) { // if weekend if(curr_moment.day()==0 || curr_moment.day()==6) // 0 being sunday, 6 being saturday { weekend_array.push(curr_moment.format("yyyy-mm-dd")); // format match data-date attr } curr_moment= curr_moment.add(1, 'days'); } console.log("number of weekend days: " + weekend_array.length); console.log(weekend_array); var dates = weekend_array highlightdates(dates); // dom restore checked dates on click $('#daymode').val('weekend'); }); so have weekend array next year. now, need highlight dates. issue click arrows view next month, selected dates cleared (since we're working in dom) created select dates in function can called weekdays, weekends or button click:
function highlightdates(dates){ $('.fc-day').each(function () { var thisdate = $(this).attr('data-date'); var td = $(this).closest('td'); if ($.inarray($(this).attr('data-date'), dates) !== -1) { td.addclass('fc-state-highlight'); } else { td.removeclass('fc-state-highlight'); } }); } i hope helps, working demo of everything. :d http://jsfiddle.net/z8jfx/255/
Comments
Post a Comment