We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Inserting child records in Treegrid

Thread ID:





146318 Jul 31,2019 07:33 AM UTC Aug 2,2019 09:55 AM UTC Angular - EJ 2 3
Tags: TreeGrid
Damir Gabeljic
Asked On July 31, 2019 07:33 AM UTC


what's the proper way to add child row to Treegrid?

First I tried do push record to dataSource array, but nothing happens.
Then I tried to use treegrid addRecord method, but the results aren't as expected.

I have modified one of your samples for my scenario: https://stackblitz.com/edit/angular-vrtsl2

Another question is how to make new row visible (scroll to it)?

Thanks in advance

Padmavathy Kamalanathan [Syncfusion]
Replied On August 1, 2019 07:32 AM UTC

Hi Damir, 
Thanks for contacting Syncfusion Forums. 
QUERY1: what's the proper way to add child row to Treegrid? 
From your query we understand that you are unable to add child row to the TreeGrid. In the sample you have shared, you have set button to the parent rows, and on button click you need to add child row to that parent row.  
In order to achieve your requirement, please follow the below steps, 
  1. For Adding/Editing you need to set isPrimaryKey to true for particular column.
  2. Since you need to add record as child, set newRowPosition property of editSettings as “Child”.
  3. In Button Click event, you need to call the addRecord method with the data and index of parent record as parameters.
Please refer the below code snippet, 
<ejs-treegrid #treegrid [dataSource]='data' height='400' childMapping='subtasks' [treeColumnIndex]='0'[editSettings]='editSettings'  (actionComplete)='actionComplete($event)'> 
      <e-column field='taskID' headerText='Task ID' isPrimaryKey='true' width='90' textAlign='Right' ></e-column> 
      <e-column width="150"> 
        <ng-template #template let-data> 
          <button (click)="insert(data)" *ngIf="data.level == 0">INSERT CHILD</button> 
export class AppComponent implements OnInit{ 
  public data: Object[] = []; 
  public editSettings: Object; 
  public treegrid: TreeGrid; 
  ngOnInit(): void { 
    this.data = sampleData; 
    this.editSettings ={ allowEditing: true, allowAdding: true, allowDeleting: true, mode:"Row", newRowPosition: 'Child'};  
insert(data: any) { 
  var value =  { taskID: 33333, taskName: 'Plan timeline'}; 
 this.treegrid.addRecord(value, data.index); 
// call addRecord method with data and index of parent record as parameters 
Please refer the below help documentations, 
QUERY2: how to make new row visible (scroll to it)? 
In order to scroll to the newly added row, call the selectRow method with the index of the added row as parameter in the actionComplete event with args.requestType as “save”. 
Please refer the below code snippet, 
actionComplete(args): void { 
  if (args.requestType == "save") { 
    var index = args.index; 
    this.treegrid.selectRow(index); // select the newly added row to scroll to it  
Please refer the below sample, 
If you have further queries, please get back to us. 
Padmavathy Kamalanathan 

Damir Gabeljic
Replied On August 1, 2019 07:49 AM UTC

Thanks, works perfectly.

Padmavathy Kamalanathan [Syncfusion]
Replied On August 2, 2019 09:55 AM UTC

Hi Damir, 

We are happy to hear that your issue has been resolved. 

Feel free to get back to us, if you need further assistance. 

Padmavathy Kamalanathan 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon