| <ejs-grid #grid [dataSource]='data' allowFiltering='true' [filterSettings]='filterSettings'> ... <e-column field='operatorName' [valueAccessor]="getTranslate" [allowEditing]='false' [filter]='filter'> ... </ejs-grid> |
xxx.component.ts
| ... ngOnInit(): void { this.filterSettings = { type: 'Excel' }; this.filter = { itemTemplate: '<div>${getValue(operatorName)}</div>' }; } public getValue = (data: Object) => { return (data as any).operatorName !== undefined ? this.localizationService.getTranslation((data as any).operatorName) : "Select All"); } |
But an error occurred when the Excel filter is open. The error message is "ReferenceError: getValue is not defined"
How can I call getValue in itemTemplate? Thanks!!
|
[app.comoponent.html]
<ejs-grid #grid [dataSource]='data' [allowFiltering]='true' [filterSettings]='filterSettings'>
<e-columns>
<e-column field='EmployeeID' headerText='Employee ID' width='125' textAlign='Right'></e-column>
<e-column field='FirstName' headerText='First Name' width='120'></e-column>
<e-column field='Title' [valueAccessor]='valueAccess' [filter]='filter' headerText='Title' width='170'></e-column>
</e-columns>
</ejs-grid>
[app.component.ts]
. . .
export class FilteringMenuComponent implements OnInit {
. . .
public filter: IFilter;
@ViewChild('grid')
public grid: GridComponent;
ngOnInit(): void {
. . .
this.filterSettings = { type: 'Excel' };
this.filter = { itemTemplate: '#temp' };
}
. . .
}
}
[Index.html]
<script id='temp' type='text/x-template'> ${getValue(data)}</script>
<script>
function getValue(data) {
var val;
if (data['Title'] != undefined) {
if (data['Title'] === "Select All") {
val = "Select All";
}
else{
// change your value here
val = data['Title']+" "+"custom";
}
return val
}
}
</script>
|