FullCalendar:仅在当前视图中以列表视图显示事件。

huangapple go评论73阅读模式
英文:

FullCalendar: Display events in a listview only for the current view

问题

我正在使用FullCalendar v4,并尝试在自定义列表视图中仅显示当前视图中可用的所有事件。

当前视图的意思是,假设我处于'dayGridMonth'视图中,我需要获取当前整个月份的事件。同样,如果我处于'timeGridWeek'视图中,我需要获取当前活动的整个周的事件。

我正在使用FullCalendar Angular插件,并尝试使用getEvents()方法的以下代码。

let CalendarApi = this.calendar.getApi();
let events = CalendarApi.getEvents()
    
console.log(events);

使用这种方式,FullCalendar会显示无论我处于哪个视图中的所有事件。我希望像懒加载一样,仅为当前视图(时间段)加载事件。

英文:

I'm using FullCalendar v4 and trying to display all the events which are available only for the current view in a custom list view.

Current view in the sense, let's say if I'm in 'dayGridMonth' view, I need get the events for the entire month which is currently on. Likewise if I'm in 'timeGridWeek' view, I need to get the events for the entire week which is currently active.

I'm using FullCalendar Angular plugin and I have tried the following code using getEvents() method.

let CalendarApi = this.calendar.getApi();
let events = CalendarApi.getEvents()

console.log(events);

Using this way, FullCalendar displays all the events no matter what view I'm in. I want something like a lazy loading way where the events are loaded only for the current view (time period).

答案1

得分: 1

尝试使用

eventRender(event){}

它将在当前视图中渲染事件。

英文:

Try using

eventRender(event){}

It will render events in current view

答案2

得分: 0

  1. 识别视图的更改(例如,点击按钮'月'或'周')。
  2. 在视图更改时,您可以擦除或插入您想要的事件列表。

如何在代码中执行这些步骤:

在组件中,添加一个返回视图的回调函数:

<full-calendar (viewSkeletonRender)="handleViewRender($event)"></full-calendar>

在您的代码中,创建方法'handleViewRender':

handleViewRender($event) {
   if ($event.view.viewSpec.buttonTextDefault === 'month') {
       // 步骤2在这里,更改月视图的事件列表
   } else if ($event.view.viewSpec.buttonTextDefault === 'week') {
       // 步骤2在这里,更改周视图的事件列表
   }
   
   alert($event.view.viewSpec.buttonTextDefault);
}

我认为您已经知道如何将事件列表添加到日历中,如果不知道,可以轻松找到...所以我不会在这里提供代码。

有关日历事件的官方文档,大部分代码使用jQuery编写:
https://fullcalendar.io/docs/event-object

有关viewSkeletonRender的官方文档,这个文档很简单。
https://fullcalendar.io/docs/viewSkeletonRender

希望对您有所帮助。

英文:

I think you need to do some steps:

  1. Identify the change of view (click at button 'month' or 'week' for example).

  2. On change of view, you erase ou insert the list of events you want for that view.

How to do these steps on code:

1)
At the component, put a callback that return the view:

&lt;full-calendar (viewSkeletonRender)=&quot;handleViewRender($event)&quot;&gt;&lt;/full-calendar&gt;

At your code, create the method 'handleViewRender':

handleViewRender($event) {
   if ($event.view.viewSpec.buttonTextDefault === &#39;month&#39;) {
       // step 2 here, change the list of events for month view
   } else if ($event.view.viewSpec.buttonTextDefault === &#39;week&#39;) {
       // step 2 here, change the list of events for week view
   }
   
   alert($event.view.viewSpec.buttonTextDefault );
}

I think you already know how to put a list of events at the calendar, and if not, is so simple to find... so i will not put the code here.

Official doc about events on calendar, most of code is in jQuery:
https://fullcalendar.io/docs/event-object

Official doc about viewSkeletonRender, this doc is so poor.
https://fullcalendar.io/docs/viewSkeletonRender

I hope it helps.

huangapple
  • 本文由 发表于 2020年1月3日 21:12:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/59579214.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定