How to escape hash character # in column template ?
3 Answers 1400 Views
johnsk
Top achievements
Rank 1
johnsk asked on 15 May 2012, 03:48 AM
Hello!

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!

3 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 15 May 2012, 07:33 AM
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!
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.
- by
Mike
Top achievements
Rank 1
on 26 Feb 2013, 03:08 PM
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. 

Thanks.
- by
Mike
Top achievements
Rank 1
on 26 Feb 2013, 03:21 PM
0
Ian
Top achievements
Rank 1
answered on 10 Aug 2017, 11:49 AM

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

e.g.

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

0
Boyan Dimitrov
Telerik team
answered on 15 Aug 2017, 06:32 AM

Hello,

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

Regards,
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.
Tags
Grid
Asked by
johnsk
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Ian
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Share this question
or