Hi,
Thanks for your answer. It works on a existing node. In my case, the context menu add a new node. In that context (see code below) it doesn't work.
The node and the connector are created in the database via an ajax call. They are added to the diagram in the ajax response:
function addNode(selectedItem, type) {
const color = getColor(type);
var description = `New ${type} name`;
// Call controller to add the new node
const newNode = {
Description: description,
Type: type,
QuarterId: selectedItem.QuarterId,
OrganizationId: selectedItem.OrganizationId,
SourceId: selectedItem.SymuId,
SourceType: selectedItem.Type
};
const jsonNode = JSON.stringify(newNode);
$.ajax({
type: "POST",
url: '/Objective/AddNode',
data: { json: jsonNode },
datatype: "text",
success: function(response) {
if (response.success) {
const addNodeId = parseInt(response.id);
const node = {
id: type.substring(0, 1) + addNodeId,
style: { fill: color },
Description: description,
Color: color,
SymuId: addNodeId,
Type: type,
QuarterId: selectedItem.QuarterId,
OrganizationId: selectedItem.OrganizationId
};
const connector = {
id: 'connector' + ej.diagrams.randomId(),
sourceID: selectedItem.id,
targetID: node.id
};
diagram.add(node);
diagram.add(connector);
diagram.doLayout();
diagram.startTextEdit(node.id);
} else {
alert('Something went wrong!');
}
}
});
}