I have fullcalendar based on script tags according to this. My calendar poses eventClick function that load data into bootstrap modal:
<script>
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
selectable: true,
firstDay : 1,
plugins: [ 'interaction', 'dayGrid'],
defaultView: 'dayGridMonth',
header: {
left: 'today',
center: 'title',
right: 'prev, next',
},
events: [
{% for event in main_events %}
{
client: '{{event.client.login}}',
user: '{{event.user}}',
},
{% endfor %}
],
eventClick: function(event) {
$('#modal_window').modal();
$('#modal_event_client').html(event.event.extendedProps.client);
$('#modal_event_user').html(event.event.extendedProps.user);
if (event.event.extendedProps.super_user_status == 'True') {
$('#modal_subtask_names').html(event.event.extendedProps.subtask_names);
$('#subtask_name').hide();
$('#subtask_description').hide();
}
if (event.event.extendedProps.super_user_status == 'False') {
$('#modal_subtask_name').html(event.event.extendedProps.subtask_name);
$('#modal_subtask_description').html(event.event.extendedProps.subtask_description);
$('#modal_subtask_comment').html(event.event.extendedProps.subtask_comment);
$('#subtask_names').hide();
}
}
});
calendar.render();
});
</script>
html:
<!-- Calendar-->
<div id='calendar'></div>
<!-- Modal -->
<div id="modal_window" class="modal fade bd-example-modal-sm">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<!-- Modal body -->
<div class="modal-body">
<div class="container-fluid">
<div class="row color">
<div class="col-4"><b>Client</b><p id="modal_event_client"></p></div>
</div>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
My problem is that every time i click event the data is forwarded from previous event into current. Calendar data is properly distributed after refresh.
How to implement refresh events or rerender events after eventClick?
Update: Thanks to sugestion of ADyson i added show function to the eventClick:
if (event.event.extendedProps.super_user_status == 'True') {
$('#subtask_name').hide();
$('#subtask_description').hide();
$('#subtask_names').show();
$('#modal_subtask_names').html(event.event.extendedProps.subtask_names);
}
if (event.event.extendedProps.super_user_status == 'False') {
$('#subtask_names').hide();
$('#subtask_name').show();
$('#subtask_description').show();
$('#modal_subtask_name').html(event.event.extendedProps.subtask_name);
$('#modal_subtask_description').html(event.event.extendedProps.subtask_description);
$('#modal_subtask_comment').html(event.event.extendedProps.subtask_comment);
}
Now all is working fine.
refreshCalendar(events)
. In this function u call$('#calendar').fullCalendar('destroy')
; and then reinitialize the calendar including your given events$('#calendar').fullCalendar({...})
– toffler