我正在尝试向剑道网格添加新记录(仅使用客户端 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/