year-calendar / js-year-calendar

A fully customizable year calendar widget
https://year-calendar.github.io/
Apache License 2.0
194 stars 71 forks source link

DataSource Not reading ajax object #76

Closed thursdaydan closed 3 years ago

thursdaydan commented 3 years ago

Hi guys, not really sure what the issue is here. I'm loading in my events from an ajax source and cannot for the life of me seem to get it working.

function getEvents() {
  return axios({
    url: '{{ route('admin.ajax.get-calendar-items') }}',
    params: {
        booking_type: !!document.querySelector('[name="booking_type"]').checked,
        event_type: !!document.querySelector('[name="event_type"]').checked,
        meeting_type: !!document.querySelector('[name="meeting_type"]').checked,
        sponsorship_type: !!document.querySelector('[name="sponsorship_type"]').checked,
        start: '2021-01-01T00:00:00Z',
        end: '2021-12-31T00:00:00Z'
    },
    transformResponse: axios.defaults.transformResponse.concat((data) => {
        data.forEach(item => {
            item.startDate = new Date(item.startDate);
            item.endDate   = new Date(item.endDate);
        });
        return data;
    })
  }).then(response => {
    return response.data;
  })
}

fullCalendar.render();

let secondCalendar = new YearCalendar('#year-calendar', {
dataSource: getEvents().then(data => {
  return data;
}),
enableRangeSelection: true
});

I've also shown the output of two objects, the first is from a codepen example that works and the second one if the object I received from the getEvents function.

Screenshot 2021-10-14 at 11 51 34