views:

55

answers:

4

What is the best way to create a calendar with JavaScript like the jquery Datepicker where I can add some more functionality?

I want to display some arrays of dates in different colors in it as well as selecting a date.

Shall I try to edit the source code, or better, use some library and do it myself?

For the first case I would like to find some good documentation of the jquery Datepicker source. For the second I would like to find some library, which creates a good and easy to use calendar.

A: 

The jQuery Datepicker widget already provides enough functionality for a calendar. Adding custom colors is more of a style (thus CSS) thing. Also, documentation is very easy to find, so is Googling for it.

Lastly, editing the source code is never a good idea, since an upgrade will overwrite your changes.

Peter Kruithof
+1  A: 

If you don't mind writing some code of your own, you could try my calendar-logic.js.

It does no UI at all. You'll get full control of the look and behaviour of the calendar, without having to worry about the math behind how many weeks there are in a month, etc.

August Lilleaas
A: 

Have a look at the extjs calendar - it looks far more extensible - and there is a pro version (paid for ) as well

http://www.sencha.com/blog/2010/09/08/ext-js-3-3-calendar-component/

James Westgate
+3  A: 

I want to display some arrays of dates in different colors in it as well as selecting a date.

jQueryUI's datepicker already have this.

crazy demo

$(function() {
    var someDates = ['10/8/2010', '10/28/2010', '10/30/2010']; // the array of dates

    $("#datepicker").datepicker({
        beforeShowDay: function(date) {
            for (var i = 0; i < someDates.length; i++) {
                if (new Date(someDates[i]).toString() == date.toString()) {

                    return [true,'someDates']; // someDates here is a class
                    // with that added class you could do your style..
                    // html would then be rendered something like this,
                    // <td class="someDates"><a href="">8</a></td>
                }
            }
            return [true];
        }
    });
});​

and you could do more. Try reading event-beforeShowDay

Reigel
cool, didn't know that!
helle
Yeah! anything else? :D
Reigel
can you just help me out another time? how can i add a style to a date? when i select a date and then press some button, i want to add this to the array of someDates ... or is it enough to call refresh after adding it to the array?
helle
what is it again? can you explain more?
Reigel
i want to change the color of the day-boxes at runtime. so i thought, i can add dates to our array someDates and then refresh the datepicker, but this seems not working.
helle