Kendo UI Timepicker custom interval format

孤街醉人 提交于 2019-12-24 01:43:07

问题


What i'm looking to do with the kendoTimePicker is have the 30 minute interval for all times leading up to 11:30PM, but after 11:30 display all subsequent times up to 12AM in minute interval. Not sure if this control supports it.

Basically looking to have something like this:

10:30 PM
11:00 PM
11:30 PM
11:31 PM
11:32 PM
11:33 PM
..etc


回答1:


The only way I could think of doing it is to manually change the list of times in the dropdown. Kendo just dynamically adds a <ul> to your page that is shown as the popup, so you could clear and rebuild the list yourself.

Something like:

<input id="timepicker" />

$("#timepicker").kendoTimePicker();
var listOfTimes = $("#timepicker_timeview");

// remove all existing <li> elements
listOfTimes.empty();

// add the times you want...
listOfTimes.append('<li tabindex="-1" role="option" class="k-item" unselectable="on">12:00 PM</li>');
listOfTimes.append('<li tabindex="-1" role="option" class="k-item" unselectable="on">12:01 PM</li>');
listOfTimes.append('<li tabindex="-1" role="option" class="k-item" unselectable="on">12:02 PM</li>');
// ...etc...

Or start with a fully populated list and just remove the ones you don't want. Either way, you can manipulate the list by just editing the <ul> with jQuery.




回答2:


Another option is to define a list of times, as Date objects. Check the dates option. Each timepicker has timeView property, which actually is the popup element. This object has a dataBind method, which accepts a list of Date objects:

var timeView = $("#timepicker").data("kendoTimePicker").timeView;

//bind list
timeView.dataBind([new Date()]);

You can use this method to dynamically update list of the available times.

Nevertheless, you always can modify the UL element, like the CodingWithSpike suggested.



来源:https://stackoverflow.com/questions/14630096/kendo-ui-timepicker-custom-interval-format

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