我正在为我的Kendo网格使用自定义编辑弹出模板,添加新行和编辑使用相同的模板,当在Add New Row上打开自定义弹出模板时,有没有办法设置默认值其中一个领域?
答案 0 :(得分:2)
字段的默认值应在dataSource的schema.model定义中设置:
schema.model对象kendo.data.Model 数据项(模型)配置。
如果设置为对象,则Model.define方法将用于初始化数据源模型。
如果设置为现有的kendo.data.Model实例,则数据源将使用该实例,并且不会初始化新实例。
示例 - 将模型设置为JavaScript对象
<script>
var dataSource = new kendo.data.DataSource({
schema: {
model: {
id: "ProductID",
fields: {
ProductID: {
//this field will not be editable (default value is true)
editable: false,
// a defaultValue will not be assigned (default value is false)
nullable: true
},
ProductName: {
//set validation rules
validation: { required: true }
},
UnitPrice: {
//data type of the field {Number|String|Boolean|Date} default is String
type: "number",
// used when new model is created
defaultValue: 42,
validation: { required: true, min: 1 }
}
}
}
}
});
</script>
示例 - 将模型设置为现有的kendo.data.Model实例
<script>
var Product = kendo.data.Model.define({
id: "ProductID",
fields: {
ProductID: {
//this field will not be editable (default value is true)
editable: false,
// a defaultValue will not be assigned (default value is false)
nullable: true
},
ProductName: {
//set validation rules
validation: { required: true }
},
UnitPrice: {
//data type of the field {Number|String|Boolean|Date} default is String
type: "number",
// used when new model is created
defaultValue: 42,
validation: { required: true, min: 1 }
}
}
});
var dataSource = new kendo.data.DataSource({
schema: {
model: Product
}
});
</script>