Telerik Kendo Scheduler:在Week View的主要部分显示全天活动

时间:2018-11-12 18:40:21

标签: kendo-ui telerik kendo-asp.net-mvc kendo-scheduler telerik-scheduler

我试图弄清楚如何隐藏AllDaySlot,但仍能在主要部分看到事件。

我检查了https://www.telerik.com/forums/=-24-hour-events-treated-as-all-day主题和任何相关主题,但没有找到解决方法。

我可以看到工作示例,但是在这里https://demos.telerik.com/aspnet-ajax/scheduler/examples/day-week-multi-day-views/defaultcs.aspx是AJAX的例子,但是我没有运气找出原因和完成方式。

我的客户需要此功能,这很关键。

期待您的回答。

谢谢。

2 个答案:

答案 0 :(得分:0)

Kendo UI调度程序在主体部分忽略24小时以上的事件。参见this feature request。投票吧。也许进度会在某个时间点解决此问题。

暂时我不created a custom view

基本上我是从kendo.scheduler.dayview.js继承的,替换了内部的_renderEvents函数。

我的起点是更改_renderEvents

var isMultiDayEvent = event.isAllDay || event.duration() >= MS_PER_DAY;

收件人:

var isMultiDayEvent = event.isAllDay;

ranges = group.slotRanges(event);

ranges = group.slotRanges(event, false);

在_updateResizeHint和_updateMoveHint中,我替换了

var multiday = event.isMultiDay();

使用

var multiday = event.isMultiDay() && this.options.allDaySlot;

这会阻止视图将大于24小时的事件解释为全天事件。

接下来发生的事情很大程度上取决于您的配置(分组,工具提示,自定义模板,调整大小,编辑...)。也许您在我的版本从未见过的地方出现错误。

如果遇到错误,请让我知道并修复(或不:))。很有可能这里的其他人也有兴趣。

HTH

伯恩德

答案 1 :(得分:0)

首先,该问题现已在 5 月 21 日之后的最新版 Telerik ui 中得到修复。

对于那些仍在使用旧版本 2020 及更低版本的用户,这可能会有所帮助

正如@bdongus 给出的那样,我将 dayview 扩展如下。 (因为他没有给出完整的代码)

  var getDate = kendo.date.getDate;
    
        function addContinuousEvent(group, range, element, isAllDay) {
            var events = group._continuousEvents;
            var lastEvent = events[events.length - 1];
            var startDate = getDate(range.start.startDate()).getTime();
    
            //this handles all day event which is over multiple slots but starts
            //after one of the time events
            if (isAllDay && lastEvent &&
                getDate(lastEvent.start.startDate()).getTime() == startDate) {
    
                    var idx = events.length - 1;
                    for ( ; idx > -1; idx --) {
                        if (events[idx].isAllDay ||
                            getDate(events[idx].start.startDate()).getTime() < startDate) {
                                break;
                            }
                    }
    
                    events.splice(idx + 1, 0, {
                        element: element,
                        isAllDay: true,
                        uid: element.attr(kendo.attr("uid")),
                        start: range.start,
                        end: range.end
                    });
                } else {
                    events.push({
                        element: element,
                        isAllDay: isAllDay,
                        uid: element.attr(kendo.attr("uid")),
                        start: range.start,
                        end: range.end
                    });
                }
        }
    
        var CustomDayView = kendo.ui.DayView.extend({
        _renderEvents: function(events, groupIndex) {
                var allDayEventContainer = this.datesHeader.find(".k-scheduler-header-wrap > div");
                var byDate = this._isGroupedByDate();
                var event;
    
                var idx;
                var length;
    
                for (idx = 0, length = events.length; idx < length; idx++) {
                    event = events[idx];
    
                    if (this._isInDateSlot(event)) {
   var isMultiDayEvent = event.isAllDay;
                        var container = isMultiDayEvent && !this._isVerticallyGrouped() ? allDayEventContainer : this.content;
                        var element, ranges, range, start, end, group;
    
                        if (!isMultiDayEvent) {
    
                            if (this._isInTimeSlot(event)) {
                                group = this.groups[groupIndex];
    
                                if (!group._continuousEvents) {
                                    group._continuousEvents = [];
                                }
    
                                ranges = group.slotRanges(event, false);
    
                                var rangeCount = ranges.length;
    
                                for (var rangeIndex = 0; rangeIndex < rangeCount; rangeIndex++) {
                                    range = ranges[rangeIndex];
                                    start = event.start;
                                    end = event.end;
    
                                    if (rangeCount > 1) {
                                        if (rangeIndex === 0) {
                                            end = range.end.endDate();
                                        } else if (rangeIndex == rangeCount - 1) {
                                            start = range.start.startDate();
                                        } else {
                                            start = range.start.startDate();
                                            end = range.end.endDate();
                                        }
                                    }
    
                                    var occurrence = event.clone({ start: start, end: end, _startTime: event._startTime, _endTime: event.endTime });
    
                                    if (this._isInTimeSlot(occurrence)) {
                                        var head = range.head;
    
                                        element = this._createEventElement(event, !isMultiDayEvent, head, range.tail);
    
                                        element.appendTo(container);
    
                                        this._inverseEventColor(element);
    
                                        this._positionEvent(occurrence, element, range);
    
                                        addContinuousEvent(group, range, element, false);
                                    }
                                }
                            }
    
                        } else if (this.options.allDaySlot) {
                           group = this.groups[groupIndex];
    
                           if (!group._continuousEvents) {
                               group._continuousEvents = [];
                           }
    
  ranges = group.slotRanges(event, false);
    
                            if (ranges.length) {
                                range = ranges[0];
                                var startIndex = range.start.index;
                                var endIndex = range.end.index;
    
                                if (byDate && startIndex !== endIndex) {
                                    start = range.start.start;
                                    end = range.end.end;
                                    var newStart = new Date(start);
                                    var newEnd = new Date(start);
    
                                    for (var i = range.start.index; i <= range.end.index; i++) {
                                        element = this._createEventElement(event, !isMultiDayEvent, i !== endIndex, i !== startIndex);
    
                                        var dateRange = group.daySlotRanges(newStart, newEnd, true)[0];
                                        newEnd.setDate(newEnd.getDate() + 1);
                                        newStart.setDate(newStart.getDate() + 1);
    
                                        this._positionAllDayEvent(element, dateRange);
    
                                        addContinuousEvent(group, dateRange, element, true);
    
                                        element.appendTo(container);
    
                                        this._inverseEventColor(element);
                                    }
                                   } else {
                                           element = this._createEventElement(event, !isMultiDayEvent);
    
                                           this._positionAllDayEvent(element, ranges[0]);
    
                                           addContinuousEvent(group, ranges[0], element, true);
    
                                           element.appendTo(container);
    
                                           this._inverseEventColor(element);
                                   }
                           }
                        }
                    }
                }
            },
        });

并且您需要在调度程序视图中使用它

$("#scheduler").kendoScheduler({
            views: [
                "day",                
                "agenda",
                { type: "CustomDayView", title: "Day view", selected: true },
            ],
});

它现在就像一个魅力。

谢谢

拉梅什 R