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

Reference Templates by ID when defining controls in .Net

4 Answers 144 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
FAYE SCHAB
Top achievements
Rank 1
FAYE SCHAB asked on 21 Jun 2013, 02:57 PM
It seems like the only way to define templates for controls declared with .Net syntax is to use escaped literal text. Whereas if the control is declared with javascript syntax, one can embed the template content in a named/ID'ed script tag and reference that ID. Is there any way to accomlish this with .Net syntax?

4 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 25 Jun 2013, 02:19 PM
Hello Faye,

Please give concrete examples (snippets) when describing the problem so we can understand what exactly you mean.

Basically the sharp symbols inside templates should be escaped because they are are used to evaluate client expressions.

http://docs.kendoui.com/getting-started/framework/templates/overview


Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
FAYE SCHAB
Top achievements
Rank 1
answered on 25 Jun 2013, 02:49 PM
Here's an example of a .Net (Razor) declared Kendo Grid
@(Html.Kendo().Grid(userOrgUnits)
    .Name("UserOrgUnitsGrid")
    .Columns(columns =>
        {
            columns.Template(e => { }).ClientTemplate(" ").Title("Org Unit");
            columns.Bound(userOrgUnit => userOrgUnit.OrgUnitTypeName).Title("Type").Width(90);
        })
    .DataSource(dataSource => dataSource
        .Ajax())
    .Scrollable()
    .Resizable(resize => resize.Columns(true))
    .ClientRowTemplate(
        "#var ouActiveClass = Active ? active_const : inactive_const;#" +
        "#var uActiveClass = UserActive ? active_const : inactive_const;#" +
            "#isAltRow = ++rowIndex % 2 == 0;# "+
            "#var altRowClass = isAltRow ? altRow_const : '';#" +
            "<tr role='row' class='#= altRowClass #'> " +
            "<td class='userOrgUnit'>" +
                "<div class='userOrgUnitName'><a href='/#=OrgUnitTypeName#/details/#=OrgUnitID#'>#=OrgUnitName #</a></div>" +
                "#if(CustomerName != null){#"+
                        " <div class='userOrgUnitCustomer'><a href='/Customer/details/#=CustomerId#'>#=CustomerName #</a></div>" +
                    "#}#"+
            "</td>" +
                "<td>"+
                    "#=OrgUnitTypeName#" +
                "</td>" +
        "</tr>")
)
Basically I want all that goo in the ClientRowTemplate in a template script and be able to reference it by ID as if I had declared this control with javascript. i.e. kendo.template($("#template-id").html()
0
Accepted
Petur Subev
Telerik team
answered on 26 Jun 2013, 07:15 AM
Hello again Faye,

I am afraid that such configuration is not supported out of the box. However I can suggest you one of the following approaches.

If you want to stick with the <script type="text/kendo-template">  script element and place your template inside you can use the following:

    //... your other Grid configuration
    .ClientRowTemplate("#=kendo.template($('\\#myTemplate').html())(data)#")
)
 
 
<script type="text/kendo" id="myTemplate">
    This is a way to use shared template #=PersonID #
</script>


Another way is to use function instead of template and it could look like this:


        .ClientRowTemplate("#=myFormattingFunction(data)#")
)
<script type="text/javascript">
    function myFormattingFunction(model) {
        return "This could be even more convenient to format the row" + model.PersonID
    }
</script>

I hope this helps.

Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
FAYE SCHAB
Top achievements
Rank 1
answered on 26 Jun 2013, 03:46 PM
Ah, there we go I like those answers.
Tags
General Discussions
Asked by
FAYE SCHAB
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
FAYE SCHAB
Top achievements
Rank 1
Share this question
or