Prioritize the Resource Color for Events

17 Feb 20223 minutes to read

By default top level resource color will be applied for the events. If user wants to apply specific resource color to events irrespective of its parent resource color, it can be achieved by resourceColorField field within eventSettings property as shown below.

@using Syncfusion.EJ2
@using Syncfusion.EJ2.Schedule

@section ControlsSection{
    <div class="control-section">
        <div class="content-wrapper">
            @Html.EJS().Schedule("schedule").Width("100%").Height("550px").CurrentView(View.WorkWeek).SelectedDate(new DateTime(2018, 6, 5)).Group(group => group.ByGroupID(false).Resources(ViewBag.Resources)).Resources(res =>
       {
           res.DataSource(ViewBag.Projects).Field("ProjectId").Title("Project").Name("Projects").TextField("text").IdField("id").ColorField("color").Add();
           res.DataSource(ViewBag.Categories).Field("CategoryId").Title("Category").Name("Categories").TextField("text").IdField("id").ColorField("color").AllowMultiple(true).Add();
       }).EventSettings(e => e.DataSource(ViewBag.datasource)).Render()
        </div>
    </div>
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebApplication1.Models;

namespace WebApplication1.Controllers
{
    public partial class ScheduleController : Controller
    {
        public ActionResult resource-color()
        {
            ViewBag.datasource = new ScheduleData().GetResourceTeamData();

            List<ProjectResource> projects = new List<ProjectResource>();
            projects.Add(new ProjectResource { text = "PROJECT 1", id = 1, color = "#cb6bb2" });
            projects.Add(new ProjectResource { text = "PROJECT 2", id = 2, color = "#56ca85" });
            ViewBag.Projects = projects;

            List<CategoryResource> categories = new List<CategoryResource>();
            categories.Add(new CategoryResource { text = "Development", id = 1, color = "#1aaa55" });
            categories.Add(new CategoryResource { text = "Testing", id = 2, color = "#7fa900" });
            ViewBag.Categories = categories;

            ViewBag.Resources = new string[] { "Projects", "Categories" };
            return View();
        }
    }
    public class ProjectResource
    {
        public string text { set; get; }
        public int id { set; get; }
        public string color { set; get; }
    }
    public class CategoryResource
    {
        public string text { set; get; }
        public int id { set; get; }
        public string color { set; get; }
    }
}

The resourceColorField field value should be as same as the name field value given with in resources property.