This is a migrated thread and some comments may be shown as answers.

Calling a text/x-kendo-template script type from a javascript function

4 Answers 2407 Views
Templates
This is a migrated thread and some comments may be shown as answers.
Allan
Top achievements
Rank 1
Allan asked on 14 Jul 2017, 02:14 PM

I have a custom button on scheduler's toolbar and on "onclick" event I'm calling function "openEditor()". Inside this function I want to call a `text/x-kendo-template` script type. How can I do this?

My code right now:

Custom button:

schedulerToolbar.append(
"<ul class='k-reset'>
   <li class='k-state-default'>
     <a role='button' href='#' class='k-link newMeetingButton' onclick='openEditor()'>
       Nova reserva
     </a>
   </li>
</ul>"
)

Function openEditor():

function openEditor() {
   *code to call customEditorTemplateBh script*
 }

Template script:

<script id="customEditorTemplateBh" type="text/x-kendo-template">
   *template code*
</script>

 

4 Answers, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 17 Jul 2017, 06:38 AM
Hi Allan,

See the second example in this documentation article, which demonstrates how the template's content can be shown:
//Get the external template definition using a jQuery selector
var template = kendo.template($("#javascriptTemplate").html());
 
//Create some dummy data
var data = ["Todd.Holland", "Steve.Anglin", "Burke.Ballmer"];
 
var result = template(data); //Execute the template
$("#example").html(result); //Append the result


Regards,
Ivan Danchev
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Allan
Top achievements
Rank 1
answered on 20 Jul 2017, 06:47 PM

Hi Ivan.

Thank you for your reply.

I found a more simple solution for this case. The following code, on openEditor function, was enough:

var scheduler = $("#scheduler-bh").data("kendoScheduler");
scheduler.addEvent({ });
0
Accepted
Ivan Danchev
Telerik team
answered on 24 Jul 2017, 08:21 AM
Hi Allan,

Indeed calling the Scheduler's addEvent method is the correct way to open the edit form programmatically, whereas the approach I mentioned in my previous reply can be used to show the content of a template in general, not the Scheduler's editor template specifically.

Regards,
Ivan Danchev
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Allan
Top achievements
Rank 1
answered on 24 Jul 2017, 12:47 PM

Ivan, you are right.

I forgot to mention that it's a Scheduler's editor template.

Tags
Templates
Asked by
Allan
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Allan
Top achievements
Rank 1
Share this question
or