Add Sub-tree (data in tree hierarchy) in tree Grid in Specific Parent

 I need to add subTree data to specific Parent in TreeGrid without adding it  -row by row- by using "addRow"  Method.
--- "block of data" in one step ---
Is there a way to send subTree Object to be attached once to parent ?

3 Replies

JS Jonesherine Stephen Syncfusion Team May 8, 2018 12:56 PM UTC

Hi Weam, 
Thanks for contacting Syncfusion support. 
In TreeGrid, at present we can add a row using addRow public method. We can add multiple records in TreeGrid by adding new records in existing data source and refreshing the data source of TreeGrid by using setModel method. Please find the code example below. 
function addData() { 
    var treeObj = $("#TreeGridContainer").ejTreeGrid("instance"); 
    var data = $.extend([], treeObj.model.dataSource), 
        parentId = treeObj.model.selectedItem ? treeObj.model.selectedItem.TaskID : 1, 
        taskId = treeObj.model.flatRecords.length, 
        subTreedata = [{ "TaskID": ++taskId, "TaskName": "Child Task 1", "StartDate": new Date("02/23/2017"), "EndDate": new Date("02/27/2017"), "Progress": "40", "parentID": parentId }, 
                             //.. 
        ], 
        dataSource = $.merge(data, subTreedata); 
    treeObj.setModel({ "dataSource": dataSource }); 
} 
We have also prepared the sample for this, please find the sample from below location. 
 
Regards, 
Jone sherine P S 



AA Awais Ashraf December 12, 2019 12:20 PM UTC

The setModel function doesn't exist in the new grid. Its not there in the documentation. How can we add new records to the updated treegrid?


PP Pooja Priya Krishna Moorthy Syncfusion Team December 13, 2019 06:32 AM UTC

Hi Awais, 
 
Can you please share us the detail, whether you are using EJ1-Treegrid or EJ2-Treegrid? We have setModel method only in EJ1-TreeGrid(jQuery based) and not in EJ2-TreeGrid(Javascript based). 
Please share this info, it will be very helpful for us to provide you a proper solution. 
 
Thanks, 
Pooja K 
 


Loader.
Up arrow icon