fullcalendar / fullcalendar

Full-sized drag & drop event calendar in JavaScript
https://fullcalendar.io
MIT License
18.46k stars 3.6k forks source link

Provide visibleRange as a async function with success callback #5857

Open EdCampion opened 3 years ago

EdCampion commented 3 years ago

Checklist

Feature Description

I'm working on a schedule feature using a custom view and the resourceTimeline plugin. It is essentially a timesheet which has arbitrary date ranges. I need to fetch the ranges via API, they are not known / computable.

I need something like the existing visibleRange option, but I need the ability to use it in an async fashion.

acerix commented 3 years ago

I'm not sure what you mean with async, could you provide an example of how you are trying to use visibleRange or why it doesn't work?

EdCampion commented 3 years ago

Hi, Perhaps I've fallen foul of the "just try it" dictum. So I've seen examples where visibleRange is provided a function. The function immediately returns a range object. My scenario would be something like the following, and would work like the events or resource fetching does.


  initialView: 'timeGrid',
  visibleRange: function(currentDate) {
    //ajaxRequest to api providing ranges

  //onSuccess of request
  //notify FullCalendar of ranges via callback similar to how events and resources work.
  }
});
acerix commented 3 years ago

In that case, you could do your own ajax call, then on success, update the range using setOption.

EdCampion commented 3 years ago

Update: Solved below by calling refetchEvents() after setting the visibleRange. Will continue to play with this, but looking good. Thanks for your help.

Thanks for that. This works for the initial load. I'm aware this is not a support avenue. But will chance my arm anyway. I'm trying to roll my own next/previous functionality. As it stands, my next and previous buttons advance / retreat the current window and then call the api to fetch the range for the chosen window. On API success I update the visible range option. My new problem is that this does not trigger a fetch of events. It dosen't make sense to me to call the fullcalendar next() / previous() functions. But maybe I'm confused.

vitality82 commented 3 years ago

@EdCampion would you mind to share your progress on this, if there was more? I'm doing a custom one (quarterList). What I found hard to understand is how the "currentDate" provided in their dateRange callback is supposed to be used. I assume that if the dateRange is calculated based on the "currentDate" the NEXT/PREV actions would auto-magically work, but now I'm not so sure anymore...