Change FullCalendar resources

3

I'm making a calendar, using the "timeline" view of FullCalendar . What I want to do is change the "resources" in a dynamic way, since I already have a view of Students and the Projects view, each with its corresponding events.

I tried to do something like this:

var resources = 'students';
$('#calendar').fullCalendar({
    resources: {
        url: 'resource-load.php',
        type: 'POST',
        data: {
            'data': resources
        }
    }
});

And views the changes from a select:

switch (selected) {
case 'general':
    $('#calendar').fullCalendar( 'changeView', 'month');
    break;
case 'students':
    $('#calendar').fullCalendar( 'changeView', 'timelineDay');
    $('#calendar').fullCalendar('option','resourceLabelText','Students');
    resources = 'students';
    $('#calendar').fullCalendar('refetchResources');
    break;
case 'proyects':
    $('#calendar').fullCalendar( 'changeView', 'timelineDay');
    $('#calendar').fullCalendar('option','resourceLabelText','Proyects');
    resources = 'proyects';
    $('#calendar').fullCalendar('refetchResources');
    break;
default: break;
}

What makes the students load at first, but when I change my view, nothing happens.

In the StackOverflow in English, I was told that I could get resources with a feature , and then reload the plugin, but the problem is that I do not understand how to do this, since I have not studied javascript so thoroughly. If someone could explain how to do this, it would be ideal.

    
asked by JCAguilera 10.08.2017 в 15:19
source

1 answer

2

With the help of a person from StackOverflow in English, I was able to solve the problem.

The answer is to get the resources through a feature like this:

var resources = 'students';
$('#calendar').fullCalendar({
    resources: function(callback) {
        getResources(function(resourceObjects) {
            callback(resourceObjects);
        });
    }
});
function getResources(handleData) {
    $.ajax({
        url:"resource-load.php",
        type: 'POST',
        data: {
            'data': resources
        },
        dataType: 'json',
        success:function(data) {
            handleData(data); 
        }
    });
}

Since every time we change the views, the value of resources changes and a recharge of the resources is done, which calls the function again with the new value of resources .

Here is the link to the solution in English:

link

    
answered by 10.08.2017 / 16:32
source