I have a bootstrap daterangepicker in which I would like to make a series of conditions so that according to the dates in the database they are blocked and change color. My problem is that I'm not sure how to tell the DateRangePicker to take the dates of the array I receive from the php without it disappearing from the web and leaving a white box.
EDIT: my json that I receive in the view, the datepicker does not interpret it correctly
My daterangepicker is this:
<script>
// Aqui recibimos el json de PHP
var daysData = <?= $data) ?>;
$( function() {
$( 'input[name="datefilter"]').daterangepicker({
isInvalidDate: function(date) {
var year = date.year();
var month = date.month() + 1;
var day = date.date();
var valid = false; // default css class
if(typeof daysData[year] != 'undefined'){
if(typeof daysData[year][month] != 'undefined'){
if(typeof daysData[year][month][day] != 'undefined'){
console.log(year, month, day, daysData[year][month][day]);
dayData = daysData[year][month][day];
//if (dayData['news'] == true){
valid = true;
//}
}
}
}
return valid;
},
isCustomDate: function(date) {
var year = date.year();
var month = date.month() + 1;
var day = date.date();
var daySettings = 'day_green'; // default css class
if(typeof daysData[year] != 'undefined'){
if(typeof daysData[year][month] != 'undefined'){
if(typeof daysData[year][month][day] != 'undefined'){
console.log(year, month, day, daysData[year][month][day]);
dayData = daysData[year][month][day];
//if (dayData['news'] == true){
daySettings = 'day_red';
//}
}
}
}
return daySettings;
},
});
</script>
The $ data variable I receive from php has the following json (already transforms it in the controller)
[{
"area_id": null,
"title": "Comida",
"start": "2018-08-13 00:00:00"
}, {
"area_id": null,
"title": "Conferencia",
"start": "2018-08-19 00:00:00"
}, {
"area_id": null,
"title": "Meeting",
"start": "2018-08-27 00:00:00"
}, {
"area_id": null,
"title": "Cumplea\u00f1os",
"start": "2018-08-05 00:00:00"
}, {
"area_id": null,
"title": "Fecha disponible",
"start": "2018-08-14 00:00:00"
}, {
"area_id": null,
"title": "Fechas No Disponibles",
"start": "2018-07-30 00:00:00"
}, {
"area_id": null,
"title": "Consultar Fecha",
"start": "2018-08-06 00:00:00"
}, {
"area_id": 1,
"title": "vacacion",
"start": "2018-08-17 00:00:00"
}, {
"area_id": 1,
"title": "vacacion",
"start": "2018-08-17 00:00:00"
}, {
"area_id": 1,
"title": "vacacion",
"start": "2018-08-17 00:00:00"
}, {
"area_id": 1,
"title": "vacacion",
"start": "2018-08-17 00:00:00"
}, {
"area_id": 1,
"title": "vacacion",
"start": "2018-08-17 00:00:00"
}, {
"area_id": 1,
"title": "vacacion",
"start": "2018-08-17 00:00:00"
}, {
"area_id": 1,
"title": "vacacion",
"start": "2018-08-17 00:00:00"
}, {
"area_id": 1,
"title": "vacacion",
"start": "2018-08-17 00:00:00"
}, {
"area_id": 1,
"title": "vacacion",
"start": "2018-08-17 00:00:00"
}, {
"area_id": 1,
"title": "vacacion",
"start": "2018-08-17 00:00:00"
}, {
"area_id": 1,
"title": "vacacion",
"start": "2018-08-17 00:00:00"
}, {
"area_id": 1,
"title": "vacacion",
"start": "2018-08-17 00:00:00"
}, {
"area_id": 1,
"title": "vacacion",
"start": "2018-08-17 00:00:00"
}, {
"area_id": 1,
"title": "vacacion",
"start": "2018-08-17 00:00:00"
}, {
"area_id": 1,
"title": "vacacion",
"start": "2018-08-17 00:00:00"
}]
How can I use this json to have all the dates that come from bd as they are occupied, and mark them with another color in the DateRangePicker? I was thinking about taking data from the array in php and passing it on just the date, but I want to keep the area_id to make conditions and put different colors.
Thanks in advance.