bootstrap-year-calendar icon indicating copy to clipboard operation
bootstrap-year-calendar copied to clipboard

How to use JSON for the DataSource

Open espinozayeff opened this issue 6 years ago • 1 comments

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

espinozayeff avatar Oct 23 '17 20:10 espinozayeff

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);
      }
    });

William-H-M avatar Oct 23 '17 21:10 William-H-M