Update node text

hello,

Please if can help about how i can update selected treeview node text using javascript from textbox.

Regards,


5 Replies

KR Keerthana Rajendran Syncfusion Team March 1, 2022 01:06 PM UTC

Hi Jack, 
 
Thanks for contacting Syncfusion support. 
 
You can update the selected node text from textbox using updateNode method. 
 
 var text = document.getElementById('editor').value; 
  var node = treeObj.selectedNodes[0]; 
  var element = treeObj.element.querySelector('[data-uid="' + node + '"]'); 
  var node = treeObj.getNode(element); 
  treeObj.updateNode(node.idtext); 
 
 
We have prepared a sample for your reference. 
 
 
 
Please let us know if you need any further assistance. 
 
Regards, 
Keerthana R. 



RP Ranjani Prabakaran Syncfusion Team March 3, 2022 04:40 AM UTC

A new ticket, #369543has been assigned to you. jack abdallah has created the ticket with the following comments. 
hello, 
Thank you for the fast and accurate response and it was exactly what i am looking for. 
 
just one more question is it possible to update the node text without setting allowediting:true due that i don't that user update the node details from Treeview and only from form. 
 
thank you again for the help, 
Best Regards, 



KR Keerthana Rajendran Syncfusion Team March 4, 2022 07:11 AM UTC

Hi Jack, 
 
Most welcome.  
 
To update the node text without setting allowEditing as true, we can use the refreshNode method of TreeView which will refresh the specified node with updated text.  
 
Refer to the following code. 
 
document.getElementById('update').addEventListener('click'function () { 
  var text = document.getElementById('editor').value; 
  var node = treeObj.selectedNodes[0]; 
  var element = treeObj.element.querySelector('[data-uid="' + node + '"]'); 
  var node = treeObj.getNode(element); 
  var obj = { 
    id: node.id, 
    name: text, 
    selected: true, 
  }; 
  treeObj.refreshNode(node.id, [obj]); //refresh the node with new text. 
}); 
 
 
 
 
Please let us know if you need any further assistance. 
 
Regards, 
Keerthana R. 
 



JA jack March 4, 2022 08:38 PM UTC

hello,

Thank you again for your response.

It worked perfectly as provided.


thanks for your professional response.


Best Regards,



RP Ranjani Prabakaran Syncfusion Team March 7, 2022 06:18 AM UTC

Hi Jack, 
 
 
We are glad to hear that the given solution works. Please contact us if you need any further assistance. 


Regards,
 

Ranjani
 


Loader.
Up arrow icon