We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to perform Template binding for node with serialization support?

Platform: ASP.NET MVC |
Control: Diagram |
Published Date: January 9, 2015 |
Last Revised Date: May 30, 2019

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

2X faster development

The ultimate ASP.NET MVC UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon