Adding, Editing Rows and Validation in the treegrid

I'm having a lot of trouble getting adding and editing rows working in the treegrid and I was hoping you could help. 

What I am trying to accomplish

I have a grid and I want to let the user choose to add child or parent rows by clicking buttons. When the row is added, they would be scrolled to that row and put into edit mode on the category textbox with the cell showing red as failing validation. I also need to add a unique ID as I add the reocrd.

1) When I add a record my buttons lose their css style as the grid is updating then it is restored when the grid is updated. Is there a way to avoid this?

When I call treegrid.AddRecord() this does not happen, but when I call with params it does 

 addRecord(data?: Objectindex?: numberposition?: RowPosition)

I also see that a refresh instead of an add event is fired when you call add record with params. 

You can see this behavior by clicking these buttons

Add Child Record no Parameters - no flicker

Add Child Record with Parameters - flicker

I attached a screenshot with an example of this.

2) How can I programatically select a row to edit?

Unlike calling add record without parameters, which kicks the user into edit mode, calling it with parameters does not. 

How can I find the row that was added and set it to edit mode? I see celledit, but I can't seem to find something like that for row edit.

3) How can I trigger validation on the textbox

When I click add child record with parameters, then double click to edit, the textbox is blank, but it is a required field. I would expect the textbox to highlight red to let the user know that the field is required and potentially even a pop up error message if they are focused in the cell, but it does not happen in this case.

4) How can I trigger validation on the entire treegrid

I would like to trigger the validation failing cells to red for the entire treegrid programatically... possibly by a save all button. How can I do this without using a toolbar button.

5) Is it possible to add the child to the top spot instead of the last spot?


I've attached a sample program to help illustrate the issues Im having. I couldn't include node_modules due to the upload size limitation.




Attachment: demoapp_21bbdf1.zip

17 Replies 1 reply marked as answer

PS Pon Selva Jeganathan Syncfusion Team September 28, 2021 12:02 PM UTC

Hi Zachary 
 
Thanks for contacting syncfusion forum. 
 

Query1: When I add a record my buttons lose their css style as the grid is updating then it is restored when the grid is updated. Is there a way to avoid this?

By default, addRecord method with no parameter it will shows the empty row in editing state. If you don’t want to row in editing state, then you need to pass the parameter.

Please refer to the below API documentation,

https://ej2.syncfusion.com/documentation/api/treegrid/#addrecord

2) How can I programatically select a row to edit?

I see celledit, but I can't seem to find something like that for row edit.

 
We achieved your query by using the event and selectRow, startEdit method of the treegrid. 
 
Please refer to the below code snippet, 
 
 
 App.component.html: 
 
<button ejs-button class="DefaultButton" (click)="oneditRecord($event)"> 
    Edit 
  </button> 
 
<ejs-treegrid #treegrid childMapping="children" [dataSource]="data" [treeColumnIndex]='0' 
 
> 
   
</ejs-treegrid> 
 
App.component.ts: 
…. 
 
public oneditRecord (args){ 
     
 if(args.requestType=="save" && args.action =="add"){ 
     
      this.treegrid.selectRow(index);  // select the newly added row to scroll to it 
             
this.treegrid.startEdit();// move to the edit state 
     
  } 
 
Note: Using startEdit method the selected row is moved to edited state 
 
Please refer to the below API documentation, 
 
 

3) How can I trigger validation on the textbox

We checked this query, but we are unable to reproduce the issue at our end. 

Please refer to the below screenshot,

Please refer to the below video demo,

https://www.syncfusion.com/downloads/support/forum/169153/ze/validate-1497650720

4) How can I trigger validation on the entire treegrid

To achieve your requirement by using toolbar click event.   

In toolbarClick event we have called the Tree Grid endEdit() method. If tree grid is in editable state, you can save a record by invoking endEdit. Before saving a record its validate the edited or added rowData and its display the error message when it does not meet the required condition in that validation function. Please refer the below code example 
 

<ejs-treegrid 
    #treegrid 
    [dataSource]="data" 
    height="400" 
    [allowReordering]="true" 
    childMapping="subtasks" 
    [treeColumnIndex]="1" 
    [editSettings]="editSettings" 
    [toolbar]="toolbar" 
    (toolbarClick)="toolabarclickHandler($event)" 
 
App.component.ts 
 
ngOnInit(): void { 
     
    this.toolbar = [ 
      'Add', 
      'Delete', 
      'Update', 
      'Cancel', 
      text: 'Custom SaveButton'tooltipText: 'Save'id: 'savebutton' }, 
    ]; 
 
toolabarclickHandler(args) { 
    if (args.item.id === 'savebutton') { 
      this.treegrid.endEdit(); //you can save a record by invoking endEdit 
    } 
  } 
 
 
      
 

Please refer to the below API documentation,

https://ej2.syncfusion.com/documentation/api/treegrid/#endedit

https://ej2.syncfusion.com/documentation/api/treegrid/#toolbarclick

5. Is it possible to add the child to the top spot instead of the last spot?

 
Based on your query, we suggest you use the newRowPosition as ‘above’ and pass the index as first child index.  Please refer to the below code example, 
 
 <button ejs-button class="DefaultButton" (click)="onAddRecord($event)"> 
    Add Child 
  </button> 
 
…. 
 
 onAddRecord(args) { 
    var parentdata = { 
      taskID: String(Math.floor(Math.random() * (100000 + 1 - 50000) + 50000)), 
      taskName: 'test', 
    }; 
 
    this.treegrid.addRecord(parentdata8'Above'); 
  } 
 
 
 
 
 
 

Please refer to the below sample,

 
Kindly get back to us for further assistance. 

Regards, 
Pon selva 



ZA Zachary September 28, 2021 05:56 PM UTC

1) I've attached a picture of the button behavior (where they lose their formatting) for this one. Is there a way to avoid it? I would also think that it is a bug that the grid fire a refresh event on action complete instead of an add when you call the addrecord with parameters.


2) Start edit works. Thanks!


3) I've attached no_validation_5a9c4feb.zip to illustrate what is happening. I add a new row. Then I click in the row and even though the column is required the validation message does not come up when I double click to edit or click off of the row.





Attachment: no_validation_5a9c4feb.zip


ZA Zachary September 28, 2021 05:57 PM UTC

Adding the screenshot for #1


Attachment: buttons_missing_changing_appearance_screen_hot_e7832969.zip


ZA Zachary September 28, 2021 06:15 PM UTC

Topic 6: #4 Did not work, but I believe that I found a bug in the controls. Could you confirm this is a bug and let me know if there is any workarounds for what I am doing?

I attached a video of this.

I click Add Child Record with no Parameters and the row is added.

I double click on the row. I fill in the required field. When i click away from the row or hit enter  it does not exit edit mode, like it normally would. TreeGrid.EndEdit did not work to exit out as well.




Attachment: row_will_not_exit_edit_mode_39c067a.zip


ZA Zachary September 28, 2021 06:20 PM UTC

Topic #5: I tried this with the code below and it adds the row in the right place, but the row is a parent row instead of a child row. How can I make it a child row instead?

  public onAddAtTopChild(argsObject)
  {
    let newRecordtreerow = new treerow();
    newRecord.children = [];
    newRecord.isParent = true;
    newRecord.id = uuidv4();
    this.treegrid.addRecord(newRecord1"Above");    
  }

Topic #7:​ When i click add row with parameters it does not start in edit mode, unlike add record without parameters.
What's the best way to to put the row in edit mode after the add? 


JR Jagadesh Ram Raajkumar Syncfusion Team September 29, 2021 02:52 PM UTC

Hi Zachary, 
  
Thanks for the update. 
  
We are validating your queries and we will provide further details on or before 1st October 2021. Until then we appreciate your patience. 
  
Regards,
Jagadesh Ram 



PS Pon Selva Jeganathan Syncfusion Team October 2, 2021 11:24 AM UTC

Hi Zachary 
  
Thanks for your patience. 
  

 

 

Query1: I've attached a picture of the button behavior (where they lose their formatting) for this one. Is there a way to avoid it? 

 

We are able to reproduce the issue at our end. We are working on this query with high priority to find the feasible solution of your requirement. We will update with further details on or before October 5th 2021.

 

 

2) How can I programatically select a row to edit?

I see celledit, but I can't seem to find something like that for row edit.

  
We are glad to hear your query has been solved by our solution. 
  

 

3) I add a new row. Then I click in the row and even though the column is required the validation message does not come up when I double click to edit or click off of the row.

  
Based on your code example, you are customizing the row while beginning of the editing action.(i.e action complete event with args.requestTypes as beginedit or add which is the cause of the issue. 
  
Confirm whether you need to hide the column template button while beginning of the edit. 

4) Did not work, but I believe that I found a bug in the controls. Could you confirm this is a bug and let me know if there is any workarounds for what I am doing?

Based on your code example, you are customizing the row while beginning of the editing action.(i.e action complete event with args.requestTypes as beginedit or add which is the cause of the issue. 
  

Confirm whether you need to hide the column template button while beginning of the edit.

5.  I tried this with the code below and it adds the row in the right place, but the row is a parent row instead of a child row. How can I make it a child row instead?

  
In your code snippet, you are set isParent property is set true. So added row is act as parent row. So, we suggest you set the isParent property as false. 
  
  
6. When i click add row with parameters it does not start in edit mode, unlike add record without parameters. 
What's the best way to to put the row in edit mode after the add?  

 

  
Based on your query, we suspect that you want to show the row as edit mode after the records added. 
We suggest you e achieved your query by using the event and selectRow, startEdit method of the treegrid.  
  
Please refer to the below code snippet,  
  
  
 App.component.html:  
  
<button ejs-button class="DefaultButton" (click)="oneditRecord($event)">  
    Edit  
  </button>  
  
<ejs-treegrid #treegrid childMapping="children" [dataSource]="data" [treeColumnIndex]='0'  
  
>  
    
</ejs-treegrid>  
  
App.component.ts:  
….  
  
public oneditRecord (args){  
      
 if(args.requestType=="save" && args.action =="add"){  
      
      this.treegrid.selectRow(index);  // select the newly added row to scroll to it  
              
this.treegrid.startEdit();// move to the edit state  
      
  }  
  
Note: Using startEdit method the selected row is moved to edited state  
  
Please refer to the below API documentation,  
  
  
Kindly get back to us for further assistance. 
  
Regards, 
Pon selva 
  
 



ZA Zachary October 4, 2021 08:38 PM UTC

Query 1: Thank you for the update

Query 2: Solved

Query 3: I do need this. Thank you for identifying this as the issue. As this issue was causing me the greatest amount of confusion and trouble.

Query 4:  Sounds like Query 3/4 are actually due to the same cause.

Query 5: That was correct and solved my issue. Thanks for the help here.

Query 6: Are there any tricks to identify what index the new record was added at? It's easy if it is getting added at the start of the row, but can be little bit confusing when it is added as a child at the bottom of the row.



PS Pon Selva Jeganathan Syncfusion Team October 5, 2021 12:10 PM UTC

Hi Zachary 
  
Thanks for your patience. 
  

 

 

Query1: I've attached a picture of the button behavior (where they lose their formatting) for this one. Is there a way to avoid it? 

 

On further analyzing in your sample, you are defining the class property in the button component. However, there is no class property in our button component. If you want to customize the button, we recommend that you use the cssClass property of the button. Please refer to the below code snippet, 

Your code: 
 
………………………… 
 <e-column headerText="" width="100px" [allowEditing]="false"> 
        <ng-template #template let-data> 
          <div *ngIf="data.hasChildRecords"> 
            <button  ejs-button class="DefaultButton" (click)="onAddChild($event)"> 
              Add Child 
            </button> 
          </div> 
        </ng-template> 
      </e-column> 
      <e-column headerText="" width="100px" [allowEditing]="false"> 
        <ng-template #template let-data> 
          <div> 
            <button ejs-button class="DefaultButton" (click)="onDelete($event)"> 
              Delete 
            </button> 
          </div> 
        </ng-template> 
      </e-column> 
 
………………………………. 
 
Modified code: 
 
……………………. 
 <e-column headerText="" width="100px" [allowEditing]="false"> 
        <ng-template #template let-data> 
          <div *ngIf="data.hasChildRecords"> 
            <button 
              ejs-button cssClass="e-outline" (click)="onAddChild($event)"> 
              Add Child 
            </button> 
          </div> 
        </ng-template> 
      </e-column> 
      <e-column headerText="" width="100px" [allowEditing]="false"> 
        <ng-template #template let-data> 
          <div> 
            <button ejs-button cssClass="e-outline" (click)="onDelete($event)"> 
              Delete 
            </button> 
          </div> 
        </ng-template> 
      </e-column> 
  …………………………… 
     
 
Please refer to the below sample, 
 
Please refer to the below API documentation, 
 
Please refer to the below help documentation, 
 

 

Query 2: Solved

  
We are glad to hear your query has been solved by our solution. 
  

 

Query 3: I do need this. Thank you for identifying this as the issue. As this issue was causing me the greatest amount of confusion and trouble.

Query 4:  Sounds like Query 3/4 are actually due to the same cause.

 
we have created separated incident for this query. You can track the further updates on this query in below incident 
 
Incident : 344406 
 

Query 5: That was correct and solved my issue. Thanks for the help here.

  
We are glad to hear your query has been solved by our solution.  
  

6.  Are there any tricks to identify what index the new record was added at? It's easy if it is getting added at the start of the row, but can be little bit confusing when it is added as a child at the bottom of the row. 

  
we have created separated incident for this query. You can track the further updates on this query in below incident 
 
Incident : 344404 
  
 
 Kindly get back to us for further assistance. 
 
Regards, 
Pon selva 
  





ZA Zachary October 5, 2021 02:21 PM UTC

When you hit the button to add a row without parameters I'm still seeing the buttons briefly lose format even in the stackblitz. I've attached a screenshot.


For the add records with no parameters this does not happen. I believe it's because the grid fires a refresh event instead of an add event when you add a row with parameters.


if it actually worked could you give me an example of how would I modify the  cssClass="e-outline" style?




Attachment: buttons_lose_format_507d6db9.zip


PS Pon Selva Jeganathan Syncfusion Team October 6, 2021 12:25 PM UTC

Hi Zachary 
  
Thanks for update. 
 
Query1: When you hit the button to add a row without parameters I'm still seeing the buttons briefly lose format even in the stackblitz. I've attached a screenshot. 
 
We checked attached stackblitz sample, but we are unable to reproduce the issue at our end. Please refer to the below video demo, 
 
Query: could you give me an example of how would I modify the  cssClass="e-outline" style? 
 
You can customize the appearance of the button by using the Cascading Style Sheets (CSS). Define the CSS according to your requirement, and assign the class name to the cssClass property.  
 
In the following code snippet the background color, text color, height, width, and sharp corner of the button can be customized through the e-custom class.  

……………………. 
 <e-column headerText="" width="100px" [allowEditing]="false"> 
        <ng-template #template let-data> 
          <div *ngIf="data.hasChildRecords"> 
            <button 
              ejs-button cssClass="e-custom" (click)="onAddChild($event)"> 
              Add Child 
            </button> 
          </div> 
        </ng-template> 
      </e-column> 
      <e-column headerText="" width="100px" [allowEditing]="false"> 
        <ng-template #template let-data> 
          <div> 
            <button ejs-button cssClass="e-custom" (click)="onDelete($event)"> 
              Delete 
            </button> 
          </div> 
        </ng-template> 
      </e-column> 
  …………………………… 
 
App.component.css 
 
.e-custom { 
  border-radius0; 
  height30px; 
  width80px; 
} 
 
.e-custom, 
.e-custom:hover, 
.e-custom:focus, 
.e-custom:active { 
  background-color#ff6e40; 
  color#fff; 
} 
 
 
     
 
Please refer to the below sample, 
 
Please refer to the below screenshot after adding the record, 
 
 
 
Please refer to the below help documentation, 
 
Kindly get back to us for further assistance. 
  
Regards, 
Pon selva 
  



ZA Zachary October 6, 2021 03:25 PM UTC

When i tried to access the download it said it was not associated with my account and blocked access.


I did navigate to the stackblitz you provided with the solution, and I am still seeing the issue with the buttons. I made a recording and attached it to show what I'm seeing.


1) When you add a row the buttons lose their format, then the format is restored.

2) This was no the original issue I was worried about, but I see that when the sample loaded the buttons had no format at all. I have seen this periodically in my development as well.


Attachment: buttons_lose_format_b818501e.zip


PS Pon Selva Jeganathan Syncfusion Team October 7, 2021 12:07 PM UTC

Hi Zachary 
  
Thanks for update. 
 
Query: When you add a row the buttons lose their format, then the format is restored.This was no the original issue I was worried about, but I see that when the sample loaded the buttons had no format at all. I have seen this periodically in my development as well. 
 
We checked attached stackblitz sample, but we are unable to reproduce the issue at our end. Please refer to the below video demo, 
 
Please refer to the below sample, 
 

After following the above reference, still faced issue please share us the following details.

  1. Share the product detail version.
  2. Share the screenshot of stacktrace details(face if any)
  3. If possible, reproduce the issue in the attached sample or share the issue reproducible sample.
  4. Share the video demo of the issue.
 
The provided information will be helpful to provide you response as early as possible.   
 
Regards, 
Pon selva 
  
 



ZA Zachary October 8, 2021 01:04 PM UTC

In the video you sent I see the issue happening. When you click Add record without parameters the buttons do not flicker into a state where the css is removed. When you click it with parameters the buttons the buttons flicker as they lose their css state then reset to their original state.


I'm guessing its related to the grid refresh event being called when you add with parameters as opposed to a grid add event being fired (which I also believe is a bug).


For the other issue where the grid is displayed without css styles it is intermittent. if I figure out how to reproduce it I'll write back. 



PS Pon Selva Jeganathan Syncfusion Team October 11, 2021 12:40 PM UTC

Hi Zachary 
  
Thanks for update. 
 
We checked your query by preparing sample. In some cases, we are able to reproduce the issue(“After the initial rendering, the button size was changed while performing the add action.”) at our end. On further analyzing,  The button's ‘e-btn’ class was not present in the initial rendering. While adding the record, the e-btn class was applied to the button component. So, the button size was changed, which is the cause of the issue. By default, the button component has a ‘e-btn’ class. So, we suggest you use the 'e-btn' class in button rendering code. 
 
Please refer to the below code snippet, 
 
App.component.html 
 
<div class="col-lg-8 control-section"> 
   
  <ejs-treegrid 
    #treegrid 
     
  > 
    <e-columns> 
      …. 
      <e-column headerText="" width="100px" [allowEditing]="false"> 
        <ng-template #template let-data> 
          <div *ngIf="data.hasChildRecords"> 
            <button ejs-button class="e-btn" (click)="onAddChild($event)"> 
              Add Child 
            </button> 
          </div> 
        </ng-template> 
      </e-column> 
      <e-column headerText="" width="200px" [allowEditing]="false"> 
        <ng-template #template let-data> 
          <div> 
            <button ejs-button class="e-btn" (click)="onDelete($event)"> 
              Delete 
            </button> 
          </div> 
        </ng-template> 
      </e-column> 
    </e-columns> 
  </ejs-treegrid> 
</div> 
 
 
  
Please refer to the below sample, 
 
Kindly get back to us for further assistance. 
 
Regards, 
Pon selva 



Marked as answer

ZA Zachary October 13, 2021 03:25 PM UTC

This worked! Thanks for taking the time to work throught his with me.



PS Pon Selva Jeganathan Syncfusion Team October 14, 2021 09:18 AM UTC

Hi Zachary 
 
Thanks for the update. 
 
We are glad to hear your query has been solved. 
 
Kindly get back to us for further assistance. We are happy to assist you. 
   
Regards, 
Pon selva 



Loader.
Up arrow icon