【问题标题】:Restrict Kendo Grid inline numeric text box editor to positive numbers only将 Kendo Grid 内联数字文本框编辑器限制为仅正数
【发布时间】:2015-12-16 11:37:54
【问题描述】:

我有一个启用了内联编辑的 Kendo Grid,其中有一个用于编辑数值的数字文本框:

$("#g_Points").kendoGrid({
    dataSource: viewModel.myList,
    columns: [
        { field: "Name", title: "Name", width: 250, editor: function (element, options) { element.text(options.model.Name) } },
        { field: "Available", title: "Points", width: 90, editable: true }
    ],
    editable: true,
    save: function (arg) {  
        arg.model.Available = arg.values.Available;
        saveRow(arg.model);
        this.cancelChanges();
    },
    scrollable: true
});

它工作正常,但我需要将“可用”字段限制为仅正数。

我试过了:

...
{ field: "Available", title: "Points", width: 90, editable: true, editor: myEditorFunction }
...

function myEditorFunction (container, options) {
    $('<input/>')
        .appendTo(container)
        .kendoNumericTextBox({
            min: 0
        });
}

它仅限于正数,但保存功能不再起作用。我可以编辑值,但是当我离开单元格编辑时,值会恢复为默认值。

如何将我的内联数字文本框限制为仅正数?

【问题讨论】:

    标签: kendo-ui kendo-grid


    【解决方案1】:

    让它工作,这就是我所做的:

    $("#g_Points").kendoGrid({
        dataSource: new kendo.data.DataSource({
            data: viewModel.myList,
            schema: {
                model: {
                    fields: {
                        Available: { type: "number", validation: { required: true, min: 0 } }
                    }
                }
            }
        }),
    

    【讨论】:

      【解决方案2】:

      看起来您必须将输入的名称属性设置为字段的名称。

      function myEditorFunction (container, options) {
          $('<input name="' + options.field + '" />')
              .appendTo(container)
              .kendoNumericTextBox({
                  min: 0
              });
      }
      

      请参阅here 了解更多信息。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-04
        • 1970-01-01
        • 2020-09-02
        • 1970-01-01
        • 1970-01-01
        • 2016-01-01
        相关资源
        最近更新 更多