This is a migrated thread and some comments may be shown as answers.

How to add node with ID

8 Answers 1025 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Thai
Top achievements
Rank 1
Thai asked on 21 Dec 2011, 05:11 AM
Hi,

I used method append to add new node to selected node:
treeview.append(
   {
       text: $("#text").val()
   },
   selectedNode
);

But how can I append node with ID?
somethings like:
treeview.append(
   {
       text: $("#text").val(),
       id: "some id"
   },
   selectedNode
);

thanks,
Thai.

8 Answers, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 26 Jan 2012, 04:51 PM
I also would like to know the answer to this plus why does the append not display straight away?
0
FieldTRAKS
Top achievements
Rank 1
answered on 29 Feb 2012, 08:53 PM
this does not work for me either....i can't imagine a scenario where doing this kind of thing wouldn't be needed...can someone please answer this thread...seems like a big bug to me....basically you cannot add any attributes besides the node text using the append method
0
Piotr Jarocki
Top achievements
Rank 1
answered on 01 Mar 2012, 11:25 AM
same thing here, i cant add custom attribute
0
Alexander Valchev
Telerik team
answered on 05 Mar 2012, 12:04 PM
Hi guys,

The idea has been already shared in our uservoice page, so if you wish you can give your votes for it here. The more votes it collects, the sooner it will be planned.


Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Aron
Top achievements
Rank 1
answered on 03 Apr 2012, 11:34 AM
Until this option is added Ive managed to find a work around.   Its not brilliant but will add a node with an ID.

Basically after you have initialised your treeview like so:

$
("#treeView").kendoTreeView({
    dragAndDrop: true
});


and you have appneded your node like so:

var treeView = $("#treeView").data("kendoTreeView");
treeView.append({ text: "Item 3" }, $("#n2"));


use the find node by text funciton to find the node just added and apply an attribute ID and set it to whatever you wish.

var foundNode = treeView.findByText("Item 3");
foundNode.attr("id", "n5");


The node should now have an id.  Im using to firebug to check this.  seems to work.

See JS Fiddle for Ful Example >> http://jsfiddle.net/3j9kL/5/

0
Alex Gyoshev
Telerik team
answered on 03 Apr 2012, 02:08 PM
See also this post, for another work-around for the problem.

Greetings,
Alex Gyoshev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Alexandre Lepage
Top achievements
Rank 1
answered on 09 Oct 2013, 06:43 PM
Maybe library has changed, but now it's pretty simple.

var treeView = $("#treeView").data("kendoTreeView");
var node = treeView.append({ text: "Item 3" }, $("#n2"));
node.attr("id", "n5");
0
Steve C
Top achievements
Rank 1
answered on 06 Jan 2015, 04:02 PM
For those people like me who come across this post years later the functionality Thai mentions is now supported in the Q3 2014 release (maybe before also)
The following now works
treeview.append({ text: "sometext", id: someid }, selectedNode);

NOTE: If you have changed the text field using DataTextField or the 'id' name then you need to use your changed names rather than 'text' and 'id'.  If your unsure check the names in use with:     var dataItem = treeview.dataItem(selectedNode);
Tags
TreeView
Asked by
Thai
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
FieldTRAKS
Top achievements
Rank 1
Piotr Jarocki
Top achievements
Rank 1
Alexander Valchev
Telerik team
Aron
Top achievements
Rank 1
Alex Gyoshev
Telerik team
Alexandre Lepage
Top achievements
Rank 1
Steve C
Top achievements
Rank 1
Share this question
or