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

[Solved] Displaying Selected Grid Row Details

3 Answers 139 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kevin
Top achievements
Rank 1
Kevin asked on 11 Oct 2010, 11:32 PM
Hello, I appreciate any help here.  I'm displaying a list of items using the grid control.  The list comes from the model of a strongly-typed view.  I've defined an onRowSelected() handler that grabs the currently selected item ID from a hidden column.  However, I need to update other controls in the view with information from the selected list item.  Since I can't access the model from JavaScript, to my knowledge, the JavaScript event handlers don't seem to do any good.  There's no point in running an ajax query since the information has already been provided to the client as part of the model.

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 12 Oct 2010, 08:38 AM
Hi Kevin,

You can access the data item to which a row is bound using the grid client-side method dataItem:

function onRowSelected(e) {

   var grid = $(this).data('tGrid');

   var row = e.row;

   var dataItem = grid.dataItem(row);

}

Regards,

Atanas Korchev
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Kevin
Top achievements
Rank 1
answered on 12 Oct 2010, 04:56 PM
Thanks Atanas.  This is very helpful.  However, I'm getting a JavaScript error in the dataItem function of telerik.grid.min.js which states that 'this.data' is null or not an object.

This occurs when the line:

var dataItem = grid.dataItem(row);

is executed from the provided code.

My grid is marked as selectable and the client OnRowSelect event is obviously firing since the JavaScript is being executed.

Thanks,

Kevin
0
Atanas Korchev
Telerik team
answered on 13 Oct 2010, 07:40 AM
Hi Kevin,

 The dataItem method works for ajax bound grids. You can use it only if this is the case. Make sure you are not initially server-binding your grid -> Html.Telerik().Grid(Model)

All the best,
Atanas Korchev
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Kevin
Top achievements
Rank 1
Share this question
or