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>
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!
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.
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(....)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With