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

e.dataItem on Grid DataBound

1 Answer 104 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tejas
Top achievements
Rank 1
Tejas asked on 25 Jun 2013, 11:05 AM
I have following code and I am getting e.dataItem as undefined. Is there a way to get access to dataItem and its properties at client using JavaScript?

Html.Kendo().Grid<AdminReport>()   
.Name("AdminReportList")
.Columns(c =>        
{
c.Bound(r => r.Name).Title("Report Name").Width(50);                    
c.Bound(r => r.Id).Title(action).Width(230).Sortable(false).Filterable(false)
})
.Pageable(p => p.PreviousNext(true))
.Sortable()
.Filterable()   
.Events(e => e.DataBound("onRowBound"))   
.DataSource(d => d       
.Ajax()       
.Model(m => m.Id(r => r.Id))       
.Read(read => read.Action("_ListAllReports", "AdminReports"))       
.Events(e => e.Error("OnError")))
.Render();
function onRowBound(e) {
    
  if ((e.dataItem.SomeProperty === true)) {
       //Some code...
    }
 
}

1 Answer, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 26 Jun 2013, 07:40 AM
Hi Tejas,


The dataBound is fired after the Grid has bounded all of the data, not on each row bound. I am not sure if you are referring to the OnRowDataBound event of the Telerik Grid. Please take a look at the following Migration page, which describes this and also other differences of our Grids.

Going back to the current case, a workaround would be to traverse the dataSource view for the current page, access each row and get it's dataItem.
E.g.
function onDataBound() {
    var data = this.view();
 
    for (var i=0; i< data.length; i++) {
        var dataItem = data[i];
        var tr = $("#grid").find("[data-uid='" + dataItem.uid + "']");
        // use the table row (tr) and data item (dataItem)
    }
 }

I hope that this information was helpful for you.

 

Regards,
Dimiter Madjarov
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
Tejas
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Share this question
or