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

How to use the BeforeCellRender Event

Asked by Jay
14 years ago.

Hello Dan,

Could you provide me with an example of how to call the BeforeCellRender event? I am trying to determine which dates are blocked/non business by traversing through each cell. I didn't see the event in the daypilot control, nor could I find it in the code behind. A walkthrough would really be appreciated. Thank you.

Comment posted by Jay
14 years ago.
Digging further into the forums and playing around with the properties, I was able to find the event property that fires the beforecellrender event. Also, thismay behelpful to anyone reading this post: using e.start and e.end allowsyou to grab the time the cell is referring to. This is how I was able to compare it with my dates in the db thatwere blocked.
Comment posted by Dan Letecky
14 years ago.
Jay,

Thanks for posting the solution!

An example can be found in Demo/Calendar/CustomBusinessHours.aspx (it's for DayPilotCalendar but DayPilotScheduler works the same way):

    protected void DayPilotCalendar1_BeforeCellRender(object sender, BeforeCellRenderEventArgs e)
{
if (e.Start.Hour >= 9 && e.Start.Hour < 12)
e.BackgroundColor = "#FFF2CC"; // shift #1
else if (e.Start.Hour >= 12 && e.Start.Hour < 15)
e.BackgroundColor = "#FFD9CC"; // shift #2
else if (e.Start.Hour >= 15 && e.Start.Hour < 18)
e.BackgroundColor = "#F2FFCC"; // shift #3

// Turning Saturday and Sunday into business days
/*
if ((e.Start.DayOfWeek == DayOfWeek.Saturday || e.Start.DayOfWeek == DayOfWeek.Sunday)
|| (e.Start.Hour >= 9 && e.Start.Hour < 18))
{
e.IsBusiness = true;
}
*/

// or you can change just IsBusiness and you will get the color automatically
/*
if (e.Start.Hour >= 10 && e.Start.Hour < 12)
e.IsBusiness = true;
else if (e.Start.Hour >= 14 && e.Start.Hour < 16)
e.IsBusiness = true;
else
e.IsBusiness = false;
*/

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