I am using the JQuery plugin jsTree, http://www.jstree.com/ I am able to expand the whole tree with the following method:
$(\"#tree\").jstree(\"open_all\");
Try this code to open node till nth Level
$("#myTree").jstree({options}).bind('loaded.jstree', function (e, data) {
/**
* Open nodes on load (until x'th level)
*/
var depth = 3;
data.inst.get_container().find('li').each(function (i) {
if (data.inst.get_path($(this)).length <= depth) {
data.inst.open_node($(this));
}
});
});