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.
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:
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.
1 | YAHOO.example.calendar.cal1 = new YAHOO.widget.CalendarGroup("cal1","cal1Container", |
2 | { pagedate:"2/2008" } ); |
3 | |
4 | YAHOO.example.calendar.cal1.addRenderer("2/29", YAHOO.example.calendar.cal1.renderBodyCellRestricted); |
5 | YAHOO.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.
1 | var myCustomRenderer = function(workingDate, cell) { |
2 | cell.innerHTML = "X"; |
3 | YAHOO.util.Dom.addClass(cell, "sunday"); |
4 | return YAHOO.widget.Calendar.STOP_RENDER; |
5 | } |
6 | YAHOO.example.calendar.cal1.addWeekdayRenderer(1, myCustomRenderer); |
view plain | print | ? |
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.
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.
Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Copyright Policy - Job Openings