import { Component, OnInit, ViewChild } from '@angular/core';
import { sampleData } from '../jsontreegriddata';
import {ClipboardModule} from '@angular/cdk/clipboard';
import {
SortService,
ResizeService,
PageService,
EditService,
ExcelExportService,
PdfExportService,
ContextMenuService,
TreeGridComponent,
} from '@syncfusion/ej2-angular-treegrid';
import { EditSettingsModel } from '@syncfusion/ej2-treegrid';
import { ContextMenuClickEventArgs } from '@syncfusion/ej2-grids';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
providers: [
SortService,
ResizeService,
PageService,
EditService,
ExcelExportService,
PdfExportService,
ContextMenuService
]
})
export class AppComponent {
public data: Object[] = [];
public pageSettings: Object;
public contextMenuItems: string[] = [];
public editing: EditSettingsModel;
public toolbar: string[];
public editparams: Object;
public rowIndex: number;
public cellIndex: number;
public selectionOptions: Object;
@ViewChild('treegrid')
public treeGridObj: TreeGridComponent;
contextMenuSettings: (string | { text: string; target: string; id: string; })[];
treegrid: any;
ngOnInit(): void {
this.data = sampleData;
{this.contextMenuSettings = [
'AutoFit',
'AutoFitAll',
'SortAscending',
'SortDescending',
'Edit',
'Delete',
'Save',
'Cancel',
'FirstPage',
'PrevPage',
'LastPage',
'NextPage',
{ text: 'Copy', target: '.e-content', id: 'customCopy'},
{ text: 'Paste', target: '.e-content', id: 'customPaste'},
];}
this.selectionOptions = {
type: 'Multiple',
mode: 'Cell',
cellSelectionMode: 'Box'
};
(this.editing = {
allowEditing: true,
allowAdding: true,
allowDeleting: true,
mode: 'Batch'
}),
(this.pageSettings = { pageSize: 10 });
this.editparams = { params: { format: 'n' } };
}
contextMenuOpen(args): void {
this.rowIndex = args.rowInfo.rowIndex;
this.cellIndex = args.rowInfo.cellIndex;
}
contextMenuClick(args): void {
if (args.item.id === 'customCopy') {
this.treeGridObj.copy();
} else if (args.item.id === 'customPaste') {
var rowIndex = this.rowIndex;
var cellIndex = this.cellIndex;
var copyContent = this.treeGridObj.clipboardModule.copyContent;
this.treeGridObj.paste(copyContent, rowIndex, cellIndex);
}
}
}