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

.append multiple items at once

4 Answers 172 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 16 Jan 2013, 08:53 PM
From what I can tell via the source there isn't a way to do this. append() calls dataSource.add() which also appears to only accept one model at a time. I'm trying to avoid multiple repaints. The only viable solution I see is to use a combination of treeView.setDataSource and treeView.select to re-render the entire tree once. This is opposed to calling .append() n number of times.

Am I missing another solution?

4 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 17 Jan 2013, 10:16 AM
Hello Ryan,

Indeed, at this time calls to TreeView append() with an array of items will call the DataSource add() method multiple times. We have logged this for fixing. Until this is addressed, you can use the array push and splice methods of the child DataSource data to append or insert items:

var treeview = $("[data-role=treeview]").data("kendoTreeView");
var node = treeview.findByText("images")
var children = treeview.dataItem(node).children.data();
children.push({ text: "foo" }, { text: "bar" });

You can try this out on the online demos, through a web developer console.

Regards,
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
Ryan
Top achievements
Rank 1
answered on 17 Jan 2013, 01:51 PM
Thank you Alex. Is there a way to push an item with a child attached? I don't have the children yet but am running my own ajax during the expand event. I'd like a dummy child to be pushed along with the items so they will render with the caret and I can use the expand event.
0
Ryan
Top achievements
Rank 1
answered on 17 Jan 2013, 02:08 PM
Seems to work fine with an items: [] property.
0
Alex Gyoshev
Telerik team
answered on 18 Jan 2013, 07:06 AM
Hello Ryan,

Indeed, it should work with the items property, or by setting hasChildren: true. Use the one that works for your case.

All the best,
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!
Tags
TreeView
Asked by
Ryan
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Ryan
Top achievements
Rank 1
Share this question
or