k-grid url change

by valchev

HTML

<script src="http://cdn.kendostatic.com/2012.1.322/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.metro.min.css">
<div id="example">
    <input id="dropdown"/>
    <div id="grid"></div>
</div>

JavaScript

var id = "";
var dataSource = new kendo.data.DataSource({
    transport: {
        read: {
            //using jsfiddle echo service to simulate JSON endpoint
            //url: "/echo/" + id, //this will not work
            url: function(options) {
                var url = "/echo/json/" + id;
                alert("Read request to " + url); 
                return "/echo/json/"; //in your case the variable "url" should be returned
            },
            dataType: "json",
            type: "POST",
            data: {
                // /echo/json/ echoes the JSON which you pass as an argument
                json: JSON.stringify([
                    {
                    "text": "Item1",
                    "value": 1},
                {
                    "text": "Item2",
                    "value": 2},
                {
                    "text": "Item3",
                    "value": 3}
                ])
            }
        }
    }
});

$("#grid").kendoGrid({
    dataSource: dataSource,
    columns: ["text", "value"]
});

$("#dropdown").kendoDropDownList({
    dataTextField: "text",
    dataValueField: "value",
    dataSource: [
        {
        "text": "Item1",
        "value": 1},
    {
        "text": "Item2",
        "value": 2},
    {
        "text": "Item3",
        "value": 3}
    ],
    change: function() {
        id = this.value();
        dataSource.read();
    }
});