This is a migrated thread and some comments may be shown as answers.

Applying resources based on a condition

1 Answer 36 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Grant
Top achievements
Rank 2
Veteran
Iron
Grant asked on 07 Aug 2019, 06:27 AM

Hi, 

As the title says, is it possible to apply a a resource based on a condition or multiple fields?

For example, I'd like to colour events based on 'age' and 'country'. eg. country=SA && age<30. 

Is this possible, or is there a work around that can achieve this?

Thanks,
Grant

1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 08 Aug 2019, 02:25 PM
Hi Grant,

An event can be colored based on a condition that checks the value of a single or several fields, by using eventTemplate. For example:
<style> 
  .custom-event {
    height: 100%;
    background-color: red;
  }
</style>
<script id="event-template" type="text/x-kendo-template">
    #if(data.country == "SA" && data.age < 30){#
      <div class="custom-event">
        <div>Title: #: title #</div>
  </div>
    #}else{#
      <div>
        <div>Title: #: title #</div>
  </div>
    #}#
</script>

Passing the template to the Scheduler:
eventTemplate: $("#event-template").html(),

Note that those fields don't necessarily have to be set as Scheduler resources. Here's a dojo example that demonstrates this approach. 

If you set a field as a resource, you can specify how all events that have a specific resource value can be colored. In the example above all events that have the country="SA" resource will be colored "lightblue" and all events with country="US" will be colored "lightgreen", because these are the colors of the country resource.
{ text: "SA", value: "SA", key: "lightblue" },
{ text: "US", value: "US", key: "lightgreen" }

However, in the template conditionally we add a div element in the template if age < 30, that's why the "Interview SA 20" event is colored in red. 

However
Regards,
Ivan Danchev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Scheduler
Asked by
Grant
Top achievements
Rank 2
Veteran
Iron
Answers by
Ivan Danchev
Telerik team
Share this question
or