简体   繁体   中英

Change view of fullcalendar dont keep event

I'm using the v3 of the fullcalendar . When I'm inicialize the calendar I see the agenda view, but when I start some events and change the view the events aren't there.

This just happen on the first interaction, after that the events are rendered just fine.

I see the lazyFetching property on the docs, but not solve my problem.

This is my calendar custom config:

$(document).ready(function () {

    var containerEl = $('#calendar');

    containerEl.fullCalendar({
        defaultView: 'agendaWeek',
        hiddenDays: [0],
        locale: 'pt-br',
        slotLabelFormat: 'HH:mm',
        views: {
            week: { columnHeaderFormat: 'ddd D/M' }
        },
        editable: true,
        allDaySlot: false,
        slotDuration: '00:15:00',
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        buttonText: {
            month: 'Mês',
            agendaDay: 'Dia',
            agendaWeek: 'Semana',
            today: 'Hoje'
        },
        // Dates outside of the valid range will be grayed-out. The user
        // will not be able to drag or resize events into these areas.
        validRange: {
            start: moment('2018-10-22'),
            end: moment('2018-05-29')
        },
        minTime: "07:00:00",
        maxTime: "23:30:00",
        // Slot do evento de tamanho fixo a horaAula da escola
        eventDurationEditable: false,
        eventStartEditable: true,
        defaultTimedEventDuration: '00:45:00',
        selectable: true,
        // Eventos
        select: function (start, end, jsEvent, view) {
            addEvent(containerEl, start, end, jsEvent, view);
        },
        eventClick: function (event, jsEvent, view) {
           removeEvent(containerEl, event, jsEvent, view);
        },
        dayClick: function(date, allDay, jsEvent, view) {
            // Se a view for de mês mudamos para o dia quando clicável
            if (jsEvent.name === 'month') {
                containerEl.fullCalendar('changeView', 'agendaDay', date);
            }
        }file:///home/italo/Downloads/bug.gif

    });
});

The project code

renderEvent has an optional argument, stick . Set it to true and event should stay between view changes.

Update your addEvent module with true as the third parameter.

function addEvent(containerEl, start, end, jsEvent, view) {
    //var allDay = !start.hasTime && !end.hasTime;
    if (view.name !== 'month') {
        var newEvent = new Object();
        newEvent.title = 'Colocar o nome da disciplina aqui';
        newEvent.start = moment(start).format();
        newEvent.allDay = false;
        containerEl.fullCalendar('renderEvent', newEvent, true /* stick */);
    }
}

Note: this change does not save your event to a resource like a database. That would require additional code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM