Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add loading indicator to fullcalendar

I'm trying to add loading spins like this to fullcalendar, when I'm changing months in it. How can I do that?

like image 369
Андрей Баранов Avatar asked May 15 '15 11:05

Андрей Баранов


2 Answers

FullCalendar Version v4 & v5 has a "Loading" callback here is a basic example:

Here is the link to the documentation: FullCalendar (Loading..)

Styles Example:

     #loading {
        width: 100%;
        height: 100%;
        top: 120px;
        left: 470px;
        position: fixed;
        display: block;
        opacity: 0.7;
        background-color: #fff;
        z-index: 99;
        text-align: center;
    }

    #loading-image {
        position: absolute;
        top: 100px;
        left: 240px;
        z-index: 100;
    } 

HTML Where Calendar Output, Add DIV that will overlay and link to progress gif image of your choice:

<div id="calendar"></div> <div id="loading" style="display:none;">
<img id="loading-image" src="/img/loading.gif" alt="Loading..." /></div>

By default style display:none the loading div will be hidden. By using the callback to trigger the show/hide of this progress bar. So the load start event (true) will show the div layer and when it returns (false) indicating not loading anymore, it will hide the div layer.

 var calendar = new FullCalendar.Calendar(calendarEl, {
  loading: function (isLoading) {
                    if (isLoading) {
                        $('#loading').show();
                    }
                    else {                
                        $('#loading').hide();
                    }
                }
  //add rest of your calendar events/options        
 });
like image 90
moto_geek Avatar answered Sep 17 '22 14:09

moto_geek


You can easily do this using available fullcalendar methods.

loading - triggers when events fetching starts

eventAfterAllRender - Triggered after all events have finished rendering.

 $('#calendar').fullCalendar({
    loading: function (bool) {
       alert('events are being rendered'); // Add your script to show loading
    },
    eventAfterAllRender: function (view) {
        alert('all events are rendered'); // remove your loading 
    }
  });
like image 39
Prasanth Jaya Avatar answered Sep 20 '22 14:09

Prasanth Jaya