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

Calendar - Weekend different color

Asked by Anonymous
11 years ago.

I would like to change the weekend into a different color than the weekdays or lock the height of the calendar so i can set all weekdays to business hours.
Is one of these currently possible?

Thank you in advance

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

You can change the color of the background cells using BeforeCellRender event handler.

You can change the cell CSS class using e.CssClass, you can also change the IsBusiness status using e.IsBusiness, and you can change the background color directl using e.BackgroundColor.

Example from Demo/Calendar/CustomBusinessHours.aspx.cs:

    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;
         */ 

    }

Just note that if you want to change the background color directly in the CssOnly mode you will need the latest sandbox build of v7.1 (http://www.daypilot.org/sandbox/).

See also:

Comment posted by Anonymous
11 years ago.

I changed it to this

protected void CalendarAfspraken_BeforeCellRender(object sender, dpwue.BeforeCellRenderEventArgs e)
{
if (e.Start.DayOfWeek == DayOfWeek.Saturday || e.Start.DayOfWeek == DayOfWeek.Sunday)
e.BackgroundColor = "#FFF990";
}

and it worked!
Thanks!

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