[index.html]
<script type="text/x-jsrender" id="template">
<img style="width: 75px; height: 70px" src="app/content/images/grid/Employees/{{:EmployeeID}}.png" alt="{{:EmployeeID}}" />
</script>
[app.component.html]
<ej-grid [(dataSource)]="gridData" [columns]=col>
</ej-grid>
[app.component.ts]
constructor(private service: NorthwindService) {
this.col = [{field:"OrderID",isPrimaryKey:true},
{field: "EmployeeID"},
{headerText:"Employee Image", template:"#template"}]
} |
Index.html
<script type="text/ng-template" id="template">
<input type="button" class="button" value="click"/>
</script>
app.component.html
<ej-grid [(dataSource)]="gridData" [columns]=col (templateRefresh)="onTemplateRefresh($event)">
</ej-grid>
app.component.ts
export class AppComponent {
. . .
onTemplateRefresh(args) {
$(args.cell).find(".button").bind("click",function(e){
//To do your code
});
}
}
|
Index.html
<script type="text/ng-template" id="template">
<input type="button" class="button" value="click"/>
</script>
app.component.html
<ej-grid [(dataSource)]="gridData" [columns]=col (templateRefresh)="onTemplateRefresh($event)">
</ej-grid>
app.component.ts
export class AppComponent {
. . .
onTemplateRefresh(args) {
$(args.cell).find(".button").bind("click",function(e){
//To do your code
});
}
}
|
app.component.html
<ej-grid [(dataSource)]="gridData" [columns]=col>
</ej-grid>
app.component.ts
export class AppComponent {
. . .
public col:any;
public openCommand = [{
type: "Detail", buttonOptions: {
text: "Open Report",
width: "100",
click: this.onOpenReportClick.bind(this),
}
}];
constructor(private service: NorthwindService) {
. . .
this.col = [{field:"OrderID",isPrimaryKey:true},
{field: "EmployeeID"},
{headerText: "Details", commands: this.openCommand, isUnbound: true, textAlign: ej.TextAlign.Left, width: 150}
]
}
onOpenReportClick(e: any) {
debugger
}
|
hi,if put the template outside the ej-grid tag and use text/x-jsrender as template so it is possible to call angular2 function in component if I have a button in jsrender template ?
[Html]
<ej-grid [allowPaging]="true"
[pageSettings]="pagesetting" [allowGrouping]="true"
[dataSource]="gridData"
>
<e-columns>
<e-column headerText="Employee Image" width="110" textAlign="center">
<!--Using template directive-->
<template e-template let-data>
<!--Render ej button with click event-->
<input type="button" ej-button id="button" [text]="text" [value]="Button" (click)="onClick($event)"/>
</template>
</e-column>
. . .
</e-columns>
</ej-grid>
[TS]
export class GridComponent {
. . .
onClick(e) {
//To do your functionality
}
} |
import { NgModule, enableProdMode, ErrorHandler } from '@angular/core';
. . . . .
import {EJAngular2Module,EJTemplateDirective} from 'ej-angular2';
.. . . . . . . .
import { rootRouterConfig } from './app.routes';
. . . .
@NgModule({
imports: [BrowserModule, FormsModule, HttpModule,
EJAngular2Module.forRoot(),
. . . .],
declarations: [AppComponent, HomeComponent, GridComponent,
EJTemplateDirective
],
bootstrap: [AppComponent]
})
export class AppModule { }
|