Search code examples
kendo-grid

How can I scan a Kendo Grid and get each rows data?


How can I scan a Kendo Grid and retrieve each row and its data. I am trying the following but can't seem to see the data :

var grid = $("#mygrid");
var columns = $("#mygrid").data("kendoGrid").columns;
var rows = $("#mygrid").data("kendoGrid").dataSource.data().length;
var noOfCols = columns.length;
var allrows = $("#mygrid").data("kendoGrid").items();                        
$("#mygrid").data("kendoGrid").items().each(function (a) {
    alert(a.text());
});

I need to check the value of a column in each row and if it is not a certain value the report tot the user. Thanks


Solution

  • Try this:

    Get Kendo Grid Selected Cell value:

    var grid = $('#GridName').data("kendoGrid");
    var selectedItem = grid.dataItem(grid.select());
    var selectedValue = selectedItem.YourPropertyColumnName;
    

    For selecting a row by index number use the following:

    $('#GridMaster').data("kendoGrid").bind('dataBound', function (e) {
        this.element.find('tbody tr:eq(3)').addClass('k-state-selected')
        //or >>>
        var index = 3;
        this.element.find('tbody tr:eq(' + index + ')').addClass('k-state-selected')
    });
    

    Alternatively, in order to display the first row always "selected" in Kendo Grid:

    $(function () {
        $('#GridMaster').data("kendoGrid").bind('dataBound', function (e) {
        this.element.find('tbody tr:first').addClass('k-state-selected')
        });
    });