var calendar = app.calendar.create(...);
// after you have your ajax data
calendar.params.rangeClasses = [ ... new range classes ... ];
// call update
calendar.update();
I have problems with the format of the array for the calendar
app.request.postJSON('php/dates.php', function (data) {
var dates = [];
var i=1;
while (data[i] != null)
{ dates[i]= [ new Date(data[i]) ];
i++;
}
calendarInline.value = dates; // this line work
calendarInline.update();
});
values are added well, but if I change the line with the values to:
Thank You, Vladimir.
I tried… the array returned like this, but without success. Didn’t understand this magic.
After long manipulations, the code that works:
app.request.postJSON('php/dates.php', function (data) {
var i=1;
var dates = [];
while (data[i] != null) {
var date = new Date(data[i]);
dates[i-1] = new Date(date.getFullYear(), date.getMonth(), date.getDate());
i++;
}
calendarInline.params.rangesClasses = [{ cssClass: 'day-busy', range: dates }];
calendarInline.update();
});
I divide the date into parts and collect it again. Miracle
var data={1:"2018-03-28",2:"2018-03-07",3:"2018-03-08",4:"2018-03-10"};
var dates=[];
for(var k in data){
dates.push(data[k]); //=> need to convert after
//dates.push(new Date(data[k]));//=> no need to convert after
}
console.log(dates); //=> ["2018-03-28","2018-03-07","2018-03-08","2018-03-10"]
var convert=dates.map(function(d){return new Date(d)});
console.log(convert); //=>[Wed Mar 28 2018 02:00:00 GMT+0200 (CEST), Wed Mar 07 2018 01:00:00 GMT+0100 (CET), Thu Mar 08 2018 01:00:00 GMT+0100 (CET), Sat Mar 10 2018 01:00:00 GMT+0100 (CET)]
var calendar=app.calendar.create({
inputEl:'#app',
rangesClasses:[]
}).open();
function convert(d){
var i=d.split(/[-]/);
return new Date(i[0],i[1]-1,i[2]);
}
app.request.postJSON('php/dates.php',function(data){
var dates=[]
for (var k in data){
dates.push(convert(data[k]));
}
app.calendar.get().params.rangesClasses.push({
cssClass:'bg-color-green',
range:dates
});
app.calendar.get().update();
});
// kitchen-sink
var calendar=app.calendar.create({
inputEl:'#app',
rangesClasses:[]
}).open();
function convert(d){
var i=d.split(/[-]/);
return new Date(i[0],i[1]-1,i[2]);
}
setTimeout(function(){
var data={1:"2018-03-01",2:"2018-03-02",3:"2018-03-03",4:"2018-03-04"};
var dates=[]
for (var k in data){
dates.push(convert(data[k]));
}
app.calendar.get().params.rangesClasses.push({
cssClass:'bg-color-green',
range:dates
});
app.calendar.get().update();
},0);