Hello,
I have a treeview which has multiple level of hierachy data, is there a way that I can expand all the nodes?
I tried to use function $("#treeview").data("kendoTreeView").expand(".k-item") , I can only expand the first level, is there a way that I can expand nodes at every level.
Thank you.
I have a treeview which has multiple level of hierachy data, is there a way that I can expand all the nodes?
I tried to use function $("#treeview").data("kendoTreeView").expand(".k-item") , I can only expand the first level, is there a way that I can expand nodes at every level.
Thank you.
9 Answers, 1 is accepted
0

Luis
Top achievements
Rank 1
answered on 21 Sep 2012, 05:36 PM
Use
<li data-expanded="true">
XX
</li>
This item will be expanded
<li data-expanded="true">
XX
</li>
This item will be expanded
0

Jianwei
Top achievements
Rank 1
answered on 21 Sep 2012, 06:48 PM
Thank you for your reply, this is not exactly what I am looking for, I am looking for some function that I can use to expand all, and collapse all.
0
Accepted
Hi Jianwei,
This event will call the expand method after each tree level load, and will stop when all levels of the tree are expanded.
e.g.:
Kind Regards,
Vladimir Iliev
the Telerik team
Basically there are expand and collapse methods, which will expand and collapse all of the tree nodes, but when you are using the hierarchical data source the expand method will expand only the first level of the tree, because its loaded on demand. In this case you can call the expand method on requestEnd event of the dataSource:
var
Categories =
new
kendo.data.HierarchicalDataSource({
type:
"odata"
,
requestEnd: requestEndHandler,
This event will call the expand method after each tree level load, and will stop when all levels of the tree are expanded.
e.g.:
<script type=
"text/javascript"
>
function
requestEndHandler()
{
setTimeout(
"expandNodes()"
);
}
function
expandNodes()
{
$(
"#treeview"
).data(
"kendoTreeView"
).expand(
".k-item"
);
}
</script>
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0

Waldemar
Top achievements
Rank 1
answered on 04 Mar 2014, 04:44 PM
The only way is to preload all the data and then set dataSource as a normal JS array (as if it was static data).
Because of this the whole tree will be generated at once and expand(".k-item") works like a charm.
Br
Waldemar
Because of this the whole tree will be generated at once and expand(".k-item") works like a charm.
Br
Waldemar
//Load tree data and then set tree.
//
//Why didn't we use kendo.data.HierarchicalDataSource? Because the levels are loaded on demand and we can only expand one level at a time with that.
DataLayer.CTree.Load( userCredentials,
function
( data: any )
{
//Set tree.
$(
"#ipt_tree"
).kendoTreeView(
{
dataSpriteCssClassField:
"sprite"
,
dataSource: data,
template:
"<span data-oid='#= item.oid#'>#= item.text#</span>"
,
change: CAdmin.Tree_Item_Selected
});
//Expand all.
$(
"#ipt_tree"
).data(
"kendoTreeView"
).expand(
".k-item"
);
},
function
( html_code: number, html_status: string )
{
//A transport operation failed -> set failed status.
CPage.Status_Add( html_code,
"Get tree request failed with: '"
+ html_status +
"'."
,
true
);
});
0

Henryk
Top achievements
Rank 1
answered on 25 Feb 2015, 01:08 PM
Create a button for it and add event oncklick like bellow (b is counter of not expand node):
$("#expandAllNodes").click(function (e) {
e.preventDefault();
expandNextLevel();
});
function expandNextLevel() {
setTimeout(function () {
var treeview = $("#treeview").data("kendoTreeView");
var b = $('.k-item .k-plus').length;
treeview.expand(".k-item");
treeview.trigger('dataBound');
if (b > 0) {
expandNextLevel();
}
}, 200);
}
$("#expandAllNodes").click(function (e) {
e.preventDefault();
expandNextLevel();
});
function expandNextLevel() {
setTimeout(function () {
var treeview = $("#treeview").data("kendoTreeView");
var b = $('.k-item .k-plus').length;
treeview.expand(".k-item");
treeview.trigger('dataBound');
if (b > 0) {
expandNextLevel();
}
}, 200);
}
0

Chris
Top achievements
Rank 1
answered on 08 May 2015, 07:56 PM
Is there some way to get this initial expand all to animate? It's kind of jumpy at page load and doesn't look professional.
0
Hello Chris,
I would suggest to check the following demo which shows how to customize the treeView animations:
Regards,
Vladimir Iliev
Telerik
I would suggest to check the following demo which shows how to customize the treeView animations:
Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0

Chris
Top achievements
Rank 1
answered on 13 May 2015, 06:29 PM
Vladimir,
I had already tried that - and it works fine to customize the animation after the full tree loads (expanding and collapsing the nodes manually), but not for this initial expansion of all nodes.
Chris
0
Hi Chris,
The current TreeView's rendering mechanism does not support animating the initial expansion and I am afraid there is no workaround that I can suggest.
Regards,
Alexander Popov
Telerik
The current TreeView's rendering mechanism does not support animating the initial expansion and I am afraid there is no workaround that I can suggest.
Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!