search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

How to change color of duration bar based on values in database

Asked by vicky romanic
3 years ago.

Hello,got an issue.
I have a column called priority_leave which can take values of P1,P2,P3 in leave_event table.
I want the duration bar change its back color based on these values
if P1-duration bar backcolor-red
else if P2-duration bar backcolor-blue
else duration bar backcolor-yellow
Below is my coding
Thanks for help

Answer posted by Dan Letecky [DayPilot]
3 years ago.

The backend_events.php script should look like this:

<?php
require_once '_db.php';

$stmt = $db->prepare("SELECT * FROM leave_event WHERE NOT ((leave_end <= :start) OR (leave_start >= :end))");
$stmt->bindParam(':start', $_GET['start']);
$stmt->bindParam(':end', $_GET['end']);
$stmt->execute();
$result = $stmt->fetchAll();

class Event {}
$events = array();

foreach($result as $row) {
    $e = new Event();
    $e->id = $row['id'];
    $e->text = "";
    $e->start = $row['leave_start'];
    $e->end = $row['leave_end'];
    $e->resource = $row['person_id'];
    $e->priority=$row['priority_leave'];

    $events[] = $e;
}

header('Content-Type: application/json');
echo json_encode($events);

You correctly store the "priority_leave" field value in "priority" property of the event object. Remove the session-related code.

On the client side, set the bar color in onBeforeEventRender like this:

onBeforeEventRender: (args) => {

  // ...
  
  switch (args.data.priority) {
    case "P1":
      args.data.barColor = "red";
      break;
    case "P2":
      args.data.barColor = "blue";
      break;
    default:
      args.data.barColor = "yellow";
      break;
  }
  
},
Comment posted by vicky romanic
3 years ago.

Thx Dan Letecky it works well

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.