Hi there,
I am working with the new ClientChanges property for the RadTreeView, included in last week's Q2 release of the Telerik controls. I am trying to edit, remove and drag and drop nodes on the client side and then process the changes all at once on the server, to minimise the number of post-backs. First, I am calling the trackChanges() method of the client-side tree object in a Javascript function that handles the OnClientLoad event. Then I have the following function to handle the OnClientNodeDropping event on the client:
function ClientNodeDropping(sender, args)
{
// get source and destination nodes
var sourceNode = args.get_sourceNode(), destNode = args.get_destNode();
if (destNode)
{
destNode.get_nodes().add(sourceNode);
}
}
Finally, I have a Submit button, with a Click event handler that calls the commitChanges() method of the client-side tree object and then generates a post-back.
On the server, I iterate through the list of ClientChanges to build up a SQL string like this:
foreach (ClientOperation<RadTreeNode> operation in tree.ClientChanges)
{
RadTreeNode node = operation.Item;
switch (operation.Type)
{
case ClientOperationType.Insert:
SQLString.AppendLine("INSERT INTO ... VALUES ...");
break;
case ClientOperationType.Remove:
SQLString.AppendLine("DELETE FROM ... WHERE ID = ...");
case ClientOperationType.Update:
UpdateClientOperation<RadTreeNode> update = operation as UpdateClientOperation<RadTreeNode>;
SQLString.AppendLine("UPDATE ... SET ParentId = ... WHERE ID = ...");
}
}
// now commit the changes to the database
UpdateDatabase(SQLString.ToString());
The UpdateDatabase function executes the commands contained in the string.
This is working well apart from one crucial issue; whenever I drag and drop a node, the ClientChanges collection of operations includes one Remove operation for deleting the node from its original (source) parent, one Insert operation for inserting it under its new (destination) parent and then one Insert operation for *each and every child* that was also moved in the drag operation! These children are already present in the database, so the code crashes at this point.
Am I doing something wrong, or is this a known issue? If so, is there a work-around?
All help gratefully received,
Ed Graham
I am working with the new ClientChanges property for the RadTreeView, included in last week's Q2 release of the Telerik controls. I am trying to edit, remove and drag and drop nodes on the client side and then process the changes all at once on the server, to minimise the number of post-backs. First, I am calling the trackChanges() method of the client-side tree object in a Javascript function that handles the OnClientLoad event. Then I have the following function to handle the OnClientNodeDropping event on the client:
function ClientNodeDropping(sender, args)
{
// get source and destination nodes
var sourceNode = args.get_sourceNode(), destNode = args.get_destNode();
if (destNode)
{
destNode.get_nodes().add(sourceNode);
}
}
Finally, I have a Submit button, with a Click event handler that calls the commitChanges() method of the client-side tree object and then generates a post-back.
On the server, I iterate through the list of ClientChanges to build up a SQL string like this:
foreach (ClientOperation<RadTreeNode> operation in tree.ClientChanges)
{
RadTreeNode node = operation.Item;
switch (operation.Type)
{
case ClientOperationType.Insert:
SQLString.AppendLine("INSERT INTO ... VALUES ...");
break;
case ClientOperationType.Remove:
SQLString.AppendLine("DELETE FROM ... WHERE ID = ...");
case ClientOperationType.Update:
UpdateClientOperation<RadTreeNode> update = operation as UpdateClientOperation<RadTreeNode>;
SQLString.AppendLine("UPDATE ... SET ParentId = ... WHERE ID = ...");
}
}
// now commit the changes to the database
UpdateDatabase(SQLString.ToString());
The UpdateDatabase function executes the commands contained in the string.
This is working well apart from one crucial issue; whenever I drag and drop a node, the ClientChanges collection of operations includes one Remove operation for deleting the node from its original (source) parent, one Insert operation for inserting it under its new (destination) parent and then one Insert operation for *each and every child* that was also moved in the drag operation! These children are already present in the database, so the code crashes at this point.
Am I doing something wrong, or is this a known issue? If so, is there a work-around?
All help gratefully received,
Ed Graham