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

[Solved] Difference in templates using attribute syntax

1 Answer 223 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Russ
Top achievements
Rank 1
Russ asked on 19 Nov 2014, 08:54 PM
[This issue may also exist using other syntax, but I don't think so.]

Taking the following grid declaration as an example (some things have been removed for simplicity).

<div id="userInfo"
      data-role="grid"
      data-columns='[{field:"FirstName", title: "First", width: "9%"},
           {field:"LastName", title: "Last", width: "10%"},
           {field:"UserId", title: "ID", width: "10%", template:IdTemplate } ]'
      data-edit="editHandler"
      data-detail-template='MessageTemplate'>
</div>

In this editHandler is the name of a function, and this works fine.

If IdTemplate is the name of a function, then that works fine.  Alternately, a valid template string may be placed where IdTemplate is.  However, it may not be the name of an element containing a template that can be processed by kendo.template.  You also cannot use  kendo.template($("#IdTemplate").html()), either (and this is documented here: http://www.telerik.com/forums/how-to-declaratively-set-mvvm-data-column-template-to-external-template- )

However, MessageTemplate apparently must be the name of an element (normally this object would be a script element) that contains the template that can be processed by kendo.template.  It may not be a function name.  You may not replace it with a valid template string.  This appears to be a convenient shorthand from the function call syntax where one would normally have to do something like kendo.template($("#MessageTemplate").html())

Obviously, this is an inconsistency in the way templates are declared between the row detail template and the column template..  I am concerned if I develop code depending on one of these mechanisms, that it will be altered by a later version of Kendo UI.

Thoughts?

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 21 Nov 2014, 03:52 PM
Hi Russ,

The reason is that the column template is not direct (top level) configuration option of the widget. The ID shorthand is supported only for top level options.
We realize that this creates a syntax difference which is why we put examples in the documentation. Changing the current behaviour is not in our immediate plans and even if we introduce such change in the future it shouldn't break the existing projects after upgrade. If the behaviour changes it will be because we added more opportunities for specifying the template without removing the existing ones.

Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Russ
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or