Delete only the selected node

2 Answers 65 Views
TreeList
Dan
Top achievements
Rank 1
Iron
Iron
Veteran
Dan asked on 27 Jan 2022, 08:24 AM

I have a hierarchy with multiple roots and I have a requirement that only the root should have the delete button enabled and when pressing delete to remove the whole hierarchy.

As it works now it seems that when I press the delete button for each node the ajax delete method is called.

Is there a way to call the delete method only for the selected node?

Is there an example where I can remove the nodes programmatically without calling the ajax delete method.

2 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 01 Feb 2022, 07:28 AM

Hello Dan,

You can add the k-state-disabled class for all delete buttons except for the root node, for example:

columns: [
                       { command: [{ name: "createchild", text: "Add child" }, "edit",  {name: "destroy", className: "k-state-disabled"}], width: 300 }
                        ],
                      dataBound: function(e) {
                        $("tbody>tr:eq(0)").find("button.k-state-disabled").removeClass("k-state-disabled");
                      }

When the delete is hit for the root node it sends a request to delete not only this node but all its children, meaning it will delete the whole hierarchy.

Let me know if you have any questions.

Regards,
Nikolay
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Dan
Top achievements
Rank 1
Iron
Iron
Veteran
commented on 01 Feb 2022, 07:45 AM

Hi Nikolay,

I think you did not understood my problem. I need to send to the server to delete only the root. And the server will determine how to delete the child nodes. Right now how it works is like so: for every node a delete call is made and if for instance one of the delete calls fails all the other delete previously done with success remain as deleted.

I need to delete the whole structure in a single call so if I can not delete the whole structure than none of the nodes should be deleted.

How can I achieve this.

0
Nikolay
Telerik team
answered on 04 Feb 2022, 07:04 AM

Hi Dan,

thank you for clarifying the scenario.

This is indeed valid and has been logged for adding in the TreeList feature:

I have lifted up ts priority.

Nevertheless, one solution possible solution to achieve this requirement is to get the children of the parent element before we delete it, change their parentId and ReportsTo properties to another parent element(let's say the main one) and then remove the current element. This would send a single request to the server and the child nodes won't be removed.

Here is a Dojo demo I prepared demonstrating this:

Hope this helps.

Regards,

Nikolay

 

 

Dan
Top achievements
Rank 1
Iron
Iron
Veteran
commented on 04 Feb 2022, 07:12 AM | edited

Hi Nikolay,

Thank you for the link to the existing issue and for the dojo as a starting point.

I would like to partially accept this answer but the demo is not complete cause it does not handle the case when the removal of the node fails and the nodes have to readd to the node, and the case when the node is successful on the server and the child nodes still remain on datasource (not sure yet if there might be an issue this)

Nikolay
Telerik team
commented on 09 Feb 2022, 06:52 AM

Hi Dan,

You can use the error data source event to handle the case when the removal of the node fails by adding back the node.

For the second case, you can perform a read() request to get the new data and refresh the TreeList with it.

Dan
Top achievements
Rank 1
Iron
Iron
Veteran
commented on 09 Feb 2022, 06:59 AM

Hi Nikolay,

The whole point of the question was to avoid using the read() request on the TreeList after the tree was loaded, otherwise I would have reloaded the tree after every change on the tree (delete with success or delete with error)

Nikolay
Telerik team
commented on 11 Feb 2022, 12:01 PM

Hi Dan,

This is how the TreeList works. For every deleted node a request is performed to the server. (For batch set up treeList it is one request for all changes in the widget)

In case a node is deleted on the server we need to fetch this update by performing a read() request.

Finally, when a node fails to be deleted o nthe server, indeed, we need to add it back. This feature, however, is still not implemented and has been logged.

 

 

Tags
TreeList
Asked by
Dan
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Nikolay
Telerik team
Share this question
or