e.dataItem on Grid DataBound

2 Answers 3615 Views
Grid
Tejas
Top achievements
Rank 1
Tejas asked on 25 Jun 2013, 11:00 AM
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
    }
 
}
I am getting e.dataItem as undefined. Is there a way to get access to dataItem and model properties?

2 Answers, 1 is accepted

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


This is a quote from my answer in the other forum thread.



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 followingMigration 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 would like to ask you to post your questions only once, so we would be able to provide you the best possible assistance.

I wish you a great day!

Regards,
Dimiter Madjarov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Teguh
Top achievements
Rank 1
commented on 16 Dec 2015, 07:32 AM

It's not working this.view(); raised exception
0
Dimiter Madjarov
Telerik team
answered on 16 Dec 2015, 11:50 AM

Hello Teguh,

There is an error in the code snippet from the previous post. You should invoke

this.dataSource.view();
instead.

I hope this information helps.

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