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

Unable to display SVG inside Grid Column Template

1 Answer 41 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Antony
Top achievements
Rank 1
Antony asked on 15 Nov 2019, 01:29 PM

In CSHTML page, I am able to display the icon image that is in SVG.

<svg class="em-c-btn__icon " data-em-icon-path="dist/unity-1.1.0/images/em-icons.svg">
         <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="dist/unity-1.1.0/images/em-icons.svg#icon-link"></use>
</svg>

However, it is not being displayed when it is bounded to Template column in Grid. 

Code for CSHTML

@(Html.Kendo().Grid<UserModel>()
        .Name("Grid")
        .Columns(columns =>
        { columns.Template("#=actionTemplate(data)#").Title("Actions").Media("(min-width: 450px"); })))

<script id="action-template" type="text/x-kendo-template">
    <svg class="em-c-btn__icon " data-em-icon-path="dist/unity-1.1.0/images/em-icons.svg">
            <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="dist/unity-1.1.0/images/em-icons.svg#icon-link"></use>
        </svg>
</script>

<script>
    var actionTemplate = kendo.template($("#action-template").html());
</script>

Please advise

1 Answer, 1 is accepted

Sort by
0
Petar
Telerik team
answered on 18 Nov 2019, 04:19 PM

Hi Antony,

Try escaping the "#" sign in the template as follows:

<script id="action-template" type="text/x-kendo-template">
    <svg class="em-c-btn__icon " data-em-icon-path="dist/unity-1.1.0/images/em-icons.svg">
            <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="dist/unity-1.1.0/images/em-icons.svg\\#icon-link"></use>
        </svg>
</script>

The escaping is achieved by adding two backslashes before the "#" sign. 

Let me know if this resolves the issue. 

Regards,
Petar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Antony
Top achievements
Rank 1
Answers by
Petar
Telerik team
Share this question
or