how to refresh datepicker? function .datePickerMultiMonth()

天涯浪子 提交于 2019-12-21 20:25:34

问题


Really like datepicker. Thanks a lot for this great library!

I have got one question for you based in this example (inline datepicker):

http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerMultiMonth5.html

I added a "renderCallback" function to disable week days based on checkboxes... (e.g. when saturday-checkbox is checked disable all saturdays shown).

This works perfectly fine when initializing the calender with datePickerMultiMonth().

But how can I refresh the inline calender when one of the checkboxes is changed (e.g. deselect monday-checkbox)?

As-is: when I select / deselect a checkbox the datepicker remains unchanged.. only after manually changing to the next month it updates and disables e.g. all mondays... this should immediately happen when changing the monday-checkbox.

Do you have any idea how I can refresh the datepicket? Thanks a lot for your help!

Cheers, Markus


回答1:


.datepicker( "refresh" )

You can find it on http://jqueryui.com/demos/datepicker/#method-refresh click the "Methods" tab




回答2:


Probably the easiest way to solve the problem is to remove the existing calendar and then rerender it. e.g.:

$mm.empty().datePickerMultiMonth({});

However, this has some drawbacks as the state of your date picker isn't maintained (e.g. displayed month, selected dates etc).

So I just made some changes to the plugin and introduced a new method: dpmmRerenderCalendar on the multimonth picker (and the corresponding dpRerenderCalendar on the date picker itself).

You can see an example of it in action here:

http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerMultiMonth7.html

And can grab the latest plugin code from my site or the googlecode repository.




回答3:


After having a bit of a look at the source, it seems you'll have to do something like this:

$.event._dpCache[$('.date-pick')[0]._dpId]._applyRenderCallbacks()

or possibly this:

$.event._dpCache[$('.date-pick')[0]._dpId]._rerenderCalendar()

The $.event._dpCache[$('.date-pick')[0]._dpId] part is used to get the first internal DatePicker object matching the css '.date-pick', which is needed to access the internal _applyRenderCallbacks and _rerenderCalendar functions.

Unfortunately, this does access the internal structure of the plugin, so it is possible it might break when new versions are released, however I couldn't find any publicly accessible way to refresh the calendar.



来源:https://stackoverflow.com/questions/2129480/how-to-refresh-datepicker-function-datepickermultimonth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!