Fix: Kendo Grid Template gives error “Unable to get value of the property ‘replace’: object is null or undefined”

I got the lovely unhelpful error “Unable to get value of the property ‘replace’: object is null or undefined” from the Kendo Grid when I added a template to a column. This was a completely useless error that led me to staring at the javascript stack and walking through the minified code. Which, by the way, is very painful to look through obfuscated minified code.

After entirely too long analyzing the code, I finally figured out the root cause. I had an ever so small typo in my template retrieval declaration and it was returning back a null template. Why on earth didn’t the Telerik guys NULL check this and fire a friendly error? All of two lines of code would have saved me some trouble.

See, javascript is entirely too friendly to typing mistakes.

Here is the errant code:

    {
                             title: "Planning", width: "100px",                                       
                             template: kendo.template($("myPortfolio_PlanningTemplate").html())
                         },

Here is the fixed code.

    {
                             title: "Planning", width: "100px",                                       
                             template: kendo.template($("#myPortfolio_PlanningTemplate").html())
                         },

Painful lesson in remember to put in the hashtag for ID lookups. Easy to forget when in a hurry.

Happy Coding!

Leave a Reply

Your email address will not be published. Required fields are marked *