createConnection

Adds an empty connection data item and a popup window will be displayed.

Example - create a connection

<button id="createBtn">Create Connection</button>
<div id="diagram"></div>
<script>
  $("#createBtn").on("click", function(){
    var diagram = $("#diagram").getKendoDiagram();
    diagram.createConnection();
  });
  var serviceRoot = "https://demos.telerik.com/kendo-ui/service";

  var shapesDataSource = {
    batch: false,
    transport: {
      read: {
        url: serviceRoot + "/DiagramShapes",
        dataType: "jsonp"
      },
      update: {
        url: serviceRoot + "/DiagramShapes/Update",
        dataType: "jsonp"
      },
      destroy: {
        url: serviceRoot + "/DiagramShapes/Destroy",
        dataType: "jsonp"
      },
      create: {
        url: serviceRoot + "/DiagramShapes/Create",
        dataType: "jsonp"
      },
      parameterMap: function (options, operation) {
        if (operation !== "read") {
          return { models: kendo.stringify(options.models || [options]) };
        }
      }
    },
    schema: {
      model: {
        id: "id",
        fields: {
          id: { from: "Id", type: "number", editable: false },
          JobTitle: { type: "string" },
          Color: { type: "string" }
        }
      }
    }
  };

  var connectionsDataSource = {
    batch: false,
    transport: {
      read: {
        url: serviceRoot + "/DiagramConnections",
        dataType: "jsonp"
      },
      update: {
        url: serviceRoot + "/DiagramConnections/Update",
        dataType: "jsonp"
      },
      destroy: {
        url: serviceRoot + "/DiagramConnections/Destroy",
        dataType: "jsonp"
      },
      create: {
        url: serviceRoot + "/DiagramConnections/Create",
        dataType: "jsonp"
      },
      parameterMap: function (options, operation) {
        if (operation !== "read") {
          return { models: kendo.stringify(options.models || [options]) };
        }
      }
    },
    schema: {
      model: {
        id: "id",
        fields: {
          id: { from: "Id", type: "number", editable: false },
          from: { from: "FromShapeId", type: "number" },
          to: { from: "ToShapeId", type: "number" },
          fromX: { from: "FromPointX", type: "number" },
          fromY: { from: "FromPointY", type: "number" },
          toX: { from: "ToPointX", type: "number" },
          toY: { from: "ToPointY", type: "number" }
        }
      }
    }
  };

  $("#diagram").kendoDiagram({
    layout: {
      type: "layered"
    },
    dataSource: shapesDataSource,
    connectionsDataSource: connectionsDataSource,
    editable: {
      tools: ["edit"]
    },
    connectionDefaults: {
      editable: {
        tools: ["edit"]
      }
    }
  });
</script>
In this article
Not finding the help you need? Improve this article