Hi
I'm using the igTree component with knockoutJS extension to display a nested list of items, and I would like to sort/reorder the nodes. Currently, the tree does not reflect the changes to my data source. The data source basically consists of nested observableArrays, all sorted on a numeric property 'sortOrder'. The reorder algorithm just swaps 'sortOrder' for two elements. I tried to manually call 'applyChangesToNode' which seemed to work, although eventually threw a 'maximum call stack exceeded' error. Any pointers?
Thanks!
Hello,
In case you find it appropriate, you could force the tree to update and reflect the sorted observable array like applying bindings and passing the updated viewmodel.
Hi,
I thought about rebuilding the tree like you suggest, and instead of wrapping it in a 'ko if' I was able to use the 'dataBind' method to re-render the tree.
My solution is something like the following:
function reorderItems(a, b) {
var newDataPath = b.dataPath;
swap(a, b); // swap items in array
// dataBind resets selection$(treeId).igTree('dataBind');// use a's new data-path to re-select node after data bindingvar node = $(treeId).igTree('nodeByPath', newDataPath);
$(treeId).igTree('expandToNode', node, true);
}
Thanks a lot!