Need to Limit Treeview only till 2 Level

I am using the Syncfusion Treeview Control and I want to restrict the treeview only till 2 levels or may be 3 levels in future if required. Is there any configuration that cn be used and restrict the user to create only 2 level treeview and not more than that. Even drag and drog should not allow to drop to create the 3 level item.

1 Reply 1 reply marked as answer

SS Sharon Sanchez Selvaraj Syncfusion Team May 20, 2021 04:10 PM UTC

Hi Rajender, 
 
Greetings from Syncfusion Support. 
 
We checked your requirement “I want to restrict the treeview only till 2 levels or may be 3 levels in future if required. Is there any configuration that cn be used and restrict the user to create only 2 level treeview”. We would like to mention that the initial rendering of TreeView levels depends on the structure of your data source. When rendering the TreeView, you can choose the data to be only at certain levels, i.e., the child nodes of the required TreeView must be provided according to your requirement. And we have created a sample over here to restrict the drag and drop action in level 2 through args.cancel. You can customize this levels based on your requirement. 
 
Refer to the code snippet. 
 
  function onNodeDragStop(args) { 
        if (args.droppedNodeData != null) { 
            var droppeddata = document.querySelector( 
                '[data-uid="' + args.droppedNodeData.id + '"]' 
            ).classList[1]; 
            if (droppeddata == 'e-level-2') { 
                args.cancel = true; 
            } 
        } 
    } 
 
Refer to the sample. 
 
 
 
Please get back to us if you need further assistance. 
 
Regards, 
 
Sharon Sanchez S. 


Marked as answer
Loader.
Up arrow icon