Use the
beforeShowDay and
onSelect options.
beforeShowDay
is a function that takes a date as a parameter and returns an
array with [0] being true if the date is selectable, false if not, [1]
being a CSS class to apply to the date, and [2] being an optional popup
tooltip. So you could have a list of the event dates and check against
them. Then add CSS to style the days.
- .ui-datepicker.ui-widget-content .ui-state-default { background: none; }
- .ui-widget-content .eventDay a.ui-state-default { background-color: #0f0; }
- .ui-widget-content .busyDay a.ui-state-default { background-color:
#f00; }
- $('#date').datepicker({beforeShowDay: showEventDates, onSelect: showEvent});
- var eventDates = [{date: new Date(2010,
6-1, 4), events: 1},
- {date: new Date(2010, 6-1, 18), events: 2},
- {date:
new Date(2010, 7-1, 16), events: 4},
- {date: new Date(2010, 8-1, 6), events: 8}];
- function showEventDates(date) {
- for (var i = 0; i
< eventDates.length; i++) {
- if (date.getTime()
== eventDates[i].date.getTime()) {
- return [true,
eventDates[i].events > 4 ? 'busyDay' : 'eventDay'];
- }
- }
- return [false,
''];
- }
- function showEvent(date) {
- window.location.href = 'events.php?date=' + date;
- }