transfer data to DataSource

by valchev

HTML

<script src="http://cdn.kendostatic.com/2012.1.515/js/kendo.all.min.js"></script>
<link rel="stylesheet" href="http://cdn.kendostatic.com/2012.1.322/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2012.1.322/styles/kendo.default.min.css">
<div id="grid1"></div>
<br /><br />
<div id="grid2"></div>

JavaScript

var dataSource1 = new kendo.data.DataSource({
    transport: {
        read: {
            //using jsfiddle echo service to simulate JSON endpoint
            url: "/echo/json/",
            dataType: "json",
            type: "POST",
            data: {
                // /echo/json/ echoes the JSON which you pass as an argument
                json: JSON.stringify([
                    {"foo":1, "bar": 1},
                    {"foo":2, "bar": 2},
                    {"foo":3, "bar": 3},
                    {"foo":4, "bar": 4},
                    {"foo":5, "bar": 5},
                    {"foo":6, "bar": 6},
                    {"foo":7, "bar": 7},
                    {"foo":8, "bar": 8},
                    {"foo":9, "bar": 9}
                ])
            }
        }
    },
    schema: {
        model: {
            id: "foo",
            fields: {
                foo: {type: "number"},
                bar: {type: "number"}                
            }
        }            
    },
    change: function() {
        //this.view() => array, current view of dataSource1
        dataSource2.data(this.view());
    }
});

var dataSource2 = new kendo.data.DataSource({
    data: [] //initially the dataSource2 is empty
});

$("#grid1").kendoGrid({
    dataSource: dataSource1,
    columns: ["foo", "bar"],
    filterable: true //enable editing
});

$("#grid2").kendoGrid({
    dataSource: dataSource2,
    columns: ["foo", "bar"]
});