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. Image for the cookie policy date

How to avoid length node names when repeatedly copy/pasting same node

Hi,

Today, if a user copies and pastes the same node several times, we can end up with names like this:

TaskSUVHcHPwiimioCiWMQ0DvZUEBrE1EAddPTHRVyIkwqJ80CgS
TaskSUVHcHPwiimioCiWMQ0DvZUEBrE1EAddPTHRVyIkwqJ80CgSGH0T
TaskSUVHcHPwiimioCiWMQ0DvZUEBrE1EAddPTHRVyIkwqJ80CgSGH0TZXq7
TaskSUVHcHPwiimioCiWMQ0DvZUEBrE1EAddPTHRVyIkwqJ80CgSGH0TZXq7IDMw
TaskSUVHcHPwiimioCiWMQ0DvZUEBrE1EAddPTHRVyIkwqJ80CgSGH0TZXq7IDMwkO75
TaskSUVHcHPwiimioCiWMQ0DvZUEBrE1EAddPTHRVyIkwqJ80CgSGH0TZXq7IDMwkO75vZZE
TaskSUVHcHPwiimioCiWMQ0DvZUEBrE1EAddPTHRVyIkwqJ80CgSGH0TZXq7IDMwkO75vZZEvr5A

Ideally I would like the pasted node to have a net new name rather than simply appending a new random string to the existing name (although the base name from the palette must be at the beginning - e.g., Task in the above samples).

I looked at the documentation and noticed that the paste method accepts 2 arguments:

paste([object], [rename])

However, I don't always have an object - in fact we have a clone function that copies ALL nodes on a diagram and pastes them on a new diagram. I was hoping I could do something like diagram.paste(,true) or diagram.paste(true) since object is optional, but that doesn't paste anything.

Any suggestions on how to avoid these lengthy names?

Thanks

Jim




1 Reply

KR Kameshwaran R Syncfusion Team December 12, 2016 04:51 AM UTC

Hi Jim, 
 
Hi,

Today, if a user copies and pastes the same node several times, we can end up with names like this:

TaskSUVHcHPwiimioCiWMQ0DvZUEBrE1EAddPTHRVyIkwqJ80CgS
TaskSUVHcHPwiimioCiWMQ0DvZUEBrE1EAddPTHRVyIkwqJ80CgSGH0T
TaskSUVHcHPwiimioCiWMQ0DvZUEBrE1EAddPTHRVyIkwqJ80CgSGH0TZXq7
TaskSUVHcHPwiimioCiWMQ0DvZUEBrE1EAddPTHRVyIkwqJ80CgSGH0TZXq7IDMw
TaskSUVHcHPwiimioCiWMQ0DvZUEBrE1EAddPTHRVyIkwqJ80CgSGH0TZXq7IDMwkO75
TaskSUVHcHPwiimioCiWMQ0DvZUEBrE1EAddPTHRVyIkwqJ80CgSGH0TZXq7IDMwkO75vZZE
TaskSUVHcHPwiimioCiWMQ0DvZUEBrE1EAddPTHRVyIkwqJ80CgSGH0TZXq7IDMwkO75vZZEvr5A

Ideally I would like the pasted node to have a net new name rather than simply appending a new random string to the existing name (although the base name from the palette must be at the beginning - e.g., Task in the above samples).
 
Please use the following code snippet to achieve your requirement. 
 
 
nodeCollectionChange: function (args) { 
    if (args.cause === "clipBoard") { 
        args.cancel = true; 
        var diagram = $("#diagram").ejDiagram("instance"); 
        var node = args.element; 
        node.name = ej.datavisualization.Diagram.Util.randomId(); 
        console.log(node.name); 
        diagram.add(node); 
    } 
} 
I looked at the documentation and noticed that the paste method accepts 2 arguments:

paste([object], [rename])

However, I don't always have an object - in fact we have a clone function that copies ALL nodes on a diagram and pastes them on a new diagram. I was hoping I could do something like diagram.paste(,true) or diagram.paste(true) since object is optional, but that doesn't paste anything.
 
 
Currently we don’t have option to pass the null or undefined as first argument of the paste method, Since the diagram.paste method renders only the object passed as first argument. So only the paste method doesn’t paste anything if we passed empty object as first object. 
 
 
Regards, 
Kameshwaran R. 
 


Loader.
Live Chat Icon For mobile
Up arrow icon