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

匿名 (未验证) 提交于 2019-12-03 01:57:01

问题:

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

 

Thanks :)

回答1:

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(....) 


回答2:

Please try with the below code snippet.

       Test

I have implemented same thing with different way.



回答3:

It could be because of the property pageable -> pageSizes: true.

Remove this and check again.



回答4:



回答5:

It is important to define an id in the model

.DataSource(dataSource => dataSource         .Ajax()         .PageSize(20)         .Model(model => model.Id(p => p.id))     ) 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!