我正在使用Kendo UI Scheduler创建活动..
如何为每个事件添加唯一的css类?
例如:第一个事件应该有.event-red
,第二个事件应该是.event-green
等等......
我正在尝试添加类下面的类,但不能正常工作...... :(
data: [
{
...
className: "event-red"
...
},
....
代码:
$(document).ready(function() {
var date = new Date();
var _data = new kendo.data.SchedulerDataSource({
data: [
{
eventID: 1,
title: "Heading 1",
start: new Date(),
end: new Date(),
isAllDay: false,
description: "Lorem ipsum content (1)",
className: "event-red"
},
{
eventID: 2,
title: "Heading 2",
start: new Date(),
end: new Date(),
isAllDay: false,
description: "New content goes here (2)",
className: "event-green"
},
{
eventID: 3,
title: "Heading 3",
start: new Date(),
end: new Date(),
isAllDay: false,
description: "More content goes here (3)",
className: "event-blue"
},
],
schema: {
model : { id : "eventID" }
}
});
function save(){
console.log(_data);
}
$('#socialMediaCalendar').kendoScheduler({
eventTemplate: $("#event-template").html(),
height: 600,
messages: {
today: "Today",
},
//editable: false,
ShowFooter: "false",
views: [
{ type: "day", title: "Day", selectedDateFormat: "{0:dddd}", showWorkHours: false, selected: true },
{ type: "month" },
],
dataBound: function() {
var scheduler = this;
var allDayEventBlock = scheduler.wrapper.find(".k-scheduler-layout>tbody>tr:nth-child(1)");
var dayViewTimesBlock = scheduler.wrapper.find(".k-scheduler-layout .k-scheduler-times");
var tdNoWorkHours = scheduler.wrapper.find(".k-scheduler-layout .k-nonwork-hour");
var prevCalContentRef = scheduler.wrapper.find(".k-scheduler-layout td.et-options #previewCalDayContent");
allDayEventBlock.remove();
dayViewTimesBlock.remove();
tdNoWorkHours.closest("tr").remove();
prevCalContentRef.attr("href", "#pn-modal-day-preview");
},
save: save,
dataSource:_data,
});
$(function () {
$("#socialMediaCalendar").kendoTooltip({
filter: ".k-event",
position: "top",
width: 250,
content: kendo.template($('#calendarPopupTemplate').html())
});
});
});
HTML
<div class="container">
<div class="rp-calendar">
<div id="socialMediaCalendar"></div>
</div>
</div>
<!-- Calendar Scheduler (Content Templates) -->
<script id="event-template" type="text/x-kendo-template">
<table width="100%" cellpadding="0" cellspacing="0" class="scheduler-template-table">
<tbody>
<tr>
<td class="et-time" width="1%" nowrap>#: kendo.toString(start, "HH:mm") #</td>
<td class="et-content"><h3>#: title #</h3><p>#: description #</p></td>
<td class="et-options" align="right">
<input type="button" value="Edit" id="eventEdit" class="k-button">
</td>
</tr>
<tbody>
</table>
</script>
<!-- /Calendar Scheduler (Content Templates) -->
<!-- Calendar Scheduler (Tooltip Templates) -->
<script id="calendarPopupTemplate" type="text/x-kendo-template">
#var uid = target.attr("data-uid");#
#var scheduler = target.closest("[data-role=scheduler]").data("kendoScheduler");#
#var model = scheduler.occurrenceByUid(uid);#
#if(model) {#
<table width="100%" cellpadding="0" cellspacing="0" class="scheduler-template-table stt-tooltip">
<tbody>
<tr>
<td class="et-time" width="1%" nowrap>#=kendo.format('{0:HH:mm}',model.start)#</td>
<td class="et-content" valign="middle"><h3>#: model.title #</h3><p>#=model.description#</p></td>
</tr>
<tbody>
</table>
#} else {#
<p>No event data is available</p>
#}#
</script>
<!-- /Calendar Scheduler (Tooltip Template) -->
答案 0 :(得分:1)
好吧,既然你正在使用模板,你可以通过它们来完成。 在模板中,您可以访问dataSource中提供的所有属性,因此关于您的示例,您只需要添加
style="color: #= myProperty #;"
或
class:"et-content #= myProperty #"
Here is demo - 您需要查看模板(事件模板)和SchedulerDataSource。