I'm using a custom edit popup template for my Kendo grid, the Add New Row and edit use the same template, when the custom popup template is opened on Add New Row, is there any way to set a default value for one of the fields?
1 Answers
4
votes
Default values for the fields should be set in the schema.model definition of the dataSource:
schema.model Object kendo.data.Model The data item (model) configuration.
If set to an object, the Model.define method will be used to initialize the data source model.
If set to an existing kendo.data.Model instance, the data source will use that instance and will not initialize a new one.
Example - set the model as a JavaScript object
<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>
Example - set the model as an existing kendo.data.Model instance
<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>