1

I want to build SVG paths with Kendo templates binding with MVVM view model. See this JS fiddle.

Known Issue:

In Firefox, when we inspect the SVG element and edit that SVG tag element (right click and select "Edit SVG") then the SVG is rendering.

But in IE 10, no path tags are found in the SVG tag.

HTML Code:

<div class="canvasTabContainer leftFloat" style="height: 522px;">
    <div class="canvasHolder workflowContainer_#= tabId #">
        <div class="canvasContainer relPosition">
            <svg id="edges_#= tabId #" width="100%" data-template="canvasEdges_renderer" data-bind="source: edges" height="99%" class="pAbsolute" style=""></svg>
            <div id="items_#= tabId #" class="items relPosition" data-template="canvasItems_renderer" data-bind="source: items"></div>
        </div>
    </div>
</div>
<script id="canvasItems_renderer" type="text/x-kendo-template">
    < div class = "canvasMatrixCell"
    itemid = "#=id#" > Item# = id# < /div>
</script>
<script id="canvasEdges_renderer" type="text/x-kendo-template">
    < path d = "#= svgPath #"
    class = "js-no-pan edgeStyle" > < /path>
</script>

JavaScript:

var canvasViewModel = [{
    "id": 1
}];
var canvasEdgeModel = [{
    "svgPath": "M382,121.5L396,121.5s 10 0 10 -10L406,50.5s 0 -10 10 -10L430,40.5M427,36.5L431,40.5L427,44.5"
}];

var canvasViewModel = kendo.observable({
    items: canvasViewModel,
    edges: canvasEdgeModel
});
kendo.bind($(".canvasHolder"), this.canvasViewModel);

It is not working in Firefox 29.0.1 & IE 10.

Toothbrush
  • 2,080
  • 24
  • 33
Sivakumar
  • 1,477
  • 2
  • 18
  • 35
  • Hi Select Smile. your fiddle was not working even in chrome so i've tried to do some changes and i got it working in chrome but not in FF/IE. I've updated your js fiddle – Strikers May 29 '14 at 06:34
  • Could be similar to [this](http://stackoverflow.com/q/20637771/628006)? – рüффп Jun 07 '14 at 09:23

1 Answers1

1

OK, I've found a way around the problem.

It seems that Kendo is manipulating the DOM, and the browser doesn't re-render the element.

The work-around I used was to give the parent node an id (canvasContainer) and refresh the innerHTML of canvasContainer after the call to kendo.bind.

I also noticed that your fiddle had a mistake (# = id# instead of #= id#), corrected that, and manually improved the source formatting.

HTML:

<div class="canvasTabContainer leftFloat" style="height: 522px;">
    <div class="canvasHolder workflowContainer_#= tabId #">
        <div class="canvasContainer relPosition" id="canvasContainer">
            <svg id="edges_#= tabId #" width="100%" data-template="canvasEdges_renderer" data-bind="source: edges" height="99%" class="pAbsolute" style=""></svg>
            <div id="items_#= tabId #" class="items relPosition" data-template="canvasItems_renderer" data-bind="source: items"></div>
        </div>
    </div>
</div>
<script id="canvasItems_renderer" type="text/x-kendo-template">
    <div class="canvasMatrixCell" itemid="#=id#">Item#= id#</div>
</script>
<script id="canvasEdges_renderer" type="text/x-kendo-template">
    <path d="#= svgPath #" class="js-no-pan edgeStyle"></path>
</script>

JavaScript:

var canvasViewModel = [{
    "id": 1
}];
var canvasEdgeModel = [{
    "svgPath": "M382,121.5L396,121.5s 10 0 10 -10L406,50.5s 0 -10 10 -10L430,40.5M427,36.5L431,40.5L427,44.5"
}, {
    "svgPath": "M788,40.5L836,40.5M833,36.5L837,40.5L833,44.5"
}, {
    "svgPath": "M179,40.5L227,40.5M224,36.5L228,40.5L224,44.5"
}, {
    "svgPath": "M585,40.5L633,40.5M630,36.5L634,40.5L630,44.5"
}, {
    "svgPath": "M179,121.5L227,121.5M224,117.5L228,121.5L224,125.5"
}];

var canvasViewModel = kendo.observable({
    items: canvasViewModel,
    edges: canvasEdgeModel
});
kendo.bind($(".canvasHolder"), this.canvasViewModel);

// Added
document.getElementById('canvasContainer').innerHTML += '';

See http://jsfiddle.net/qqzmZ/16/ for the working example.

Toothbrush
  • 2,080
  • 24
  • 33
  • Thanks @toothbrush, What you have suggested is working in firefox but not in IE. Path tags are not created in SVG tag. – Sivakumar Jun 09 '14 at 05:03
  • @SelectSmile Have you tried using `` in the `head`? – Toothbrush Jun 09 '14 at 12:48
  • I also tried to put meta tag in head. But no luck with IE 10/11. For reference http://jsbin.com/gacic/1/edit – Sivakumar Jun 10 '14 at 04:05
  • Can you please look at this http://www.telerik.com/forums/svg-is-not-rendering-with-kendo-templates-in-firefox-and-ie. If you get any idea please share with me. – Sivakumar Jun 10 '14 at 04:29
  • @SelectSmile I'm not sure what to do. I've tried that, but it doesn't work. – Toothbrush Jun 10 '14 at 09:20
  • IE 10/11 do not support the `innerHTML` property on SVG elements. This may be the cause for the limited success of this approach. – Sampson Dec 24 '14 at 01:11