[app.component.ts]
@Component({ selector: 'app-root',
template: '<div><DataGrid></DataGrid></div>',
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [ToolbarService, EditService, PageService]
})-------------------------------------------------------------------------------------------------------------------
[app.childcomponent.ts] @Component({ selector: 'DataGrid',
template: `
<ejs-grid #grid [dataSource]='data' [height]='400'>
<e-columns>
<e-column field='OrderID' headerText='Order ID' width='120' textAlign='Left'></e-column>
<e-column field='CustomerID' headerText='Customer Name' width='150'></e-column>
<e-column field='OrderDate' headerText='Order Date' width='130' format="yMd" textAlign='Right'></e-column>
</e-columns>
</ejs-grid>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
// styleUrls: ['./child.component.css']
})
export class ChildComponent {
@ViewChild('grid', { static: true }) public grid: GridComponent;
public data: object[];
public selectionOptions: SelectionSettingsModel;
ngOnInit(): void {
this.data = hierarchyOrderdata;
}
} |
[app.component.ts]
@Component({ selector: 'app-root',
template: `<div><DataGrid [tableColumns]="tableColumns"></DataGrid></div>`,
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [ToolbarService, EditService, PageService]
})
export class AppComponent implements OnInit {
tableColumns:any = [{
field: "OrderID",
headerText: "Order ID",
textAlign: "Right",
width: 120
},
{
field: "CustomerID",
headerText: "Customer ID",
width: 140
},
{
field: "Freight",
headerText: "Freight",
textAlign: "Right",
width: 120,
format: "C2",
},]
}-------------------------------------------------------------------------------------------------------------------
[app.childcomponent.ts] @Component({ selector: 'DataGrid',
template: `
<ejs-grid #grid [dataSource]='data' [height]='400' [columns]='gcolumns'>
</ejs-grid>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
// styleUrls: ['./child.component.css']
})
export class ChildComponent {
@Input() childProperty: any;
@Input() tableColumns: any;
constructor() {
this.initDefaults();
}
private initDefaults(): void {
this.tableColumns = [];
}
@ViewChild('grid', { static: true }) public grid: GridComponent;
public data: object[];
public selectionOptions: SelectionSettingsModel;
public gcolumns: object[];
ngOnInit(): void {
debugger;
this.data = hierarchyOrderdata;
this.gcolumns = this.tableColumns;
}
} |