I would like to use an external template for a column in my grid.
Of course this doesn't work, as it just prints 'myTemplate' on each row of that column. I know I can inline the template but I would like to keep things tidy by having the template external. Is this possible with the kendo mvc extensions?
7 Answers, 1 is accepted
To achieve this you should first initialize the template and then pass it as a client template to the column. Here is a sample approach.
Have a great day!
I also needed this and your example works fine. However, I defined the 2 <script>'s further down in the view, below the Kendo MVC Grid configuration, and yet it still worked. I would think since the kendo.template() is run after the Kendo MVC grid setup that it would not work. Does the Kendo MVC Grid get run after <script>'s, or is this a timing thing and I got lucky?
Should the <script> that runs kendo.template() be executed before the Kendo MVC grid or does it matter? Thanks.
In this case the data is bound via ajax, so the client template will only be evaluated after the items are requested. This is why there should no be timing issues depending on the placement of the external script block.Regards,
I have test the ClientTemplate() with kendo external template works perfect,
but Is there have any way to pass the custom arguments into kendo template script ?
<script id="columnTemplate" type="text/x-kendo-template">
#= myArg1 #
#= myArg2 #
columns.Bound(p => p.Active).ClientTemplate("#=myTemplate(data, 'myValue1', 'myValue2')#");
*myArg1 = 'myValue1'.
Nonetheless, the arguments are passed on:
If this is not the desired result, please provide some more details about the desired outcome, so we can look into possible approaches to accomplish it.