How to control positioning of jQueryUI datepicker

前端 未结 13 1365
一整个雨季
一整个雨季 2020-12-07 16:55

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

13条回答
  •  孤街浪徒
    2020-12-07 17:23

    Edit: JaredC gave an updated answer for later versions of jQuery above. Switching accepted answer to that.

    Alright, this is a matter of monkeypatching the feature it has of attempting to always render in the viewport since there's no option provided to enable/disable the feature. Luckily it's uncoupled and isolated in one function so we can just go in and override it. The following code completely disables that feature only:

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

    _checkOffset is called when it's opening and it does calculations on the offset and returns a new offset if it would otherwise be outside of the view port. This replaces the function body to just pass the original offset right through. Then you can use the beforeShow setting hack and/or the .ui-datepicker css class to put it wherever you want.

提交回复
热议问题