I have a treelist bound to server data that i need to open to the same branch after refresh.
The refresh is done with a separate button that reloads the data from the database, and returns the path to the last selected tree node as list of the node's id's. Problem is that the tree is set to load data only when needed, so the loop this function runs attempting to expand the tree works too fast, and tries to expand nodes that the tree hasn't loaded yet.
Function code is following
function
onRefreshClick() {
var
treelist = $(
"#treelist"
).data(
"kendoTreeList"
);
treelist.dataSource.read();
$.ajax({
type:
"POST"
,
url:
'@Url.Action("GetTreePath", "Tree")'
,
data: { itemID: currentID },
success:
function
(data) {
var
dataArray = $.map(data,
function
(el) {
return
el });
for
(i = 0; i < dataArray.length; i++) {
var
rows = treelist.content.find(
"tr:visible"
);
var
found =
false
;
for
(
var
iRow = 0; iRow < rows.length; iRow++) {
if
(found) {
break
;
}
row = rows[iRow];
var
cellI = 0;
if
(row != undefined) {
while
(row.cells[cellI] != undefined) {
if
(row.cells[cellI].innerText == dataArray[i]) {
treelist.expand(row)
;
alert(
"Opening tree"
);
found =
true
;
break
;
}
cellI++;
}
}
}
}
}
});
}
The above works if the user dismisses the "opening tree" alert after the tree has loaded and opened the tree branch, but is it possible to make the function wait for the data to be loaded without manual control, or is there some other way to perform this function?