Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datepicker with events?

Is there a jquery plugin that would allow me to have a small calendar like rectangle, like in datepickers and some of the dates would be different colour. When I go over the date with mouse there is a popup saying what event is scheduled on that day. Of course I would populate the event array with events ;-)

All I find are the datepickers (small) or calendars (full screen large). What I need for my webpage is there is a small calendar there and a simple mouseover that would show the text that I would like it to show.

Does something like that exists?

like image 797
Jerry2 Avatar asked Feb 19 '11 16:02

Jerry2


People also ask

How do I create a DatePicker?

If the Controls task pane is not visible, click More Controls on the Insert menu, or press ALT+I, C. Under Insert controls, click Date Picker. In the Date Picker Binding dialog box, select the field in which you want to store the date picker data, and then click OK.

Is there a bootstrap DatePicker?

Bootstrap date picker is a plugin that adds the function of selecting time without the necessity of using custom JavaScript code. This documentation may contain syntax introduced in the MDB 4.17.

What is Flatpickr?

flatpickr is a lightweight and powerful datetime picker. Lean, UX-driven, and extensible, yet it doesn't depend on any libraries. There's minimal UI but many themes. Rich, exposed APIs and event system make it suitable for any environment.

What is Kendo DatePicker?

The DatePicker component is part of Kendo UI for jQuery, a professional grade UI library with 110+ components for building modern and feature-rich applications.


2 Answers

As others have pointed out, this is possible with jQueryUI's datepicker.

Datepicker has some built in functionality that will help you get there. Specifically, the beforeShowDay event will let you customize the appearance and behavior of each day without much code at all:

  1. Create an object containing events you can reference from the datepicker's event handler:

    var Event = function(text, className) {
        this.text = text;
        this.className = className;
    };
    
    var events = {};
    events[new Date("02/14/2011")] = new Event("Valentines Day", "pink");
    events[new Date("02/18/2011")] = new Event("Payday", "green");
    

    This code just creates an object with "keys" being the event date and "values" being event data.

  2. To make the datepicker widget show up all the time (without requiring an input for example), just apply the widget to a div:

    HTML:

    <div id="dates"></div>
    

    JavaScript:

    $("#dates").datepicker({....});
    
  3. Tap into the beforeShowDay event, and return the appropriate array. datepicker will automatically apply a tooltip and class you specify. This is where the Event objects we defined above come in handy:

    $("#dates").datepicker({
        beforeShowDay: function(date) {
            var event = events[date];
            if (event) {
                return [true, event.className, event.text];
            }
            else {
                return [true, '', ''];
            }
        }
    });
    

    This is probably the trickiest part. The beforeShowDay event handler expects you to return an array structured like this:

    [ 0 ] equal to true/false indicating whether or not this date is selectable, [ 1 ] equal to a CSS class name(s) or '' for the default presentation, and [ 2 ] an optional popup tooltip for this date.

    So what we're doing is looking up the event on the date passed into the function handling the beforeShowDay event and returning the data from our event object, if it exists.

It looks like alot, but it's not too bad when you look at it all put together. Check out the example here: http://jsfiddle.net/andrewwhitaker/rMhVz/1/

Note the CSS classes must use !important to override the default background of the datepicker, and actually apply to the a tags inside of the date trs

like image 81
Andrew Whitaker Avatar answered Oct 13 '22 01:10

Andrew Whitaker


Use the jquery UI datepicker. With some extra jquery you can hook up a mouseover event and display information.

The dates are recognizable with cssclass and nesting information. After showing the calendar you can attach your eventhandler.

   $(document).ready(function () {
         $("input").datepicker();     
   });

   $('td a').live('mouseenter', function () { 
     alert($(this).text() + ' ' + $('.ui-datepicker-month').text() 
                          + ' ' +$('.ui-datepicker-year').text()  );    
   });

the selectors need some precision to work correct, but the idea stays the same.

like image 33
Michiel Overeem Avatar answered Oct 13 '22 00:10

Michiel Overeem