Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to control positioning of jQueryUI datepicker

The datepicker in jQueryUI renders with a dynamic position. It renders according to its css if there's enough room for it, but if there isn't enough window space it tries to render on screen. I need it to stay put and render in the same place every time, independent of the screen position or other circumstances. How can this be done with the jQueryUI datepicker? Other implementations of jQuery datepicker seem to have ways of doing this, but I don't see a way of doing it for the UI version.

The answer doesn't seem to be just modifying the css:

.ui-datepicker { width: 17em; padding: .2em .2em 0; (trying top/margin-top/position:relative, etc. here...)} 

...since when the datepicker is created it dynamically creates top and left in element style. Haven't found a way around this yet. One approach I saw is to give something like this in the beforeShow option:

beforeShow: function(input,inst){                                 inst.dpDiv.css({                                     'top': input.offsetHeight+ 'px',                                     'left':(input.offsetWidth - input.width)+ 'px'                                                });                                 } 

This has some effect but the top and left properties are still being dynamically set after this is run when the datepicker renders. It's still trying to render on screen. How do I get it to always render in the same spot? My next step is probably to go into the datepicker guts and start pulling things out. Any ideas?

Note that the answer (for the UI version) is not in:

  • how-to-change-the-pop-up-position-of-the-jquery-datepicker-control
  • change-the-position-of-jquery-ui-datepicker
like image 865
Purrell Avatar asked Nov 30 '09 09:11

Purrell


People also ask

How do I change my datepicker position?

To change the position of the jQuery UI Datepicker just modify . ui-datepicker in the css file. The size of the Datepicker can also be changed in this way, just adjust the font size.

How do I limit datepicker?

You can restrict the users from selecting a date within the particular range by specifying MinDate and MaxDate properties. The default value of MinDate property is 1/1/1920 and MaxDate property is 12/31/2120 . Dates that appears outside the minimum and maximum date range will be disabled (blackout).

How do I style a datepicker calendar?

Right click on datepicker box. Select 'inspect' (Ctrl+Shift+I) in Chrome or 'inspect element' (Q) in Firefox. Find the CSS style that you want to change.

How do I stop datepicker pop up?

$(document). mouseup(function (e) { $('#example1'). Close(); });


1 Answers

Posting this in hopes that it will help others. At least as of v1.8.1 of datepicker, using 'window.DP_jQuery.datepicker' no longer works, because the pointer(right term?) now is named with a timestamp of its creation - so for example it would now be 'window.DP_jQuery_1273700460448'. So now, rather than using the pointer to the datepicker object, refer to it directly like this:

$.extend($.datepicker,{_checkOffset:function(inst,offset,isFixed){return offset}}); 

Many thanks for the answer below for getting me what I needed.

like image 152
JaredC Avatar answered Oct 08 '22 19:10

JaredC