DatePicker JQUERY UI - Redial dates from a database

0

What I'm trying to do is highlight some dates, taken from a database, in a datepicker. After searching a lot on the internet it seems normal, but I can not get it ... any help will be welcome.

My codes:

//función para mostrar el calendario (datepicker jquery ui)
function calendario() {

var fechas = [];

//recuperar el idobra seleccionado
var idobra = $("#combo_obra").val();

$.ajax({
    url: "php/consulta_clientes.php",
    type: "post",
    data: {"idobra":idobra, "opcion":"remarcar"},
    success: function(respuesta) {

        var arrayRespuesta = JSON.parse(respuesta);

        for(var i = 0; i<arrayRespuesta.length; i++) {

            fechas[new Date (arrayRespuesta[i]["fecha"])] = new Date (arrayRespuesta[i]["fecha"]);
        }
        return fechas;
    }
})
console.log(fechas);

$('#calendario').datepicker({
    monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
    monthNamesShort: ['Ene','Feb','Mar','Abr', 'May','Jun','Jul','Ago','Sep', 'Oct','Nov','Dic'],
    dayNames: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'],
    dayNamesShort: ['Dom','Lun','Mar','Mié','Juv','Vie','Sáb'],
    dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','Sá'],
    dateFormat: 'yy/mm/dd',
    prevText: '< Ant',
    nextText: 'Sig >',
    firstDay: 1,
    showButtonPanel: true,
    currentText: 'Hoy',

    beforeShowDay: function(date) {

        console.log(date);
        console.log(fechas);

        var date = $.datepicker.formatDate('yy/mm/dd', date);
            if($.inArray(date, fechas) !== -1) {
                return [true, 'verde'];
            } else {
                 return [true, ''];
            }
    }
})

};

I have put three console.log to see what is there.

The first one after the $ .ajax query, where you see an array with the dates that I want to highlight in the calendar:

The second one inside beforeShowDay, to see the date parameter (in the original console log there are some more date lines):

And the third one also within beforeShowDay to ensure that the array dates arrives:

asked by itaca9 20.12.2017 в 18:45
source

0 answers