How to escape hash character # in column template ?

6 posts, 0 answers
  1. johnsk
    johnsk avatar
    8 posts
    Member since:
    Sep 2012

    Posted 14 May 2012 Link to this post


    I need to output a link <a href="#"></a> inside the column template of the grid.
    How do i escape the hash character as i now get javascript error when trying to put directly like this

    { field: "Name", title: "Name", template: '<a href="#">#=Name#</a>' } 

    Hope to hear from you soon!
  2. Alexander Valchev
    Alexander Valchev avatar
    2895 posts

    Posted 15 May 2012 Link to this post

    Hi John,

    You can escape hash characters with double backslash ("\\"). In your case the template should look like this:

    template: '<a href="\\#">#= Name #</a>'

    Kind regards,
    Alexander Valchev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Mike
    Mike avatar
    2 posts
    Member since:
    Nov 2011

    Posted 26 Feb 2013 Link to this post

    Hi Alexander,

    This does not appear to work the same in a child grid. I assume this is because the \\# has a special meaning in a child grid. I tried using just a # sign and also \\\\#, but neither worked. Please let me know how I can get this to work in a child grid as I'm trying to put an anchor tag that calls a javascript function and I need the href='#' in there.

    Thank you.
  4. Mike
    Mike avatar
    2 posts
    Member since:
    Nov 2011

    Posted 26 Feb 2013 Link to this post

    A quick Google search told me that I can use href='javascript:myFunction(argument)' instead of the onclick event. Forgive me, I'm still learning the ways of the interwebs, apparently. 

    I'm still curious what the escape sequence is for the pound sign in a child grid. 

  5. Ian
    Ian avatar
    5 posts
    Member since:
    Mar 2009

    Posted 10 Aug 2017 in reply to Mike Link to this post

    For anyone looking, it is \\\\\\


    columns.Template(@<text></text>).ClientTemplate("<a href='Jobs\\\\\\#/Page/\\#=JobId\\#'>View</a>").Width(50);

  6. Boyan Dimitrov
    Boyan Dimitrov avatar
    2062 posts

    Posted 15 Aug 2017 Link to this post


    More information about Kendo UI Templates engine in general and escaping hash symbols in templates can be found in the Templates Overview article. 

    Boyan Dimitrov
    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.
Back to Top