Working with Kendo Data Model

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

Read more about it here

You can create Kendo UI Model as following,

image

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

image

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.

image

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

image

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

image

If you change above model as following, you will get true in alert since id of model is not set.

image

In this way you can work with Kendo.data.model. I hope you find this post useful. Thanks for reading.

 

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.