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
2 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]
2 years ago.

The backend_events.php script should look like this:

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']);
$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'];

    $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 ( {
    case "P1": = "red";
    case "P2": = "blue";
    default: = "yellow";
Comment posted by vicky romanic
2 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.