Kendo: How to loop through each row in a Grid

kendouigridfinal.pngHere’s the most efficient way to loop though a list of rows in a Kendo Grid after the grid has data bound:

Step 1: Add a dataBound event assignment to a Kendo Grid (MVC example):

.Events(builder => builder.DataBound(“dataBound”))

 

 

Step 2: Loop through rows in a Kendo Grid

function dataBound(e) {
  
  var grid = this;
  var dataSource = grid.dataSource;
  //Loop through each record in a Kendo Grid
  $.each(grid.items(), function(index, item) {
        var uid = $(item).data("uid");
        var dataItem = dataSource.getByUid(uid);
        //Add an ID to each row as an example
        $(item).attr("id", dataItem.SomeField + "-" 
                 + dataItem.AnotherField);
   });
}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s