collapse - prevent expanding parent node when its datasource is updated due to addition of a child item inside kendo treeview -
i have kendotreeview 3 root parent nodes.example shown below.
when drop child3 new subgroup, node "new subgroup" gets expanded default even if collapsed before. prevent possibility. if new subgroup expanded before, keep is. problem expand gets called before databound event , hence stuck here.
please help.
parent1:
--new subgroup --child2 --child3 --child4
parent2:
--child4 --child5
code snippet: databound: function (e) { console.log("databound", e.node); var nodedataitem = $("#dimmeastree").data("kendotreeview").dataitem($(e.node)); if (nodedataitem.fieldkey === "subgroup" && ($(e.node).attr("aria-expanded")) === "true") { $("#dimmeastree").data("kendotreeview").collapse($(e.node)); } }
i subscribing own custom expand function (i.e. subgroup_expand()) after initialize treeview. demonstrated below:
<div id="treeview"></div> <script> function subgroup_expand(e) { if (typeof event === 'undefined') { //if browser firefox, subgroup expand , not close automatically. // because firefox not support "event" attribute gloabally in ie or in google chrome. } else if (!!e.node && typeof(event) !== 'undefined' && event.type !== "click" && event.type !== "dblclick") { var nodedataitem = $("#treeview").data("kendotreeview").dataitem($(e.node)); if (nodedataitem.fieldkey === "subgroup") { // e.preventdefault(); settimeout(function () { //collapse subgroup if not expanded click or dblclick. $("#treeview").data("kendotreeview").collapse($(e.node)); }, 50); } } } $("#treeview").kendotreeview({ datasource: modeldata }); var treeview = $("#treeview").data("kendotreeview"); treeview.bind("expand", subgroup_expand); </script>
Comments
Post a Comment