How to customize the cells in different views (Month, week, day etc) ?
The following steps shows the way to customize the scheduler cells in different views (Month, week, day etc.) and to highlight the current date column cells.
Step 1: Create a scheduler cell template sample with multiple resources and refer the required scripts and stylesheets to it by referring the following link.
Online Sample Link: http://js.syncfusion.com/demos/web/#!/azure/schedule/template/cell
Step 2: Include an additional field namely “Type” which holds two values namely present and absent within the owner dataSource as shown below,
JavaScript
$(function () { var dManager = ej.DataManager(window.ResourcesData).executeLocal(ej.Query().take(0)); $("#Schedule1").ejSchedule({ width: "100%", height: "575px", showCurrentTimeIndicator: false, workCellsTemplateId: "#workTemplate", // API to apply custom templates for cells showAppointmentNavigator: false, group: { resources: ["Rooms", "Owners"] }, resources: [ { field: "roomId", title: "Room", name: "Rooms", allowMultiple: false, resourceSettings: { dataSource: [ { text: "Star Hotel", id: 1, groupId: 1, color: "#cb6bb2" }], text: "text", id: "id", groupId: "groupId", color: "color" } }, { field: "ownerId", title: "Owner", name: "Owners", allowMultiple: true, resourceSettings: { dataSource: [ { text: "Party Hall-A", id: 1, groupId: 1, color: "#ffaa00", type: "absent" }, { text: "Party Hall-B", id: 3, groupId: 1, color: "#f8a398", type: "present" }], text: "text", id: "id", groupId: "groupId", color: "color" } }], appointmentSettings: { dataSource: dManager, id: "Id", subject: "Subject", startTime: "StartTime", endTime: "EndTime", description: "Description", allDay: "AllDay", recurrence: "Recurrence", recurrenceRule: "RecurrenceRule", resourceFields: "roomId,ownerId" }, create: "currentDay", // this event will trigger when the control initially loads actionComplete: "navigation" // this event will raise on all successful completion of scheduler actions. }); });
Step 3: Define the create event mapped to the event handler function namely currentDay which contains the code to highlight the current date column cells. The following code example shows the logic.
function currentDay() { var obj = $("#Schedule1").data("ejSchedule"); if (obj.model.orientation != "horizontal") { var obj = $("#Schedule1").data("ejSchedule"); // here we are creating the object for schedule var today, date, index, value, element; today = new Date().setHours(0, 0, 0, 0); if (obj.currentView() == "day") { date = new Date(obj._dateRender[0]).setHours(0, 0, 0, 0); index = (date == today) ? 0 : -1; } else index = obj._dateRender.indexOf(today); if (index != -1) { if (obj.model.showAllDayRow) { value = index; for (i = 0; i < obj.res1.length; i++) { // obj.res1 represent the no of resources rendered in the contorl. It will be 1 for default sample $(obj.element.find(".e-alldaycells")[value]).addClass("e-currentdayhighlight"); // here are highlighting the current date allday cell value = value + obj._dateRender.length; } } element = obj.element.find(".e-workcellstab tr"); for (a = 0; a < element.length; a++) { value = index; for (b = 0; b < obj.res1.length; b++) { $($(element[a]).children()[value]).addClass("e-currentdayhighlight"); // here we are highlighting the current date work cells value = value + obj._dateRender.length; } } } } }
Step 3: Also, define the actionComplete event which gets triggered on completion of every successful scheduler action. Call the function currentDay on the successful completion of specific actions such as view and date navigation as depicted in the below code example.
function navigation(args) { if (args.requestType == "viewNavigate" || args.requestType == "dateNavigate") { currentDay(); } }
Step 4: The following template code can be used to customize the scheduler cells based on the resource name and type, view, day and date.
<script id="workTemplate" type="text/x-jsrender"> {{if resource.classname == 'e-parentnode'}} {{:resource.text}} {{else}} {{if view != 'month' && (date.getDay() == 0 || date.getDay() == 6) }} <div class="image"><img src='13.4.0.53/themes/web/images/schedule/weekend.png' /><br /><span class="caption">Weekend</span></div> {{else}} {{if view == 'workweek' && resource.type == 'absent' && date.getDate() != 4}} <div class="image" style="background-color: #ffe2bc;height:100%;width:100%;"></div> {{else view == 'month' && resource.text == 'Party Hall-A' && date.getDay() == 5}} <div class="image"><img src='13.4.0.53/themes/web/images/schedule/meeting.png' /><br /><span class="caption">Meeting</span></div> {{else resource.text != 'Party Hall-B' && date.getDate() == 15}} <div class="image"><img src='13.4.0.53/themes/web/images/schedule/holiday.png' /><br /><span class="caption">Holiday</span></div> {{else view != 'month' && resource.text == 'Party Hall-A' && view != 'workweek' && date.getDay() == 5 && date.getHours() == 10}} <div class="image"><img src='13.4.0.53/themes/web/images/schedule/meeting.png' /><br /><span class="caption">Meeting</span></div> {{else view == 'month' && resource.text == 'Party Hall-B' && view != 'workweek' && date.getDay() == 5 }} <div class="image"><img src='13.4.0.53/themes/web/images/schedule/conference.png' /><br /><span class="caption">Conf.</span></div> {{else resource.text == 'Party Hall-B' && date.getDate() == 16}} <div class="image"><img src='13.4.0.53/themes/web/images/schedule/happyday.png' /><br /><span class="caption">Happyday</span></div> {{else view != 'workweek' && view != 'month' && date.getDate() == 10 && date.getMonth() == 11}} <div class="image"><img src='13.4.0.53/themes/web/images/schedule/wednesday.png' /><br /><span class="caption">Day Spl</span></div> {{else date.getDate() == 25 && date.getMonth() == 11}} <div class="image"><img src='13.4.0.53/themes/web/images/schedule/christmas.png' /><br /><span class="caption">Christmas</span></div> {{/if}} {{/if}} {{/if}} </script>
Sample Link: http://jsplayground.syncfusion.com/bzmnu3fa
Step 5: Run the above sample and the customized week view cells will be seen as shown below.
Figure 1: Scheduler with customized week view cells.