【问题标题】:Kendo-ui Grid: Can the standard HTML5 input date-time be used as a cell editor?Kendo-ui Grid:标准 HTML5 输入日期时间可以用作单元格编辑器吗?
【发布时间】:2015-02-08 00:52:27
【问题描述】:

我一直在尝试使用标准 html5 输入作为 kendo-ui 网格中的单元格编辑器 即

<input type="datetime-local" value="1996-12-19T16:39:57" />

我喜欢这个日期时间小部件,因为您可以使用箭头键转到每个日期时间组件,然后使用向上向下箭头编辑日期时间的那部分。

我已经尝试定义以下单元格模板函数..

 function timeEditor(container, options) {
    var input = $('<input "datetime-local" name="' + options.field +'" />')
   input.appendTo(container);        
 }

并将其提供给列定义中的相应字段..

columns: [
  {
    field: "Time",
    title: "Time",
    width: "180px",
    editor: timeEditor,       
  },

编辑器已实例化(我在其中遇到了一个断点),但我没有让控件按预期显示。

我对剑道用户界面相当陌生(我正在试用它),所以也许我在这里有一些简单的错误?或者可以用这个吗?

提前感谢您的帮助 问候,彼得

【问题讨论】:

  • 请注意,“本地日期时间”输入在许多浏览器中都不起作用。
  • 感谢@dandavis,我看到了(谷歌搜索后)。

标签: javascript jquery html kendo-ui kendo-grid


【解决方案1】:

你做对了,只是你的 HTML 是错误的。

<input "datetime-local ...

缺少type= 属性名称,应该是:

<input type="datetime-local ...

另外请记住,在自定义编辑器中,如果有人更改输入框的值,您将不得不进行设置值和更新数据的工作,因此您可能需要添加 .on('change' ...)事件处理程序。

一个完整的编辑器看起来像这样:

function timeEditor(container, options) {
    var input = $('<input type="datetime-local" name="'
        + options.field
        +'" value="'
        + options.model.get(options.field)
        + '" />');
    input.on('change', options.model.set(options.field, input.val()));
    input.appendTo(container);        
 }

【讨论】:

  • 感谢@CodeWithSpike!现在看来这肯定行得通。令人遗憾的是,对这个控件的支持很少(如上所述),它可能是我见过的处理日期和时间的最好的控件之一(至少我在 Chrome 中得到的那个)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-09
  • 1970-01-01
相关资源
最近更新 更多