let grid: TreeGrid = new TreeGrid(
{
dataSource: sampleData,
childMapping: 'subtasks',
treeColumnIndex: 1,
height: 400,
columns: [
{
field: 'taskID', headerText: 'Task ID', isPrimaryKey: true, textAlign: 'Right',
validationRules: { required: true, number: true }, width: 80
},
{
headerText: 'Manage Records', width: 130,
commands: [{ type: 'Edit', buttonOption: { iconCss: ' e-icons e-edit', cssClass: 'e-flat' } },
{ type: 'Delete', buttonOption: { iconCss: 'e-icons e-delete', cssClass: 'e-flat' } },
{ type: 'Save', buttonOption: { iconCss: 'e-icons e-update', cssClass: 'e-flat' } },
{ type: 'Cancel', buttonOption: { iconCss: 'e-icons e-cancel-icon', cssClass: 'e-flat' } }]
}
]
});
grid.appendTo('#Grid'); |
Hi Sunithra,
Thanks for contacting Syncfusion Support.
Query#:- I need a help by Adding a button control in treegrid by doing Action like Edit & Delete option.
We have checked your query and by default TreeGrid provides an option to render CRUD action buttons in a column by using the CommandColumn feature.Please refer to the code example:-
let grid: TreeGrid = new TreeGrid({dataSource: sampleData,childMapping: 'subtasks',treeColumnIndex: 1,height: 400,columns: [{field: 'taskID', headerText: 'Task ID', isPrimaryKey: true, textAlign: 'Right',validationRules: { required: true, number: true }, width: 80},{headerText: 'Manage Records', width: 130,commands: [{ type: 'Edit', buttonOption: { iconCss: ' e-icons e-edit', cssClass: 'e-flat' } },{ type: 'Delete', buttonOption: { iconCss: 'e-icons e-delete', cssClass: 'e-flat' } },{ type: 'Save', buttonOption: { iconCss: 'e-icons e-update', cssClass: 'e-flat' } },{ type: 'Cancel', buttonOption: { iconCss: 'e-icons e-cancel-icon', cssClass: 'e-flat' } }]}]});grid.appendTo('#Grid');
Demo and Documentation Link:-
Please get back to us if you need any further assistance.
Regards,Farveen sulthana T
Hi Sunithra,Query#:- If i click on Edit button on that page it should take me to our popup instead of showing default popup , instead of inline editing .From your query we suspect that you need to customize the Dialog Form with your Template. In Tree Grid, we have the support of Template driven Forms so that you can place the forms using ngTemplate with editSettings mode with Dialog.Refer to the documentation and Demo Link:-
Sample Link:- https://stackblitz.com/run?file=app.component.html
If your requirement is different from above solution, please get back to us with further details.
Regards,Farveen sulthana T
select(args: DialogEditEventArgs): void {
if(!args.target.classList.contains("e-btn-icon"))
window.location.assign("https://ej2.syncfusion.com/home/angular.html"); //url as per your requirement
}
|
ngOnInit(): void {
-----------
this.commands = [{ type: 'Edit', buttonOption: { content: 'Edit', cssClass: 'e-flat' } },
{ type: 'Delete', buttonOption: { content: 'Delete', cssClass: 'e-flat' } },
{ type: 'Save', buttonOption: { content: 'Save', cssClass: 'e-flat' } },
{ type: 'Cancel', buttonOption: { content: 'Cancel', cssClass: 'e-flat' } }];
}
|
select(args: DialogEditEventArgs): void {
// - check if args.target contain class name of expand/collapse icon (e-treegridexpand and e-treegridcollapse) and class name of custom command button (e-btn)
if(!args.target.classList.contains("e-btn") && !args.target.classList.contains("e-treegridexpand") && !args.target.classList.contains("e-treegridcollapse") )
window.location.assign("https://ej2.syncfusion.com/home/angular.html"); //url as per your requirement
}
|
<style>
.e-icons.e-treegridcollapse::before{
content: '\e913'
}
.e-icons.e-treegridexpand::before{
content: '\e913'
}
</style> |
App.component.html
<ejs-treegrid [dataSource]='data' childMapping='subtasks' [treeColumnIndex]='1'allowPaging='true' [pageSettings]='pageSettings' [editSettings]='editSettings' (queryCellInfo)="queryCellInfo($event)" >
<e-columns>
<e-column field='taskID' headerText='Task ID' width='120' textAlign='Right' isPrimaryKey='true' ></e-column>
. . .
</e-columns>
</ejs-treegrid>
App.component.ts
queryCellInfo(args: QueryCellInfoEventArgs): void {
if (args.data.index == 0) {
if (args.cell.classList.contains("e-unboundcell")) {
args.cell.querySelector('.e-unboundcelldiv').style.display = "none";
args.cell.innerText = "Header";
}
} |