javascript - 如何使 "add new record"将字段表示为复选框 - Kendo Grid

标签 javascript kendo-ui kendo-grid

我正在尝试向剑道网格添加新记录(仅使用客户端 JavaScript),但我只能获取以文本字段表示的所有字段。

然而,其中一个字段实际上是一个 bool 值,我希望将其表示为复选框。有谁知道如何做到这一点?

有人可以帮忙吗?任何帮助将不胜感激。

使用下面的代码进行了更新。我还尝试了模板建议,但当我单击网格顶部的添加新记录按钮时,这不起作用。我收到 JavaScript 错误“primary 未定义”

$("#phoneGrid").kendoGrid({
                            columns: [
                                {
                                    field: "type",
                                    title: "Type"
                                },
                                {
                                    field: "primary",
                                    title: "Primary",
                                    template: "<input type=\"checkbox\" #= primary ? checked='checked' : '' #/>"
                                },
                                {
                                    field: "number",
                                    title: "Number"
                                },
                                { command: ['edit'], title: ' ' }
                            ],
                            editable: "inline",
                            dataSource: {
                                data: patientDetailUpdateViewModel.phones,
                                schema: {
                                    model: { id: "id" }                                    
                                }
                            },
                            toolbar: ['create'],
                            save: function (e) {
                                //alert("Save Event Triggered");
                                if (e.model.isNew()) {
                                    phone = new Phone();
                                    //Give the phone an id to uniquely identify it, but one which would signify a new phone instance (negative phone instance).
                                    phone.id = patientDetailUpdateViewModel.phones.length * -1;
                                    e.model.id = phone.id;//So isNew() will return false on subsequent calls. 
                                    phone.type = e.model.type;
                                    phone.primary = e.model.primary;
                                    phone.number = e.model.number;
                                    patientDetailUpdateViewModel.phones.push(phone);
                                    //alert("isNew() = true");
                                }
                            }
                        });

最佳答案

您可以使用模板进行列定义:

{     
  field: "ColumName",
  template: '<input type="checkbox" #= Column? checked="checked" : "" # disabled="disabled" ></input>'
}

编辑:

尝试如下定义数据源模型( http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-schema.model ),但要根据源中的数据类型:

schema: {
    model: {
      id: "ProductID",
      fields: {
        type: {
          type: "string"
        },
        UnitPrice: {
          type: "number"
        }
      }
    }
}

关于javascript - 如何使 "add new record"将字段表示为复选框 - Kendo Grid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29640986/

相关文章:

javascript - 动态生成html和js,生成意外的引用

javascript - 让div在滚动时淡入淡出

javascript - 如何对齐垂直:middle filter icon in Kendo UI Grid Header

c# - Kendo UI DropDownList 更改触发事件

javascript - 在 JavaScript 中对网格数据进行排序。排序函数出错

javascript - 如何检测已在 Kendo UI 网格中创建网格行?

JavaScript 函数在某个 if 语句后停止

Javascript - 检测表单按钮按下

javascript - 将 rangey 与 Kendo Editor 结合使用

kendo-ui - Kendo Grid - oData - Web API - 服务器端分页、过滤 - 十进制类型