Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
180 views
in Technique[技术] by (71.8m points)

javascript - Events are badly rendered if calendar on a nav-tab

I just made a not very cool discovery ...

I am using FullCalendar on my app. I have a page that contains several tabs (made with bootstrap), like this:

enter image description here

The last tab "Provisional calendar" must contain a FullCalendar.

But I noticed one thing:

If the DOM element that should host the fullCalendar is not visible when the page loads, then the events will be badly rendered, like this:

enter image description here

The only possibilities for events to be correctly rendered are as follows:

  1. Or load the page directly on the last tab "Provisional calendar".

  2. Either, when loading the page, quickly click on the "Provisional calendar" tab to arrive on the tab before the events have time to be retrieved to be returned.

  3. Manually resize the window, which will trigger the call of the handleWindowResize () function and correctly put the events back in the calendar.

Which in the end will correctly deliver my events:

enter image description here

Other possible solutions would be:

  1. Make sure that fullCalendar can handle this case.

  2. Have an "eventAllRendered" option on the latest version of FullCalendar, in which we could call a function that would allow the events to be correctly delivered.

This si a codePen to simulate the bug : https://codepen.io/kiuega/pen/VwmeLgB

<ul class="nav nav-tabs" id="myTab" role="tablist">
  <li class="nav-item">
    <a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Home</a>
  </li>
  <li class="nav-item">
    <a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">Click here to display calendar</a>
  </li>
</ul>
<div class="tab-content" id="myTabContent">
  <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">...</div>
  <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">
    <div id='top'>

  Locales:
  <select id='locale-selector'></select>
</div>


<div id='calendar'></div>
    
  </div>
</div>
document.addEventListener('DOMContentLoaded', function() {
  var initialLocaleCode = 'de';
  var localeSelectorEl = document.getElementById('locale-selector');
  var calendarEl = document.getElementById('calendar');

  var calendar = new FullCalendar.Calendar(calendarEl, {
    headerToolbar: {
      left: 'prev,next today',
      center: 'title',
      right: 'dayGridMonth,timeGridWeek,timeGridDay,listMonth'
    },
    locale: initialLocaleCode,
    initialView: 'timeGridWeek',
    buttonIcons: false, // show the prev/next text
    weekNumbers: true,
    navLinks: true, // can click day/week names to navigate views
    editable: true,
    dayMaxEvents: true, // allow "more" link when too many events
    events: 'https://fullcalendar.io/demo-events.json?overload-day'
  });

  calendar.render();

  // build the locale selector's options
  calendar.getAvailableLocaleCodes().forEach(function(localeCode) {
    var optionEl = document.createElement('option');
    optionEl.value = localeCode;
    optionEl.selected = localeCode == initialLocaleCode;
    optionEl.innerText = localeCode;
    localeSelectorEl.appendChild(optionEl);
  });

  // when the selected option changes, dynamically change the calendar option
  localeSelectorEl.addEventListener('change', function() {
    if (this.value) {
      calendar.setOption('locale', this.value);
    }
  });

});
question from:https://stackoverflow.com/questions/66049327/events-are-badly-rendered-if-calendar-on-a-nav-tab

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...