Thursday, February 2, 2012

KendoUI : Row Selection

Here is an example which shows how to select a row and saving
a grid instance after creation.
Notice that we register the grid in 'dataBound' event, otherwise
we register an empty grid !!!

var grid;
     
function RegisterGrid(g) {
      grid = g;
      grid.select(grid.tbody.find(">tr").eq(3));         
}

$(document).ready(function () {
    var grid = $("#grid").kendoGrid({

        dataBound : function(e) {          
             RegisterGrid($("#grid").data("kendoGrid"));          
        },
        columns:
            [{
                field: "id",
                title: ""
            
           
            },
                {
                field: "Email",
               title: "Email"
            }],

        dataSource: {
            transport: {
                read: {
                    type: "POST",
                    url: "http://localhost/WebService.asmx/GetAdmin?name=Paul&age=12",
                    data: [],
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    async: true
                }
            },
            schema: {
                data: "d",
                model: {
                    fields: {
                        id: { type: "number" },
                        Email: { type: "string" }
                    }
                },
                total : function (r) {
                   
                }
            },
        },
        selectable: "row",
        navigatable: true,
        sortable: true,
        pageable: true,

        change: function (arg) {          
            var selected = $.map(this.select(), function (item) {
                alert(item.cells[0].innerHTML);                
            });
        },        
    });   
})

No comments:

Post a Comment