Yahoo! Developer Network Home - Help

YDN Site Search

# 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.

View example in new window.

## 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.

YAHOO.example.calendar.cal1 = new YAHOO.widget.CalendarGroup("cal1","cal1Container", { pagedate:"2/2008" } ); YAHOO.example.calendar.cal1.addRenderer("2/29", YAHOO.example.calendar.cal1.renderBodyCellRestricted); YAHOO.example.calendar.cal1.addRenderer("2/1/2008-2/7/2008", YAHOO.example.calendar.cal1.renderCellStyleHighlight1);

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.

var myCustomRenderer = function(workingDate, cell) { cell.innerHTML = "X"; YAHOO.util.Dom.addClass(cell, "sunday"); return YAHOO.widget.Calendar.STOP_RENDER; } YAHOO.example.calendar.cal1.addWeekdayRenderer(1, myCustomRenderer);

### YUI Logger Output:

Note: Logging and debugging is currently turned off for this example.

Reload with logging
and debugging enabled.

### Calendar Control Examples:

- Quickstart Tutorial
- Multi-Select Calendar
- Multi-Page Calendar
- Minimum/Maximum Dates
- Handling Calendar Events
- Calendar and Text Fields
- Calendar and Select Fields
- Using the Render Stack
- Popup Calendar
- Localization - Germany
- Localization - Japan
- Skinning The Calendar
- Calendar Plugin (included with examples for Rich Text Editor (beta))
- Inline Cell Editing (included with examples for DataTable Control (beta))
- Using YUI Loader to Load the Calendar Control (included with examples for YUI Loader Utility (beta))

### More Calendar Control Resources:

- User's Guide (external)
- API Documentation
- Cheat Sheet PDF (external)

Copyright © 2007 Yahoo! Inc. All rights reserved.

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