Dynamically adding branches to treeview.net javascript tree control

Y

ylarom

Pro bono publico...

After rendering the treeview.net tree, the code doesn't offer a means
to adding folders dynamically.
I've put in a little time investigating this, and here is the result:

function dynInsFolder(parent, folder)
{
// add to parent
insFld(parent, folder);

// build leftside indicator
var leftSide = parent.leftSideCoded;
if (parent.level > 0)
leftSide += (parent.isLastNode ? "0" : "1");
if (typeof leftSide == 'undefined')
leftSide = '';

// initialize
folder.initialize(parent.level + 1, true, leftSide)

// if parent has other siblings, rememer the last one
var lastSibling = (parent.nChildren == 1 ? null :
parent.children[parent.nChildren - 2]);

if (lastSibling != null)
lastSibling.isLastNode = 0;

// render the new folder if supposed to be visible
if (parent.isRendered && parent.isOpen)
{
// if no siblings, render after the parent, otherwise render after
the last sibling
var parentNavObj = (lastSibling == null ? parent.navObj :
lastSibling.navObj);
folder.renderOb(parentNavObj)
}

// if no siblings, need to update parent's node image and tree lines
if (parent.isRendered && parent.level > 0 && lastSibling == null)
refreshNodeImage(parent);

// if there is a sibling, need to update node image - change tree
lines to connect down as well
if (lastSibling != null && lastSibling.isRendered)
refreshNodeImage(lastSibling);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top