【问题标题】:Is it possible to filter the selectable days in the Kendo UI datepicker?是否可以在 Kendo UI 日期选择器中过滤可选择的日期?
【发布时间】:2015-01-21 04:10:19
【问题描述】:

有谁知道是否可以传入天数来限制 Kendo UI 日期选择器中可选择的天数?

例如 - 只选择周一至周五..

<input kendo-date-picker=""    
       ng-model="dateString"
       days="[0,1,2,3,4]"/>

【问题讨论】:

  • 我认为日期选择器没有这样的功能。也许将 JS 函数绑定到日期选择器的 Change 事件,并在那里检查它是一周还是周末。如果是周末,e.preventDefault(); 应该避免选择
  • @chiapa 谢谢,但我希望这一天变成灰色并且只读。

标签: angularjs kendo-ui telerik


【解决方案1】:

Kendo DatePicker 没有这样的功能:之前是 has been asked in the Telerik forum,他们的回答是“当前不支持该行为”。

有一个UserVoice 项目正在请求创建它。

这是一个模拟您想要的自定义解决方法:

$(document).ready(function() {

  var p = $("#datepicker").kendoDatePicker({
    value: new Date(), //setting the value to "today"
    open: function(e) {
      $(".disabledDay").parent().removeClass("k-link");
      $(".disabledDay").parent().removeAttr("href");
      $('.k-weekend a').bind('click', function() {
        return false;
      });
    }
  }).data("kendoDatePicker");
});
.k-weekend {
  background-color: silver;
}
.k-weekend:hover {
  background-color: silver !important;
}
.k-weekend a:hover {
  background-color: silver !important;
}
.k-calendar a:hover {
  background-color: red;
}
<!DOCTYPE html>
<html>

<head>
  <link href="http://cdn.kendostatic.com/2013.3.1119/styles/kendo.common.min.css" rel="stylesheet" type="text/css" />
  <link href="http://cdn.kendostatic.com/2013.3.1119/styles/kendo.default.min.css" rel="stylesheet" type="text/css" />
  <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
  <script src="http://cdn.kendostatic.com/2013.3.1119/js/kendo.all.min.js"></script>
  <meta charset=utf-8 />
  <title>KendoUI Example</title>
</head>

<body>
  <input id="datepicker" style="width:150px;" />

</body>

</html>

我知道这并不理想,但由于小部件本身不存在该功能,因此只有通过变通方法我们才能获得这种行为。有了这个,你就不能选择周末了,在 CSS 上稍微花点时间就可以实现你想要的。

【讨论】:

  • 感谢您的样品。同意它并不理想,但总比没有好。会接受你的回答。
猜你喜欢
  • 2010-09-19
  • 1970-01-01
  • 2013-07-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-24
  • 1970-01-01
  • 2015-04-12
相关资源
最近更新 更多