Articles in this section
Category / Section

How to perform Template binding in ASP.NET MVC Diagram?

7 mins read

You can embed the SVG, HTML element into node using templateId property and the embedded SVG, HTML elements can be bounded with node’s properties using JSRender templates.

Native Node

Diagram supports to embed SVG element into node. It is achieved by setting node shape’s type as ej.datavisualization.Diagram.Shapes.Native and assigns the template id to the shape’s templateId property.

Note:
  1. Refer to the “jsrender.min.js” file for template binding support.
  2. Template (HTML/ SVG tags) have to be retained in application side as only its ID is saved during Diagram’s save method.
  3. SVG or HTML element defined in script tag cannot be displayed in the browser.

 

The following code illustrates how a Native node is created.

JS

//dependency scripts
<script src="http://borismoore.github.io/jsrender/jsrender.min.js"></script>
<script id="svgTemplate" type="text/x-jsrender">
  <g id="{{:text}}">
<path d="M 58.813 0 H 3.182 L 30.998 24.141 L 58.813 0 Z M 32.644 34.425 C 32.133 34.87 31.567 35.095 31 35.095 S 29.867 34.87 29.353 34.425 L 1 9.826V 60 H 61 V 9.826 L 32.644 34.425Z"></path>
            <text x="20" y="45">{{:text}} </text>   </g></script>  
var node = {
            shape: { type: ej.datavisualization.Diagram.Shapes.Native,                 templateId: "svgTemplate" },
            text:"Mail";
        }

CSHTML

//dependency scripts
<script src="http://borismoore.github.io/jsrender/jsrender.min.js"></script>
<script id="svgTemplate" type="text/x-jsrender">
  <g id="{{:text}}">
<path d="M 58.813 0 H 3.182 L 30.998 24.141 L 58.813 0 Z M 32.644 34.425 C 32.133 34.87 31.567 35.095 31 35.095 S 29.867 34.87 29.353 34.425 L 1 9.826V 60 H 61 V 9.826 L 32.644 34.425Z"></path>
            <text x="20" y="45">{{:text}} </text>   </g></script>  

Controller

//CustomNode derived from Node class
CustomNode node = new CustomNode ();
node.Shape = new Shape(Shapes.Native);
//Set the templateId
node.Shape.TemplateId = "svgTemplate";
node.Text="Mail";

ASPX

//dependency scripts
<script src="http://borismoore.github.io/jsrender/jsrender.min.js"></script>
<script id="svgTemplate" type="text/x-jsrender">
  <g id="{{:text}}">
<path d="M 58.813 0 H 3.182 L 30.998 24.141 L 58.813 0 Z M 32.644 34.425 C 32.133 34.87 31.567 35.095 31 35.095 S 29.867 34.87 29.353 34.425 L 1 9.826V 60 H 61 V 9.826 L 32.644 34.425Z"></path>
            <text x="20" y="45">{{:text}} </text>   </g></script>  

ASPX.CS

//CustomNode derived from Node class
CustomNode node = new CustomNode ();
node.Shape = new Shape(Shapes.Native);
//Set the templateId
node.Shape.TemplateId = "svgTemplate";
node.Text="Mail";

 

Render a SVG node

Figure 1: Native Shape

HTML Node

You can embed the HTML elements in Diagram through HTML shape node. It is achieved by setting node shape’s type as ej.datavisualization.Diagram.Shapes.Html and assigns the template id to the shape’s templateId property. The following code illustrates how an HTML node is created.

JS

//dependency scripts
<script src="http://borismoore.github.io/jsrender/jsrender.min.js"></script>
<script id="htmlTemplate" type="text/x-jsrender">
        <div>
            <input type="button" value="{{:value}}" />
        </div>
 </script>
  var node = {
            shape: { type: ej.datavisualization.Diagram.Shapes.Html, templateId: "htmlTemplate" },            
            value: "button"
        }

CSHTML

//dependency scripts
<script src="http://borismoore.github.io/jsrender/jsrender.min.js"></script>
<script id="htmlTemplate" type="text/x-jsrender">
        <div>
            <input type="button" value="{{:value}}" />
        </div>
 </script>

Controller

//CustomNode derived from Node class
CustomNode node = new CustomNode ();
node.Shape = new Shape(Shapes.Html);
//Set the templateId
node.Shape.TemplateId = "htmlTemplate";
node.Value="button";

ASPX

//dependency scripts
<script src="http://borismoore.github.io/jsrender/jsrender.min.js"></script>
<script id="htmlTemplate" type="text/x-jsrender">
        <div>
            <input type="button" value="{{:value}}" />
        </div>
 </script>

ASPX.CS

//CustomNode derived from Node class
CustomNode node = new CustomNode ();
node.Shape = new Shape(Shapes.Html);
//Set the templateId
node.Shape.TemplateId = "htmlTemplate";
node.Value="button";

 

Render an HTML node

Figure 2: HTML Shape

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied