Paul-DS / bootstrap-year-calendar

[DEPRECATED] A fully customizable year calendar widget, for boostrap !
Apache License 2.0
294 stars 243 forks source link

How to use JSON for the DataSource #176

Open espinozayeff opened 6 years ago

espinozayeff commented 6 years ago

Hi there, I'm pretty new with this calendar and I don't know how to use my own JSON from a query on MySQL, to change the default DataSource in the example code. There is a guide for it or someone who can help me?

Thanks

William-H-M commented 6 years ago

Hi , you should look at #103 But basically when you get your response, do something like:

    $.ajax({
      url: "YourUrl!,
      dataType: "json",
      success: function(response) {
        var data = [];
        for (var i = 0; i < response.length; i++) {
          data.push({
            id: response[i].id,
            name: response[i].name,
            location: response[i].location,
            startDate: new Date(response[i].startDate),
            endDate: new Date(response[i].endDate),
            color: response[i].color
          });
        }
        $(e.target).data('calendar').setDataSource(data);
      }
    });