Your search did not match any results.

Resources

Users can categorize appointments by resources. The following example illustrates what resources are: in an educational center lectures are held in several rooms. In Scheduler terms, room is a resource kind, individual rooms are resource instances, and lectures are appointments that use these resource instances.

Define Resource Kinds

Use the resources array to define resource kinds. Each object in this array should contain at least the following fields:

  • dataSource
    Resource instances of this resource kind. Each instance should contain the id, text, and color fields. If your field names differ, specify them in the valueExpr, displayExpr, and colorExpr properties, respectively.

  • fieldExpr
    A data field used to assign instances of this resource kind to appointments. Add this field to appointment objects and set the field values to id values of resource instances.

In this demo, the resources array contains three resource kinds: rooms, priorities, and assignees. Their fieldExpr values are roomId, priorityId, and assigneeId, respectively. Each appointment contains the same fields. Field values assign the appointments to different instances of these resource kinds.

Color Appointments Based on a Resource Kind

To use the color scheme of a specific resource kind, enable the kind's useColorAsDefault property. Otherwise, appointments use the color scheme of the last resource kind declared in the resources array.

This demo enables you to change the useColorAsDefault property at runtime. Click the radio buttons under the Scheduler to switch between different color schemes.

Assign Multiple Instances of a Resource Kind

Each resource kind object can contain the allowMultiple property. When this property is set to true, users can assign multiple instances of this kind to a single appointment. In this demo, the Assignee resource kind allows multiple instances.

You can also group appointments by resources as shown in the following demo: Group Orientation.

Backend API
@model DevExtreme.NETCore.Demos.ViewModels.SchedulerResourcesViewModel @{ var resourcesList = new[] { "Assignee", "Room", "Priority" }; } @(Html.DevExtreme().Scheduler() .ID("scheduler") .DataSource(Model.Appointments) .TimeZone("America/Los_Angeles") .Views(new[] { SchedulerViewType.WorkWeek }) .CurrentView(SchedulerViewType.WorkWeek) .CurrentDate(new DateTime(2021, 4, 27)) .StartDayHour(9) .EndDayHour(19) .Resources(res => { res.Add() .FieldExpr("RoomId") .ValueExpr("Id") .ColorExpr("Color") .Label("Room") .DisplayExpr("Text") .DataSource(Model.Rooms); res.Add() .FieldExpr("PriorityId") .ValueExpr("Id") .ColorExpr("Color") .Label("Priority") .DisplayExpr("Text") .DataSource(Model.Priorities); res.Add() .FieldExpr("AssigneeId") .ValueExpr("Id") .ColorExpr("Color") .Label("Assignee") .DisplayExpr("Text") .AllowMultiple(true) .DataSource(Model.Assignees); }) .Height(600) .TextExpr("Text") .StartDateExpr("StartDate") .EndDateExpr("EndDate") .AllDayExpr("AllDay") .RecurrenceRuleExpr("RecurrenceRule") .RecurrenceExceptionExpr("RecurrenceException") ) <div class="options"> <div class="caption">Use colors of:</div> <div class="option"> @(Html.DevExtreme().RadioGroup() .Items(resourcesList) .Value(resourcesList[0]) .Layout(Orientation.Horizontal) .OnValueChanged("resources_valueChanged") ) </div> </div> <script> function resources_valueChanged(e) { var scheduler = $("#scheduler").dxScheduler("instance"), resources = scheduler.option("resources"); for(var i = 0; i < resources.length; i++) { resources[i].useColorAsDefault = resources[i].label == e.value; } scheduler.repaint(); } </script>
using DevExtreme.NETCore.Demos.Models.SampleData; using DevExtreme.NETCore.Demos.ViewModels; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; namespace DevExtreme.NETCore.Demos.Controllers { public class SchedulerController : Controller { public ActionResult Resources() { return View(new SchedulerResourcesViewModel { Appointments = SampleData.AppointmentsWithResources, Assignees = SampleData.AssigneeResources, Rooms = SampleData.RoomResources, Priorities = SampleData.PriorityResources }); } } }
using System; using System.Collections.Generic; using System.Linq; namespace DevExtreme.NETCore.Demos.Models.SampleData { public partial class SampleData { public static readonly IEnumerable<AppointmentWithResources> AppointmentsWithResources = new[] { new AppointmentWithResources { Text = "Website Re-Design Plan", AssigneeId = new int[] { 4 }, RoomId = 1, PriorityId = 2, StartDate = "2021-04-26T16:30:00.000Z", EndDate = "2021-04-26T18:30:00.000Z" }, new AppointmentWithResources { Text = "Book Flights to San Fran for Sales Trip", AssigneeId = new int[] { 2 }, RoomId = 2, PriorityId = 1, StartDate = "2021-04-26T19:00:00.000Z", EndDate = "2021-04-26T20:00:00.000Z", AllDay = true }, new AppointmentWithResources { Text = "Install New Router in Dev Room", AssigneeId = new int[] { 1 }, RoomId = 1, PriorityId = 2, StartDate = "2021-04-26T21:30:00.000Z", EndDate = "2021-04-26T22:30:00.000Z" }, new AppointmentWithResources { Text = "Approve Personal Computer Upgrade Plan", AssigneeId = new int[] { 3 }, RoomId = 2, PriorityId = 2, StartDate = "2021-04-27T17:00:00.000Z", EndDate = "2021-04-27T18:00:00.000Z" }, new AppointmentWithResources { Text = "Final Budget Review", AssigneeId = new int[] { 1 }, RoomId = 1, PriorityId = 1, StartDate = "2021-04-27T19:00:00.000Z", EndDate = "2021-04-27T20:35:00.000Z" }, new AppointmentWithResources { Text = "New Brochures", AssigneeId = new int[] { 4 }, RoomId = 3, PriorityId = 2, StartDate = "2021-04-27T21:30:00.000Z", EndDate = "2021-04-27T22:45:00.000Z" }, new AppointmentWithResources { Text = "Install New Database", AssigneeId = new int[] { 2 }, RoomId = 3, PriorityId = 1, StartDate = "2021-04-28T16:45:00.000Z", EndDate = "2021-04-28T18:15:00.000Z" }, new AppointmentWithResources { Text = "Approve New Online Marketing Strategy", AssigneeId = new int[] { 4 }, RoomId = 2, PriorityId = 1, StartDate = "2021-04-28T19:00:00.000Z", EndDate = "2021-04-28T21:00:00.000Z" }, new AppointmentWithResources { Text = "Upgrade Personal Computers", AssigneeId = new int[] { 2 }, RoomId = 2, PriorityId = 2, StartDate = "2021-04-28T22:15:00.000Z", EndDate = "2021-04-28T23:30:00.000Z" }, new AppointmentWithResources { Text = "Customer Workshop", AssigneeId = new int[] { 3 }, RoomId = 3, PriorityId = 1, StartDate = "2021-04-29T18:00:00.000Z", EndDate = "2021-04-29T19:00:00.000Z", AllDay = true }, new AppointmentWithResources { Text = "Prepare 2021 Marketing Plan", AssigneeId = new int[] { 1 }, RoomId = 1, PriorityId = 2, StartDate = "2021-04-29T18:00:00.000Z", EndDate = "2021-04-29T20:30:00.000Z" }, new AppointmentWithResources { Text = "Brochure Design Review", AssigneeId = new int[] { 4 }, RoomId = 1, PriorityId = 1, StartDate = "2021-04-29T21:00:00.000Z", EndDate = "2021-04-29T22:30:00.000Z" }, new AppointmentWithResources { Text = "Create Icons for Website", AssigneeId = new int[] { 3 }, RoomId = 3, PriorityId = 1, StartDate = "2021-04-30T17:00:00.000Z", EndDate = "2021-04-30T18:30:00.000Z" }, new AppointmentWithResources { Text = "Upgrade Server Hardware", AssigneeId = new int[] { 4 }, RoomId = 2, PriorityId = 2, StartDate = "2021-04-30T21:30:00.000Z", EndDate = "2021-04-30T23:00:00.000Z" }, new AppointmentWithResources { Text = "Submit New Website Design", AssigneeId = new int[] { 1 }, RoomId = 1, PriorityId = 2, StartDate = "2021-04-30T23:30:00.000Z", EndDate = "2021-05-01T01:00:00.000Z" }, new AppointmentWithResources { Text = "Launch New Website", AssigneeId = new int[] { 2 }, RoomId = 3, PriorityId = 1, StartDate = "2021-04-30T19:20:00.000Z", EndDate = "2021-04-30T21:00:00.000Z" } }; } }
using System; namespace DevExtreme.NETCore.Demos.Models.SampleData { public class AppointmentWithResources : Appointment { public int[] AssigneeId { get; set; } public int RoomId { get; set; } public int PriorityId { get; set; } } }
using System; namespace DevExtreme.NETCore.Demos.Models.SampleData { public class AssigneeResource { public int Id { get; set; } public string Text { get; set; } public string Color { get; set; } } }
using System; using System.Collections.Generic; using System.Linq; namespace DevExtreme.NETCore.Demos.Models.SampleData { public partial class SampleData { public static readonly IEnumerable<AssigneeResource> AssigneeResources = new[] { new AssigneeResource { Id = 1, Text = "Samantha Bright", Color = "#727bd2" }, new AssigneeResource { Id = 2, Text = "John Heart", Color = "#32c9ed" }, new AssigneeResource { Id = 3, Text = "Todd Hoffman", Color = "#2a7ee4" }, new AssigneeResource { Id = 4, Text = "Sandra Johnson", Color = "#7b49d3" } }; } }
using System; namespace DevExtreme.NETCore.Demos.Models.SampleData { public class PriorityResource { public int Id { get; set; } public string Text { get; set; } public string Color { get; set; } } }
using System; using System.Collections.Generic; using System.Linq; namespace DevExtreme.NETCore.Demos.Models.SampleData { public partial class SampleData { public static readonly IEnumerable<PriorityResource> PriorityResources = new[] { new PriorityResource { Id = 1, Text = "High", Color = "#cc5c53" }, new PriorityResource { Id = 2, Text = "Low", Color = "#ff9747" } }; } }
using System; namespace DevExtreme.NETCore.Demos.Models.SampleData { public class RoomResource { public int Id { get; set; } public string Text { get; set; } public string Color { get; set; } } }
using System; using System.Collections.Generic; using System.Linq; namespace DevExtreme.NETCore.Demos.Models.SampleData { public partial class SampleData { public static readonly IEnumerable<RoomResource> RoomResources = new[] { new RoomResource { Id = 1, Text = "Room 1", Color = "#00af2c" }, new RoomResource { Id = 2, Text = "Room 2", Color = "#56ca85" }, new RoomResource { Id = 3, Text = "Room 3", Color = "#8ecd3c" } }; } }
.options { padding: 20px; background-color: rgba(191, 191, 191, 0.15); margin-top: 20px; } .caption { font-size: 18px; font-weight: 500; } .option { margin-top: 10px; display: inline-block; }