This is a migrated thread and some comments may be shown as answers.

Select row by dataItem condition

1 Answer 2059 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sven
Top achievements
Rank 1
Sven asked on 20 Jun 2013, 01:26 PM
Hi,

I am trying to programmatically select a row in a Grid depending on some dataItem value. My current approach is to loop through the rows in the DataBound event handler. So far I can find the row, but when I try to select it by using addClass("k-state-selectable") I get a "Object doesn't support this method or property" error.
Here is my code:

function gServices_DataBound(e) {
try {
var servicesGrid = $("#gServices").data("kendoGrid");
if (servicesGrid) {
var selServiceName = '@ViewData["SelServiceName"]';
if (selServiceName) {
// loop thorugh grid rows and select the service with that name
$("#gServices tr").each(function () {
var di = servicesGrid.data(this);
if (di.Name == selServiceName) {
// found the dataItem
// => select it
$(this).addClass("k-state-selected");
}
});
}
}
}
catch (ex) {
alert('gServices_DataBound: Exception: ' + ex.message);
}
}

Any ideas how I can loop through the set of rows and select the one I want programmatically?

Regards
Sven

1 Answer, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 21 Jun 2013, 06:28 AM
Hello Sven,

The code for selecting a row based on underlying data should be similar to the following:

function dataBoundHandler()
{
  var grid = this;
  grid.items().each(function() {
    var data = grid.dataItem(this);
    //some condition
    if (data.ShipCountry == "Brazil") {
     grid.select(this);
    }
  });
}

Regards,
Nikolay Rusev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Sven
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question
or