Use cellRendererFramework to add action Buttons.
App.component.ts
columnDefs = [
{ headerName: 'First Name', field: 'firstName', sortable: true, filter: true },
{ headerName: 'Last Name', field: 'lastName', sortable: true, filter: true },
{ headerName: 'Email', field: 'email', sortable: true, filter: true },
{ headerName: 'User Name', field: 'userIdName', sortable: true, filter: true },
{ headerName: 'Role', field: 'role', sortable: true, filter: true },
{ headerName: 'Actions', field: 'action', cellRendererFramework: CellCustomComponent }];
rowData: any;
ngOnInit() {
const empDatas = localStorage.getItem('user');
const finalData = JSON.parse(this.empDatas);
this.rowData = this.finalData;
}
In the above code, we can see CellCustomComponent. Create that component & add the buttons.
cell-custom.component.html
<button type="button" class="btn-success" (click)="editRow()">Edit</button>
<button type="button" class="btn-success" (click)="viewRow()">View</button>
Now in the cell-custom.component.ts add the functions
cell-custom.component.ts
export class CellCustomComponent implements OnInit {
data: any;
params: any;
constructor(private http: HttpClient, private router: Router) {}
agInit(params) {
this.params = params;
this.data = params.value;
}
ngOnInit() {}
editRow() {
let rowData = this.params;
let i = rowData.rowIndex;
console.log(rowData);
}
viewRow() {
let rowData = this.params;
console.log(rowData);
}
}
After this we need to add this component in App.module.ts
app.Module.ts
@NgModule({
declarations: [AppComponent, CellCustomComponent],
imports: [
BrowserModule,
AppRoutingModule,
FormsModule,
HttpClientModule,
AgGridModule.withComponents([AppComponent])
],
providers: [],
entryComponents: [CellCustomComponent],
bootstrap: [AppComponent]
})
export class AppModule {}
Now we can trigger a method in the component file using Button.