|
[app.component.html]
<ejs-grid #grid [dataSource]='data' [allowPaging]='true'>
<e-columns>
<ng-template #template ngFor let-column [ngForOf]="columns">
<e-column [field]="column.field"
[headerText]="column.headerText"
[allowEditing]="column.allowEditing"
[isPrimaryKey]="column.isPrimaryKey != null ? column.isPrimaryKey : null"
[width]="column.width">
</e-column>
</ng-template>
</e-columns>
</ejs-grid>
<ng-template #header>
<span class="e-icon-userlogin e-icons employee"></span>
Emp ID
</ng-template>
[app.component.ts]
export class DefaultComponent implements OnInit {
. . .
public template: any;
@ViewChild('header')
public headerTemp: NgModel;
@ViewChild('grid')
public grid: Grid;
public columns: any;
ngOnInit(): void {
this.data = employeeData;
this.columns = [{ field: "EmployeeID", isPrimaryKey: "true", headerText: "Employee ID", width: "90" },
{ field: "FirstName", headerText: "First Name", width: "90" },
{ field: "LastName", headerText: "Last Name", width: "90", allowEditing: false },
{ field: "Country", headerText: "Country", width: "90" }]
}
ngAfterViewInit(): void {
(this.grid.getColumns()[3].headerTemplate as any) = this.headerTemp;
}
|
|
<ejs-grid #grid [dataSource]='data' [allowPaging]='true'>
<e-columns>
<ng-template #template ngFor let-column [ngForOf]="columns">
<e-column [field]="column.field"
[headerText]="column.headerText"
[allowEditing]="column.allowEditing"
[isPrimaryKey]="column.isPrimaryKey != null ? column.isPrimaryKey : null"
[width]="column.width">
</e-column>
</ng-template>
</e-columns>
</ejs-grid>
<ng-template let-data #template1>
<div>
<span style="background: red">a</span>
</div>
</ng-template>
<ng-template let-data #template2>
<span style="background: blue">{{data.FirstName}}</span>
</ng-template>
<ng-template let-data #template3>
<span style="background:green">template-Data</span>
</ng-template>
</div>
[app.component.ts]
public data: Object[] = [];
public gridData: any;
public template: any;
@ViewChild('header')
public headerTemp: NgModel;
@ViewChild('template1')
public temp1: NgModel;
@ViewChild('template2')
public temp2: NgModel;
@ViewChild('template3')
public temp3: NgModel;
@ViewChild('grid')
public grid: Grid;
public columns: any;
ngOnInit(): void {
this.data = employeeData;
this.columns = [{ field: "EmployeeID", isPrimaryKey: "true", headerText: "Employee ID", width: "90" },
{ field: "FirstName", headerText: "First Name", width: "90" },
{ field: "LastName", headerText: "Last Name", width: "90", allowEditing: false },
{ field: "Country", headerText: "Country", width: "90" }]
}
ngAfterViewInit(): void {
(this.grid.getColumns()[1].template as any) = this.temp1;
(this.grid.getColumns()[2].template as any) = this.temp2;
(this.grid.getColumns()[3].template as any) = this.temp3;
}
}
|
|
@Component({
selector: 'control-content',
template: '<div class="control-section">
<ejs-grid #grid [dataSource]='data' [allowPaging] = 'true' [columns]="gridColumns">
</ejs-grid>
<ng-template let-data #template1>
<button ejs-button> Button </button>
</ng-template >
</div> ',
styleUrls: ['default.component.css']
})
export class DefaultComponent implements OnInit {
. . .
@ViewChild('template1')
public temp1: NgModel;
ngAfterViewInit(): void {
this.gridColumns = [{ field: "EmployeeID", isPrimaryKey: "true", headerText: "Employee ID", width: "90" },
{ headerText: "Button", width: "90", template: this.temp1 }];
}
} |
|
...
@Component({
selector: 'app-root',
template: `<ejs-grid [dataSource]='data | async' [frozenRows]='2' [frozenColumns]='1' [allowPaging]='true' [pageSettings]='pageOptions' [allowSorting]='true' [allowGrouping]='true' (dataStateChange)= 'dataStateChange($event)'>
<e-columns>
<ng-template ngFor let-column [ngForOf]="columns">
<e-column [field]="column.field"
[headerText]="column.headerText"
[allowEditing]="column.allowEditing"
[isPrimaryKey]="column.isPrimaryKey != null ? column.isPrimaryKey : null"
[width] = "column.width"
>
</e-column>
</ng-template>
</e-columns>
</ejs-grid>`,
providers: [OrdersService, PageService, FreezeService, SortService, GroupService]
})
export class AppComponent implements OnInit {
public data: Observable<DataStateChangeEventArgs>;
public pageOptions: Object;
public state: DataStateChangeEventArgs;
constructor(public service: OrdersService) {
this.data = service;
}
public columns: any;
public dataStateChange(state: DataStateChangeEventArgs): void {
this.service.execute(state);
}
public ngOnInit(): void {
this.pageOptions = { pageSize: 5, pageCount: 4 };
let state = { skip: 0, take: 20 };
this.service.execute(state);
this.columns = ...]
}
}
|
|
[app.component.html]
<ejs-grid #grid [dataSource]='data' allowPaging='true' [pageSettings]='pageSettings' [editSettings]='editSettings'
[toolbar]='toolbar'>
<e-columns>
<e-column field='ShipCountry' headerText='Ship Country' width='150' [template]="languageEditTemplate">
</e-column>
<e-column field='OrderID' headerText='Order ID' width='120' textAlign='Right' isPrimaryKey='true'
[validationRules]='orderidrules'></e-column>
<e-column field='CustomerName' headerText='Customer Name' width='120' [validationRules]='customeridrules'>
</e-column>
<e-column field='Freight' headerText='Freight' width='120' format='C2' textAlign='Right'
editType='numericedit' [validationRules]='freightrules'></e-column>
</e-columns>
</ejs-grid>
<ng-template #languageEditTemplate let-column>
<ejs-dropdownlist [width]='column.width' [dataSource]='languages' (change)='change($event)' [value]='column.ShipCountry'
[fields]="{text:'ShipCountry', value: 'ShipCountry'}" [placeholder]='column.headerText'></ejs-dropdownlist>
</ng-template>
|
Hello,
here the languageEditTemplate is valid only for one column as you are mentioning column specific data in the template
if i want to use a single template for more than one columns how can it be done??
Hi Karthik,
Based on your query, you want to use single template for the entire row, your requirement can be achieved by using the ‘rowTemplate’. We have already discussed the same in the below documentation and sample demo. Please refer the below for more details.
Documentation: https://ej2.syncfusion.com/angular/documentation/grid/row/row-template
Sample: https://ej2.syncfusion.com/angular/demos/#/bootstrap5/grid/row-template
Hello Joseph,
Thank you for the response,
is it possible to reuse templates only for some columns instead of entire row.
i want to utilize batch editing experience for other columns and i have multilevel stacked header generated by columns attribute in e-columnand these columns are built dynamically in typescript.
I would be helpful if you can prepare a sammple for the above scenarios
Hi Karthik,
Before proceeding to the solution, we would like you to share the below details.