Reference Templates by ID when defining controls in .Net

5 posts, 1 answers
  1. FAYE SCHAB
    FAYE  SCHAB avatar
    4 posts
    Member since:
    Mar 2009

    Posted 21 Jun 2013 Link to this post

    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?
  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 25 Jun 2013 Link to this post

    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!
  3. FAYE SCHAB
    FAYE  SCHAB avatar
    4 posts
    Member since:
    Mar 2009

    Posted 25 Jun 2013 Link to this post

    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()
  4. Answer
    Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 26 Jun 2013 Link to this post

    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!
  5. FAYE SCHAB
    FAYE  SCHAB avatar
    4 posts
    Member since:
    Mar 2009

    Posted 26 Jun 2013 Link to this post

    Ah, there we go I like those answers.
Back to Top