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

Color ressource according status

Asked by Anonymous
7 months ago.

Dear all

i would like change color for only ressource with Maintenance Status.

//weekend color and maintenance
dp.onBeforeCellRender = function(args) {
if (args.cell.start.getDayOfWeek() === 0 || args.cell.start.getDayOfWeek() === 6) {
args.cell.backColor = "silver";

}

if (args.resource.status == "Maintenance") {
args.resource.backColor = "silver";

}

};

This code doesn't work. Ok for week-end but not for status.
Thanks a lot for your help

Answer posted by Dan Letecky [DayPilot]
7 months ago.

The row header background color needs to be set using onBeforeRowHeaderRender event. The onBeforeCellRender only sets properties of the grid cells.

It could look like this:

dp.onBeforeRowHeaderRender = function(args) {
  if (args.row.data.status === "Maintenance") {
    args.row.backColor = "silver";
  }
};

This assumes "status" is set on the resources[] items:

dp.resources = [
  { name: "Room 1", id: 1, status: "Maintenance" },
  // ...
];

See also:
https://api.daypilot.org/daypilot-scheduler-onbeforerowheaderrender/

Comment posted by Anonymous
7 months ago.

Yur code is ok for RowHeaderRender
Infact i would like change color for all ressource line

i have just check with this

dp.onBeforeCellRender = function(args) {
if (args.row.data.status === "Maintenance") {
args.row.backColor = "silver";
}
};

Comment posted by Dan Letecky [DayPilot]
7 months ago.

For cells you'll need to add this as well:

dp.onBeforeCellRender = function(args) {
  var row = dp.rows.find(args.cell.resource);
  if (row.data.status === "Maintenance") {
    args.cell.backColor = "silver";
  }
};
Comment posted by Anonymous
7 months ago.

Nice.

It's working.

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