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

KendoUI onRowDataBound replacement?

1 Answer 470 Views
Grid
This is a migrated thread and some comments may be shown as answers.
RGTech
Top achievements
Rank 1
RGTech asked on 31 Mar 2013, 10:41 PM
 Hi,

I'm migrating a project from ASP.NET MVC Extensions to KendoUI. I'm trying to figure out the best way to re-create this grid binding using KendoUI and without any serverside code. I can't find anything to do with onRowDataBound or similar in the documentation.

As you can see, as each row is databound, it attaches the countdown jquery plugin (http://keith-wood.name/countdown.html) and uses the current dataItem's Due datetime value.

Is the only way to do this using javascript inside the <script id="rowTemplate" type="text/x-kendo-tmpl"> element?

How can I recreate this to work with KendoUI?
function onRowDataBound(e) {
 
     e.row.cells[2].innerHTML = "<span class='countdown-" + e.dataItem.SONumber + "'></span>"
 
     if (e.dataItem.Due != null && e.dataItem.Due < new Date(2015, 4, 1) && e.dataItem.Due > new Date(2011, 4, 1)) {
         $('.countdown-' + e.dataItem.SONumber).countdown({
             until: new Date(Date.parse(e.dataItem.Due)), compact: true,
             layout: '<strong>{dn} {dl} {hnn}{sep}{mnn}{sep}{snn}</strong>',
         });
     }
 
 
 }

This is sample output for one row once it has been rendered:
<tr style="background: none repeat scroll 0% 0% rgb(255, 134, 112);">
   <td>43475</td>
   <td>New</td>
      <td>
         <span class="countdown-43475 hasCountdown">
            <strong>0 d 00:00:00</strong>
         </span>
      </td>
   <td>Account</td>
   <td>Description</td>
   <td>Cons</td>
   <td class="t-last">P3 - 24H</td>
</tr>
Thanks

1 Answer, 1 is accepted

Sort by
1
Accepted
RGTech
Top achievements
Rank 1
answered on 01 Apr 2013, 12:21 AM
After much perseverance, I actually got this working.

Found this gem at the bottom of the Migration from Telerik MVC Extensions document.
This shows you how to use the datasource to go through each data item
Note: to use the data, the this.view() function doesn't appear to exist - I got it working by using this._data;

http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/migration/widgets/grid

function onDataBound() {
   var data = this._data;
  
   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)
   }
}
Tags
Grid
Asked by
RGTech
Top achievements
Rank 1
Answers by
RGTech
Top achievements
Rank 1
Share this question
or