Add column dynamically in tree grid with defaultValue not working

I add column to columns with defaultValue option but it's not work and i try to add new property to the dataSource but it still not work.

https://stackblitz.com/edit/angular-mqa5hw-kwufzb?file=app.component.ts


7 Replies 1 reply marked as answer

QU Quang August 11, 2022 02:57 AM UTC

I need help! Someone can help me?



FS Farveen Sulthana Thameeztheen Basha Syncfusion Team August 11, 2022 05:06 PM UTC

Hi Quang,


We have checked your reported problem and if you use refreshColumns method, it will update the changes that has been made into the TreeGrid columns. In order to refresh the TreeGrid, we suggest to use Refresh method of the TreeGrid.


Refer to the code below:-

App.Component.ts:-

 

clicked(): void {

    let columnName = { field: 'newCol', width: 100, defaultValue: 'Default' };

    this.data.map((d) => Object.assign(d, { newCol: 'Default' }));

    this.treegrid.columns.splice(2, 0, columnName); //Add the columns

    this.treegrid.refreshColumns();

    this.treegrid.refresh();

  }


Modified sample link:- https://stackblitz.com/edit/angular-mqa5hw-suasbi?file=app.component.ts


Refer to the documentation link:-

https://ej2.syncfusion.com/angular/documentation/api/treegrid/#refresh


Please get back to us if you need any further assistance.


Regards,

Farveen sulthana T


Note:- If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.



QU Quang replied to Farveen Sulthana Thameeztheen Basha August 17, 2022 04:08 AM UTC

Hi Farveen Sulthana Thameeztheen Basha,

Thanks for your support. It's work ok but if i using type/edit type dropdownlist. After refresh treegrid in dropdownlist column still not display default value(i setup first item value of dropdownlist is defaultValue of column). And one more thing if i select an value in dropdownlist and save it, i edit this column again dropdownlist will reset value of this cell.



QU Quang replied to Quang August 19, 2022 01:50 AM UTC

I need help for this problem! Someone can help 



PS Pon Selva Jeganathan Syncfusion Team August 19, 2022 02:54 AM UTC

Hi Ayush,


Thanks for the update.


Query: After refresh treegrid in dropdownlist column still not display default value(i setup first item value of dropdownlist is defaultValue of column). And one more thing if i select an value in dropdownlist and save it, i edit this column again dropdownlist will reset value of this cell.


Based on your query, we understand you need to show the default value after refreshing the treegrid or after editing the cell value. By default, the defaultValue property is used only when adding a new record to the TreeGrid.


Please refer to the below API documentation,

https://ej2.syncfusion.com/documentation/api/treegrid/column/#defaultvalue


If you want to show the default value while editing or after refreshing the treegrid, we suggest you use the actionBegin event. In the actionBegin event with args.requestType as beginEdit you can change the value before editing.


Please refer to the below code example,


 <ejs-treegrid

    #treegrid

    [dataSource]="data"

    height="400"

    childMapping="subtasks"

    [treeColumnIndex]="1"

    [selectionSettings]="selectionsettings"

    (checkboxChange)="checkboxChange($event)"

    (actionBegin)="actionBegin($event)"

    [editSettings]="editSettings"

    [toolbar]="toolbar"

  >

 

 

….

 

actionBegin(args) {

    console.log(args'actionBegin event triggered');

 

    if (args.requestType == 'beginEdit') {

      args.rowData.newCol = 'Default'// here you can define the default value

    }

  }

 


Please refer to the below sample,

https://stackblitz.com/edit/angular-mqa5hw-mlqyoh?file=app.component.ts,app.component.html


Still, if you are facing the issue, kindly share the below details


  1. Detailed explanation of your issue.
  2. Share the video demo/screenshot of your issue.
  3. Share the code example(both ts and html).


Please get back to us if you need more assistance. 


Regards,
Pon selva


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.







QU Quang replied to Pon Selva Jeganathan August 22, 2022 03:19 AM UTC

Thank for your support!

Now it's working but it has new problem when i use virtualization.

[enableVirtualization]="true"

After add newCol i click to cell of newCol to edit data but new error like below is appear and dropdown is empty options.


You can check the link for detail: https://stackblitz.com/edit/angular-mqa5hw-pvg1sz?file=app.component.html



PS Pon Selva Jeganathan Syncfusion Team August 24, 2022 03:06 AM UTC

Hi Quang,


Thanks for the update.


Query: it has new problem when i use virtualization..


We have discussed same issue in this forum.  Please follow up the below forum for further information on the dropdown edit with virtualization.

https://www.syncfusion.com/forums/176954/can-not-load-dropdownlist-edit-when-enable-virtualization 


Please get back to us if you need more assistance. 


Regards,
Pon selva


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.



Marked as answer
Loader.
Up arrow icon