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

Can't get selectedItem in DataGrid when using rowTemplate

2 Answers 174 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dariel
Top achievements
Rank 1
Dariel asked on 23 Jan 2012, 07:51 PM
Hi guis, thx before everything:

I'd like to use the amazing Kendo's Grid to take soma advantages like paging, filtering through DataSource and more.
 As I show up in ths fiddle http://jsfiddle.net/dsubiros/5fXZq/ , I can't get selectedItem when I'm using a rowTemplate.

In this example if I change the attribute columns by " columns: ['OrderID', 'ShipName'] ", and comment out the rowTemplate attribute, grid works as expected, but I need to be able to use a template, and still get grid's selected row.

$("#grid").kendoGrid({
   dataSource: dataSource,
   pageable: true,
   selectable: true,
   rowTemplate: kendo.template($("#rowTemplate").html()),
   columns: [''],
   change: function() {
   var id = this.select().data("id");
   $("#log").html("LOG: selected id = " + id);
}
});

Please help me out.

2 Answers, 1 is accepted

Sort by
0
Dariel
Top achievements
Rank 1
answered on 23 Jan 2012, 10:13 PM
Hi again:

I found a temporal solution.
In the html template set a hidden field(or visible if you want to show it) with the item id from the template value. Ex:

..
<b id="${id}" style="display: hidden"></b>
<b>Ship Name: </b>${ ShipName }<br/>
..

then in grid's change event, we can capture the selected row's item id by using in a jQuery selector the class "k-state-selected", because that's the one that is put to a row when selected:

var id = $('.k-state-selected b:first').attr('id')

Then you can use this id.

Hope this helps somebody, but I'm waiting for the a KendoUI team developers solution, included in the framework.

Dariel
0
Mauro
Top achievements
Rank 1
answered on 13 Jul 2012, 07:06 PM
Hi, I found a temporal easy solution, change first TR with
 <tr data-uid="#= uid #">
Tags
Grid
Asked by
Dariel
Top achievements
Rank 1
Answers by
Dariel
Top achievements
Rank 1
Mauro
Top achievements
Rank 1
Share this question
or