YUI Library Home

YUI Library Examples: Calendar Control: Using the Render Stack

Calendar Control: Using the Render Stack

Calendar employs a feature called the Render Stack to allow you to customize the way that certain date cells are rendered on the Calendar. The Render Stack consists of a collection of functions that can be executed when rendering certain dates. When the Calendar is rendered, each function in the Render Stack is executed for each applicable date. This functionality allows developers implementing the Calendar to alter the contents of date cells based on a set of rules.

This example shows you how to use any one of the built-in renderers provided with the Calendar, or write your own.

Su Mo Tu We Th Fr Sa
27 28 29 30 31 1 2
X 4 5 6 7 8 9
X 11 12 13 14 15 16
X 18 19 20 21 22 23
X 25 26 27 28 29 1
2 3 4 5 6 7 8
Su Mo Tu We Th Fr Sa
24 25 26 27 28 29 1
X 3 4 5 6 7 8
X 10 11 12 13 14 15
X 17 18 19 20 21 22
X 24 25 26 27 28 29
X 31 1 2 3 4 5

Setting up the Calendar

In this tutorial, we will create a Calendar that makes use of the built-in renderers, and we will also create one of our own.

The built-in renderers available are:

  • renderCellDefault - Places a clickable link in the date cell
  • renderBodyCellRestricted - Renders a text=only cell with the "restricted" style
  • renderOutOfBoundsDate - Renders an out-of-bounds date (beyond the specified min/max dates)
  • renderCellNotThisMonth - Renders a cell that is displayed in the current page, but precedes or follows the current month
  • renderCellStyleToday - Renders the cell representing today's date
  • renderCellStyleSelected - Renders a selected cell
  • renderCellStyleHighlight1 - Adds the "highlight1" class to the date cell
  • renderCellStyleHighlight2 - Adds the "highlight2" class to the date cell
  • renderCellStyleHighlight3 - Adds the "highlight3" class to the date cell
  • renderCellStyleHighlight4 - Adds the "highlight4" class to the date cell

To begin, we will instantiate a new Calendar and apply the restricted renderer to 2/29 of any year, and the "highlight1" style to the range of dates between 2/1/2008 and 2/7/2008.

1YAHOO.example.calendar.cal1 = new YAHOO.widget.CalendarGroup("cal1","cal1Container"
2                                                             { pagedate:"2/2008" } ); 
3 
4YAHOO.example.calendar.cal1.addRenderer("2/29", YAHOO.example.calendar.cal1.renderBodyCellRestricted); 
5YAHOO.example.calendar.cal1.addRenderer("2/1/2008-2/7/2008", YAHOO.example.calendar.cal1.renderCellStyleHighlight1); 
view plain | print | ?

Next, we will create a custom renderer that will place an "X" in the cell for every Sunday, and style it in a dark gray color. In order to specify that our renderer should override the default renderer (renderCellDefault), the custom function must return YAHOO.widget.Calendar.STOP_RENDER. This tells the Calendar to ignore the rest of the Render Stack and continue rendering the rest of the Calendar.

1var myCustomRenderer = function(workingDate, cell) { 
2    cell.innerHTML = "X"
3    YAHOO.util.Dom.addClass(cell, "sunday"); 
4    return YAHOO.widget.Calendar.STOP_RENDER; 
5
6YAHOO.example.calendar.cal1.addWeekdayRenderer(1, myCustomRenderer); 
view plain | print | ?

Configuration for This Example

You can load the necessary JavaScript and CSS for this example from Yahoo's servers. Click here to load the YUI Dependency Configurator with all of this example's dependencies preconfigured.

YUI Logger Output:

Logger Console

INFO 3369ms (+0) 7:54:57 PM:

Config

Firing Config event: iframe=false

INFO 3369ms (+0) 7:54:57 PM:

Config

Firing Config event: close=false

INFO 3369ms (+1) 7:54:57 PM:

Config

Firing Config event: title=false

CELL 3368ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-4-5)

CELL 3368ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell41 (2008-4-5)

CELL 3368ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-4-4)

CELL 3368ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell40 (2008-4-4)

CELL 3368ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-4-3)

CELL 3368ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell39 (2008-4-3)

CELL 3368ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-4-2)

CELL 3368ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell38 (2008-4-2)

CELL 3368ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-4-1)

CELL 3368ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell37 (2008-4-1)

CELL 3368ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-31)

CELL 3368ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-31)

CELL 3368ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell36 (2008-3-31)

CELL 3368ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-30)

CELL 3368ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell35 (2008-3-30)

CELL 3368ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-29)

CELL 3368ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-29)

CELL 3368ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell34 (2008-3-29)

CELL 3368ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-28)

CELL 3368ms (+1) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-28)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell33 (2008-3-28)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-27)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-27)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell32 (2008-3-27)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-26)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-26)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell31 (2008-3-26)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-25)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-25)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell30 (2008-3-25)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-24)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-24)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell29 (2008-3-24)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-23)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell28 (2008-3-23)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-22)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-22)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell27 (2008-3-22)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-21)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-21)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell26 (2008-3-21)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-20)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-20)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell25 (2008-3-20)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-19)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-19)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell24 (2008-3-19)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-18)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-18)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell23 (2008-3-18)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-17)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-17)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell22 (2008-3-17)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-16)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell21 (2008-3-16)

CELL 3367ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-15)

CELL 3367ms (+1) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-15)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell20 (2008-3-15)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-14)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-14)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell19 (2008-3-14)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-13)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-13)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell18 (2008-3-13)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-12)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-12)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell17 (2008-3-12)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-11)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-11)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell16 (2008-3-11)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-10)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-10)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell15 (2008-3-10)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-9)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell14 (2008-3-9)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-8)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-8)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell13 (2008-3-8)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-7)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-7)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell12 (2008-3-7)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-6)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-6)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell11 (2008-3-6)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-5)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-5)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell10 (2008-3-5)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-4)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-4)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell9 (2008-3-4)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-3)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-3)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell8 (2008-3-3)

CELL 3366ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-2)

CELL 3366ms (+1) 7:54:57 PM:

Calendar cal1_1

Rendering cell cal1_1_cell7 (2008-3-2)

CELL 3365ms (+0) 7:54:57 PM:

Calendar cal1_1

renderer[1] for (2008-3-1)

CELL 3365ms (+3364) 7:54:57 PM:

Calendar cal1_1

renderer[0] for (2008-3-1)

INFO 1ms (+1) 7:54:54 PM:

global

Logger initialized

Note: You are viewing this example in debug mode with logging enabled. This can significantly slow performance.

Reload with logging
and debugging disabled.

More Calendar Control Resources:

Copyright © 2009 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings