Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught TypeError : cannot read property 'replace' of undefined In Grid

Tags:

I'm new in using Kendo Grid and Kendo UI . My question is how can i resolve this Error

Uncaught TypeError: Cannot read property 'replace' of undefined  

This is my Code on my KendoGrid

$("#Grid").kendoGrid({             scrollable: false,             sortable: true,             pageable: {                 refresh: true,                 pageSizes: true             },             dataSource: {                 transport: {                     read: {                         url: '/Info/InfoList?search=' + search,                         dataType: "json",                         type: "POST"                     }                  },                 pageSize: 10             },             rowTemplate: kendo.template($("#rowTemplate").html().replace('k-alt', '')),             altRowTemplate: kendo.template($("#rowTemplate").html())         }); 

Line that Causes the Error

rowTemplate: kendo.template($("#rowTemplate").html().replace('k-alt', '')), 

HTML of rowTemplate

 <script id="rowTemplate" type="text/x-kendo-tmpl">            <tr class='k-alt'>             <td>                 ${ FirstName } ${ LastName }             </td>         </tr>             </script> 
like image 719
Ren Tao Avatar asked Apr 29 '14 02:04

Ren Tao


People also ask

How do you fix undefined properties Cannot be read?

To solve the "Cannot read properties of undefined" error, make sure that the DOM element you are accessing exists. The error is often thrown when trying to access a property at a non-existent index after using the getElementsByClassName() method. Copied!

What does Cannot Read Property replace of undefined mean?

The "Cannot read property 'replace' of undefined" error occurs when calling the replace() method on a variable that stores an undefined value. To solve the error, make sure to only call the replace method on data types that implement it, e.g. strings.


1 Answers

I think jQuery cannot find the element.

First of all find the element

var rowTemplate= document.getElementsByName("rowTemplate"); 

or

var rowTemplate = document.getElementById("rowTemplate");  

or

var rowTemplate = $('#rowTemplate'); 

Then try your code again

rowTemplate.html().replace(....) 
like image 198
Dr.Nyanpasu Avatar answered Sep 17 '22 19:09

Dr.Nyanpasu