Obtain the associated Id for RadRating on RadGrid from JavaScript

Milton

I have a RadRating element for each row in a RadGrid, and need to get the associated Id for the row where the RadRating is being Rated (but with Javascript), however, the get_parent() method is returning the grid reference and not the row.

How can I get the GridDataItem of the row of the RadRating?

The following code works sometimes but not all the time. What am I doing wrong?

Milton

This is what I found. `get_parent()` method does not return the row at all. What I was seeing was red herring. `get_parent` returns the parent control which is the grid, then to find which rows it belongs I found two options:

1) Obtain the HTML element and go through the parent nodes until finding the rows and get the `rowIndex`. And use that index to obtain the respective `DataItem` from the grid.

Viktor Tachev

In order to get reference of the GridDataItem client-side you can use the OnClientRating handler. It would look similar to the one below:

function OnClientRating(sender, args) {

var parentTableView = sender.get_parent();

var rowID = $telerik.$(sender.get_element()).closest("tr")[0].id;

var rowIndex = rowID.split("__")[1];

var dataItem = parentTableView.get_dataItems()[rowIndex];

var someCellText = dataItem.get_cell("ColumnUniqueName").innerHTML;

// add custom logic here

}

Give the approach a try and let me know how it works for you.

Regards,
Viktor Tachev
Telerik

Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items

Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.