Kendo UI MVVM and the Grid: Example 01

Introduction to binding an editable Grid to a ViewModel

by siliconsoul

HTML

<link rel="stylesheet" href="http://cdn.kendostatic.com/2012.2.710/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2012.2.710/styles/kendo.default.min.css">
<script src="http://cdn.kendostatic.com/2012.2.710/js/kendo.all.min.js"></script>
<div id="people">
    <div data-role="grid" 
         data-bind="source: people" 
         data-editable="inline" 
         data-toolbar='["create"]' 
         data-columns='[{"field": "firstName", "title": "First Name"}, 
                        {"field": "lastName", "title": "Last Name"},
                        { "command": ["edit", "destroy"] } ]'>
    </div>
</div>

JavaScript

var peopleDataSource = new kendo.data.DataSource({
    data: [
        { id: 1, firstName: "John", lastName: "DeVight" },
        { id: 2, firstName: "Wendy", lastName: "Parry" }
    ],
     schema: {
        model: {
            id: "id"
        }
    }
});

// Create an observable object.
var vm = kendo.observable({
    people: peopleDataSource
});

kendo.bind($("#people"), vm);