This is a migrated thread and some comments may be shown as answers.

Kendo UI control's initialization - what is the good approach

1 Answer 70 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Marcin asked on 24 Jun 2015, 02:40 PM

Hi :) 

In my web application I am using Kedno UI Controls for implementing front-end side controls and user interaction. Most of the web application code is written in java-script, so the general approach is to go client side.

On the Kendo UI demo website, we have 2 approaches for initializing kendo grid in case of using MVVM pattern and bindings (as a sample control, but this should apply to other controls):

1/ Data attribute initialization - part of example for brevity

<div data-role="grid"
     data-toolbar="['create', 'save']"
                    { 'field': 'ProductName', 'width': 270 },
                    { 'field': 'UnitPrice' },
     data-bind="source: products,
                visible: isVisible, events: { save: onSave }"
     style="width: 480px; height: 200px">

Full example:

2/ Custom binding (angular way) - part of example for brevity

<div kendo-grid data-bind="options: mainGridOptions">
Javascript file - ViewModel/Controller - Scope ect...
.mainGridOptions = {
            dataSource: {
                type: "odata",
                transport: {
                    read: "<url...>"
                pageSize: 5,
            sortable: true,
            pageable: true,
            columns: [{
                field: "FirstName",
                title: "First Name",
                width: "120px"
                field: "LastName",
                title: "Last Name",
                width: "120px"
                field: "Country",
                width: "120px"

In the binding for the grid, we pass all required options for particular control. Full similar angular example:

Concerning information above I have these questions:

  • Which approach is better and why (pron and cons) - to use data attributes for settings or to keep all the control settings in the view model in js and bind it easy to the control like angular does? Taking into account long term application development - support of tools and frameworks (i.e. Typescript), complex settings for controls
  • Is this bad idea or breaks MVVM pattern in anyway, that view model contains kendo object after it was initialized, so view model knows what is the control behind it? Of course not in every case, but in the situation when we need to do some workaround on our kendo control in js. In this case we don't need to use jquery selector to get control's data, because binding will give us a reference to the kendo control in the view model after its initialization.

This approach was implemented in Kendo Binding for Angular -> Leverage Widget References.

Thank you all for the feedback and answers.

1 Answer, 1 is accepted

Sort by
Alexander Valchev
Telerik team
answered on 26 Jun 2015, 09:29 AM
Hello Marcin,

The two approaches are completely different. First one uses Kendo MVVM while the second is intended to be used when customers want to use Kendo UI widgets in AngularJS applications. If you do not develop AngularJS application use the first approach.

In case you develop AngularJS application you should follow the second approach where settings are defined in the view controller. For more information regarding Kendo UI Angular JS integration please check this help topic:

Alexander Valchev
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Asked by
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question