Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

197
Views
jQuery Kendo Grid calling a function from template

Background: I am attempting to work on a grid where one column can have different editor based on the column value in a Grid. I found a working example on Telerik site. It works great!

Issue: I like to separate out html code in html file vs jquery code in js file. Once I separated out the code like this I am getting an error which says "customTemplate is not defined". customTemplate is a function which is being called from template under field editor. I also created a JsFiddle of what my code looks like locally where i seem to be getting same error.

I think the problem is around template attribute where I am calling the customTemplate function. I tried swapping the double quotes to single quotes and that didn't seem to work either.

Below is how grid and customTemplate function is defined:

   $("#grid").kendoGrid({
      dataSource: dataSource,
      columns: [
        { field: "id" , title: "ID" },
        { field:"type" , title: "Type" },
        { field: "editor",
          title: "Editor",
           template: "#=customTemplate(data.type,data.editor)#",
          editor: chooseEditor
        }],
      editable: true
    });
  });

 function customTemplate(type,value) {
    if (value == null)
      return "";

    switch (type) {
      case "date":
        return kendo.toString(kendo.parseDate(value), 'yyyy/MM/dd');
      default:
        return value;
    }
  }

Here is the screenshot of the ReferenceError I get

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use a function to call your function instead of a template string:

{
  field: 'editor',
  title: 'Editor',
  template: function(dataItem) {
    return customTemplate(dataItem.type, dataItem.editor);
  },
  editor: chooseEditor
}

Fiddle: https://dojo.telerik.com/AluziYAc

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!