TreeGrid - add new node

I need to have my TreeGrid editable: Add and remove nodes.

Here is code to add a new node right after the selected one:

oNode = TreeGrid.getSelectedRecord();
TreeGrid.data.add(oNode, TreeGrif.data.getParentPath(oNode), TreeGrid.getRecordIndex(oNode));

Here is what is happening.

  1. The new node is added and it is a complete clone of selected node. +
  2. The new node is placed at the end of a list because TreeGrid.getRecordIndex(oNode) is not relative to a clonning node’s parent. I think. - How to get node’s position relative to its parent?
  3. Regardless where new node is the navigation thru the tree after new node is added highlights both original and new node together. - What am I doing wrong?

Please help.

Thanks

Any word on that?

Is this a databound treeGrid, or is the data explicitly specified as a (client-side) Tree object?
If it’s a databound tree grid, you’ll want to add the record directly to the DataSource rather than trying to manipulate the treegrid’s data object directly in this way.

If you need more help - post a full working example for us to try out

Thanks
Isomorphic Software

This is a databound tree grid.

sc.DynamicForm.create({
	ID: "frmSafetyRule",
    dataSource: "SafetyRules",
    width:300,
    autoDraw:false,
    numCols: 2,
    colWidths: ["47%", "*"],
    fields:[
	    {name: "relation", title: "Rule #", type: "text", width: 100, canEdit: false},
	    {name: "name", title: "Rule Title", type: "text", width: 500},
	    {name: "description", title: "Rule Desription", type: "text", width: 500, height: 400, length: 500}
	]
});	  

isc.TreeGrid.create({
		ID: "SafetyRulesTree",
		autoDraw:false,
		dataSource: "SafetyRules",
		autoFetchData: false,
		leaveScrollbarGap: false,
		alternateRecordStyles: true,
		nodeClick: "frmSafetyRule.editRecord(node);",
		nodeContextClick: function (SafetyRulesTree, node)
			{return customNodeMenu.showContextMenu();
		},
		loadDataOnDemand:false
});
isc.DataSource.create({
		ID:"SafetyRules",
		dataURL:"../../safety/forms/safety.asp?requesttype=send&datarequest=xml&methodexecute=mBuildMenuTree",
		recordXPath:"//menu",
		fields:[
		        {type:"integer", required:true, title:"Menu ID", primaryKey:true, name:"menuid"},
		        {type:"integer", required:true, title:"Menu system", rootValue:"1", foreignKey:"menu.menuid",name:"parentid"},
   		        {type:"text", title:"Name", length:128, name:"name"}
		    ]
});

I wish I could see how DS.addData would work.
But as soon as I issue DS.addData(newrecord) it will take long time before IE asks for just first time “script takes long time to run”…
As I had reported to you a while ago providing debug information from Developer Console the problem is that the whole Tree data is being submited back to Server.

Hi Mark,
I think we need to back up a little to make sense of this.
What are you actually trying to achieve?

If you simply want to add some arbitrary child node to the selected node in a databound treegrid, you would need to use dataSource.addData() to add the node to the datasource. Like this:

// get the desired parentNode's primary key
var parentNode = SafetyRulesTree.getSelectedRecord();
// create the new node to add
var newNode = {
    // new primary key
    menuid:1000,
    // link to parent
    parentid:parentNode.menuid,
    name:"New Node"
}

// add the node
SafetyRules.addData(newNode);

If this doesn’t solve your issue, can you give us a fuller description of what exactly you’re trying to achieve.

Thanks

Ok, I see what I need to do to add a new node.
A few questions here. What if I want to clone and add the existing node? What if that node is actually a parent node - node that has children?
Another thing is about saving tree data. I have provided info to you via email that when I save changes it takes a very long time. What was found was that the whole tree data was getting submitted to the server. Even with that fact it should not take that long because when tree is pulled from the server it does not take long time at all. For tree data change I am using a dynamic form. Something similar to your documentaion samples.