I have a standard edit page in my application that has in it an igTree.
This tree has a total of 1500 nodes and on load I need to change the checkstate to checked all of the checkboxes that meet a certain criteria that is returned from a dataset loaded via an ajax call.
What I'm currently doing is finding the nodes that need to be checked against the entire collection. This works fine and work as expected.
Where I'm having a problem is the actual performance of checking the checkboxes. I'm hoping there's a better way of doing this. Currently I'm iterating over the collection of nodes that need to be checked and telling igTree to check them.
var t1 = new Date();
var theTree = $("#tree");
for (var i = 0; i < allMatchedNodes.length; i++) {
theTree.igTree("toggleCheckstate", allMatchedNodes[i].element);
}
var t2 = new Date();
var dif = t1.getTime() - t2.getTime();
var Seconds_from_T1_to_T2 = dif / 1000;
var Seconds_Between_Dates = Math.abs(Seconds_from_T1_to_T2);
In the example above, allMatchedNodes has a total of 36 entries and they typically have a child collection which may have another child collection (3 levels).
The problem is this takes a dreadfully long time to complete under IE8, so long in fact that you get the long running script error multiple times.
In the test cases I've run so far, the above reports 65 seconds as the running time. Am I doing something wrong attempting to check the checkboxes in this fashion?Can I remove the child collection from each top level node?
Will igTree be intelligent enough to check all children for me or does it need the children collection to check them? I'm guessing the internal toggleCheckState call is recursively iterating through the children which in this case there are up to three more levels to go through.
Your help is appreciated.
Thank You
Hello CharGuilette,
Thank you for your reply.
Please feel free to contact us with any updates and additional questions.
Thanks for the quick followup.
I'll give this a go later today and post back the results.
Hi again,
I guess I see exactly what the issue is. Let's try and trick the JS engine of the IE8. Do the following after the tree is rendered:
var tree = $('#treeID').data('igTree'); var checkbox = $('#treeID').find('span[data-role=checkbox]'); var checkIcon = checkbox.children('span'); checkbox.attr('data-chk', 'on'); checkIcon.removeClass(tree.css.checkboxOff).addClass(tree.css.checkboxOn);
This would change all the checkboxes to being checked. Then call toggleCheckstate only on the nodes you need unchecked.
Let me know if this improves performance or we still at hitting the wall?
The issue is not with manually checking the checkboxes on the UI. That works fine.
It is with programatically setting the checked boxes on page load.
We load the tree into our page and a set of checkboxes need to be checked based on user selection.
This is an Edit page where on the create page prior the user selected a set of checkboxes in the tree so on Edit we are loading their selections.
US => Region => District => Store
A common example for us is we have the entire US node selected except a half dozen checkboxes all the way down at the storelevel of the tree. This means that the top node should be a partial check, the second level (of which there are usually 20 entries) should all be full checked except one, the third level should all be full checked except one, and the store level is all checked except the six stores in quesiton.
Your example would have to be extended to next get a set of the nodes in your tree and check them upon page load. Mind you this also involves two server calls as well, one to get the tree, and another to get the selected items.
Also, the target browser in this case is IE8. Not my choice unfortunately. The logic I currently have works well enough in Chrome and Firefox. There's still a lag of perhaps 1-2 seconds but it's nothing major. IE 8 however throws the dreaded long running script error twice before completing.
I'm trying to move as much processing as possible to the server as I know IE8 javascript engine is, to be nice, horrific.
I hope this gives you a better idea of what we're attempting to do.
Thanks
I tried to reproduce the performance issue. I made the following sample:
<div id="tree3"></div>
var ul = $('<ul></ul>').appendTo($('#tree3')), markup = ''; for (var i = 0; i < 3; i++) { markup += '<li>Node Text<ul>'; for (var j = 0; j < 50; j++) { markup += '<li>Node Text<ul>'; for (var k = 0; k < 51; k++) { markup += '<li>Node Text</li>'; } markup += '</ul></li>'; } markup += '</ul></li>'; } ul.html(markup); $('#tree3').igTree({ checkboxMode: 'triState' });
The checkboxes did not show any performance slowdown for me. I check them and they instantly cascade down. I tested this against IE9/Firefox13/Chrome 19/Maxthon 3.4.1.
Maybe you're using a different browser, if that's the case let me know which one. This sample actually has 7650 nodes.
Thank you for your patience!