Kendo.data.model provides the ability to define schema. Inside schema fields with various attributes and methods can be defined. It is inherited from ObservableObject
You can create Kendo UI Model as following,
Even though at first glance above syntax looks verbose but it is very straight forward. You can create a new model by creating a variable of type kendo.data.model
- First we define identifier of the model. This can be any field of the model. It is defined by setting id attribute
- Different fields of model can be created in field attribute
For example, if you want to create a model for Student, you can do that as following
In Student model
- There are three fields name , rollnumber and marks
- Rollnumber is set as identifier field of this model.
- Type of the fields is set in the type attribute.
You can create object of a model as below.
You can controls fields behavior and can configure many details like following
- Default value can be set
- Editable behavior can be set
- Null behavior can be set
- Default parsing function for a field can be set.
- Validation rules can be set
You can configure various attributes as following
Name filed in the model is created with different attributes. For example this name field is editable and its default value is dj.
You can determine that whether a model is new or not using isNew method. Consider below instance of Student model, you will get false as output. If model identifier is set then Kendo framework does not consider that as new
If you change above model as following, you will get true in alert since id of model is not set.
In this way you can work with Kendo.data.model. I hope you find this post useful. Thanks for reading.
Follow @debug_mode