forked from telerik/kendo-ui-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom Month view with event count in show more button demo
- Loading branch information
1 parent
8bae45f
commit 979ba21
Showing
1 changed file
with
250 additions
and
0 deletions.
There are no files selected for viewing
250 changes: 250 additions & 0 deletions
250
.../web/scheduler/how-to/custom-month-view-with-event-count-in-show-more-button.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,250 @@ | ||
--- | ||
title: Create custom Month view with event count in show more button | ||
page_title: Create custom Month view with event count in show more button | ||
description: Create custom Month view with event count in show more button | ||
--- | ||
|
||
# Create custom Month view with event count in show more button | ||
|
||
The example below demonstrates how to inherit the built-in Month view and implement showing the hidden events count when the "show more" button is rendered. | ||
|
||
#### Example: | ||
|
||
```html | ||
<div id="scheduler"></div> | ||
<script> | ||
var MORE_BUTTON_TEMPLATE = kendo.template( | ||
'<div style="width:#=width#px;left:#=left#px;top:#=top#px" class="k-more-events k-button"><span style="font-size:8pt; margin-top: 0;"> #=getEventCountForRange(startSlot, endSlot, rowsCount)# more events..</span></div>'); | ||
function getEventCountForRange(startSlot, endSlot, rowsCount) { | ||
var scheduler = $(startSlot.element).closest("[data-role=scheduler]").getKendoScheduler(); | ||
var currentTimezoneOffset = kendo.date.MS_PER_MINUTE * new Date().getTimezoneOffset(); | ||
var rangeStart = new Date(startSlot.start + currentTimezoneOffset); | ||
var rangeEnd = new Date(endSlot.end + currentTimezoneOffset); | ||
return scheduler.occurrencesInRange(rangeStart, rangeEnd).length - rowsCount + 1; | ||
} | ||
var CustomMonthView = kendo.ui.MonthView.extend({ | ||
options: { | ||
name: "CustomMonthView", | ||
title: "Month Week" | ||
}, | ||
name: "CustomMonthView", | ||
_positionEvent: function(slotRange, element, group) { | ||
var eventHeight = this.options.eventHeight; | ||
var startSlot = slotRange.start; | ||
if (slotRange.start.offsetLeft > slotRange.end.offsetLeft) { | ||
startSlot = slotRange.end; | ||
} | ||
var startIndex = slotRange.start.index; | ||
var endIndex = slotRange.end.index; | ||
var eventCount = startSlot.eventCount; | ||
var events = kendo.ui.SchedulerView.collidingEvents(slotRange.events(), startIndex, endIndex); | ||
var rightOffset = startIndex !== endIndex ? 5 : 4; | ||
events.push({ | ||
element: element, | ||
start: startIndex, | ||
end: endIndex | ||
}); | ||
var rows = kendo.ui.SchedulerView.createRows(events); | ||
for (var idx = 0, length = Math.min(rows.length, eventCount); idx < length; idx++) { | ||
var rowEvents = rows[idx].events; | ||
var eventTop = startSlot.offsetTop + startSlot.firstChildHeight + idx * eventHeight + 3 * idx + "px"; | ||
for (var j = 0, eventLength = rowEvents.length; j < eventLength; j++) { | ||
rowEvents[j].element[0].style.top = eventTop; | ||
} | ||
} | ||
if (rows.length > eventCount) { | ||
for (var slotIndex = startIndex; slotIndex <= endIndex; slotIndex++) { | ||
var collection = slotRange.collection; | ||
var slot = collection.at(slotIndex); | ||
if (slot.more) { | ||
return; | ||
} | ||
slot.more = $(MORE_BUTTON_TEMPLATE({ | ||
startSlot: slotRange.start, | ||
endSlot: slotRange.end, | ||
rowsCount: rows.length, | ||
ns: kendo.ns, | ||
start: slotIndex, | ||
end: slotIndex, | ||
width: slot.clientWidth - 2, | ||
left: slot.offsetLeft + 2, | ||
top: slot.offsetTop + slot.firstChildHeight + eventCount * eventHeight + 3 * eventCount | ||
})); | ||
this.content[0].appendChild(slot.more[0]); | ||
} | ||
} else { | ||
slotRange.addEvent({ | ||
element: element, | ||
start: startIndex, | ||
end: endIndex, | ||
groupIndex: startSlot.groupIndex | ||
}); | ||
element[0].style.width = slotRange.innerWidth() - rightOffset + "px"; | ||
element[0].style.left = startSlot.offsetLeft + 2 + "px"; | ||
element[0].style.height = eventHeight + "px"; | ||
group._continuousEvents.push({ | ||
element: element, | ||
uid: element.attr(kendo.attr("uid")), | ||
start: slotRange.start, | ||
end: slotRange.end | ||
}); | ||
element.appendTo(this.content); | ||
} | ||
}, | ||
}); | ||
$(function() { | ||
var scheduler = $("#scheduler").kendoScheduler({ | ||
date: new Date("2013/6/13"), | ||
startTime: new Date("2013/6/13 07:00 AM"), | ||
height: 600, | ||
views: [{ | ||
type: "CustomMonthView" | ||
}, | ||
"day" | ||
], | ||
timezone: "Etc/UTC", | ||
dataSource: { | ||
batch: true, | ||
transport: { | ||
read: { | ||
url: "http://demos.telerik.com/kendo-ui/service/tasks", | ||
dataType: "jsonp" | ||
}, | ||
update: { | ||
url: "http://demos.telerik.com/kendo-ui/service/tasks/update", | ||
dataType: "jsonp" | ||
}, | ||
create: { | ||
url: "http://demos.telerik.com/kendo-ui/service/tasks/create", | ||
dataType: "jsonp" | ||
}, | ||
destroy: { | ||
url: "http://demos.telerik.com/kendo-ui/service/tasks/destroy", | ||
dataType: "jsonp" | ||
}, | ||
parameterMap: function(options, operation) { | ||
if (operation !== "read" && options.models) { | ||
return { | ||
models: kendo.stringify(options.models) | ||
}; | ||
} | ||
} | ||
}, | ||
schema: { | ||
model: { | ||
id: "taskId", | ||
fields: { | ||
taskId: { | ||
from: "TaskID", | ||
type: "number" | ||
}, | ||
title: { | ||
from: "Title", | ||
defaultValue: "No title", | ||
validation: { | ||
required: true | ||
} | ||
}, | ||
start: { | ||
type: "date", | ||
from: "Start" | ||
}, | ||
end: { | ||
type: "date", | ||
from: "End" | ||
}, | ||
startTimezone: { | ||
from: "StartTimezone" | ||
}, | ||
endTimezone: { | ||
from: "EndTimezone" | ||
}, | ||
description: { | ||
from: "Description" | ||
}, | ||
recurrenceId: { | ||
from: "RecurrenceID" | ||
}, | ||
recurrenceRule: { | ||
from: "RecurrenceRule" | ||
}, | ||
recurrenceException: { | ||
from: "RecurrenceException" | ||
}, | ||
ownerId: { | ||
from: "OwnerID", | ||
defaultValue: 1 | ||
}, | ||
isAllDay: { | ||
type: "boolean", | ||
from: "IsAllDay" | ||
} | ||
} | ||
} | ||
}, | ||
filter: { | ||
logic: "or", | ||
filters: [{ | ||
field: "ownerId", | ||
operator: "eq", | ||
value: 1 | ||
}, { | ||
field: "ownerId", | ||
operator: "eq", | ||
value: 2 | ||
}] | ||
} | ||
}, | ||
resources: [{ | ||
field: "ownerId", | ||
title: "Owner", | ||
dataSource: [{ | ||
text: "Alex", | ||
value: 1, | ||
color: "#f8a398" | ||
}, { | ||
text: "Bob", | ||
value: 2, | ||
color: "#51a0ed" | ||
}, { | ||
text: "Charlie", | ||
value: 3, | ||
color: "#56ca85" | ||
}] | ||
}] | ||
}).data("kendoScheduler"); | ||
$("#days").change(function() { | ||
//change the number of days option of the view | ||
scheduler.setOptions({ | ||
numberOfDays: parseInt($(this).val()) | ||
}); | ||
//reload the view | ||
scheduler.view(scheduler.view().name); | ||
}); | ||
}); | ||
</script> | ||
``` |