简体   繁体   English

Fullcalendar 向事件添加工具提示

[英]Fullcalendar add tooltip to events

I'm using fullcalendar in my php site.我在我的 php 站点中使用 fullcalendar。 I load events with eventSources, giving it an url redirecting to my php controller, which generates json data.我用 eventSources 加载事件,给它一个 url 重定向到我的 php controller,它生成 json 数据。 Before the calendar is rendered, I wish every event has a tooltip.在呈现日历之前,我希望每个事件都有一个工具提示。 To this scope I wrote a javascript function that add the tooltip:为此 scope 我写了一个 javascript function 添加了工具提示:

 function dailyTooltip(){
   $('.fc-day-grid-event, .fc-time-grid-event').each(function(){
      var content = $(this).data('content');
      $(this).attr('title',''); 
      $(this).tooltip({
       tooltipClass: 'event-tooltip',
       content: content,
      }); 
   });
 }

where content is html content.其中内容为 html 内容。 The function runs after calendar rendering. function 在日历呈现之后运行。 After the calendar has been rendered, the tooltip is not showing.呈现日历后,工具提示不显示。

To resolve this problem, I tried to add the function to datesRender, and eventRender.为了解决这个问题,我尝试将 function 添加到 datesRender 和 eventRender。 datesRender seems to work, but only when I change view (eg from timeGrid to dayMonthGrid). datesRender 似乎有效,但只有当我更改视图时(例如,从 timeGrid 到 dayMonthGrid)。 eventRender doesn't work. eventRender 不起作用。

you can use Tooltip.js with fullcalendar eventRender for showing tooltips, 您可以将Tooltip.js与fullcalendar eventRender一起使用以显示工具提示,

<script src='https://unpkg.com/tooltip.js/dist/umd/tooltip.min.js'></script>

you can use event render function like this as its suggested in official docs 您可以使用官方文档中建议的事件渲染功能

eventRender: function(info) {
        var tooltip = new Tooltip(info.el, {
          title: info.event.extendedProps.description,//you can give data for tooltip
          placement: 'top',
          trigger: 'hover',
          container: 'body'
        });
      },

See docs Event render Tooltip Fullcalendar 参见docs 事件渲染工具提示Fullcalendar

In fullcalendar.js V5, there is no eventRender.在fullcalendar.js V5中,没有eventRender。 So what I did is everytime I click any button on the calendar header i create their tooltip所以我所做的是每次单击日历上的任何按钮 header 我都会创建他们的工具提示

<script src='https://unpkg.com/tooltip.js/dist/umd/tooltip.min.js'></script>


const calendarControlBtns = Array.from(
  document.querySelectorAll('.fc-header-toolbar button')
);
calendarControlBtns.forEach((singleControlBtn) => {
  singleControlBtn.addEventListener('click', handleNewInterval);
});
const handleNewInterval = (e) => {
  const allEvents = Array.from(document.querySelectorAll('.fc-timegrid-event'));
  allEvents.forEach((singleEvent) => {
    singleEvent.dataset.toggle = 'tooltip';
    const title = singleEvent.querySelector('.fc-event-title').innerHTML;
    singleEvent.dataset.title = title;
  });
  $('[data-toggle="tooltip"]').tooltip();
}

I know this is an old post but if someone finds this post.我知道这是一篇旧文章,但如果有人找到这篇文章。 FullCalendar v5 has a hover example. FullCalendar v5 有一个 hover 的例子。 https://fullcalendar.io/docs/event-tooltip-demo https://fullcalendar.io/docs/event-tooltip-demo

You can also view it in code pen(top right hand corner button)您也可以在代码笔(右上角按钮)中查看它

Make sure to add the two js scripts.确保添加两个 js 脚本。 https://unpkg.com/popper.js/dist/umd/popper.min.js https://unpkg.com/tooltip.js/dist/umd/tooltip.min.js https://unpkg.com/popper.js/dist/umd/popper.min.js https://unpkg.com/tooltip.js/dist/umd/tooltip.min.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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