typescript - Angular 6 ag-grid cell renderer click function

typescript – Angular 6 ag-grid cell renderer click function

typescript – Angular 6 ag-grid cell renderer click function

I use cellRenderFramework:

    headerName: , width: 30,
    cellRendererFramework: ActionCellRendererComponent,
    cellRendererParams: {
      icon: fa-download,
      action: this.downloadAttachmentAction

and than I have custom Component

  selector: cu-download-link-cell-renderer,
  template: `
  <div class=text-center>
    <i class=fa {{params.icon}} (click)=onClick() aria-hidden=true></i>
export class ActionCellRendererComponent {


    constructor() {

    agInit(params): void {
        this.params = params;
        if (_.isNil(params.action)) {
            throw new Error(Missing action parameter for ActionCellRendererComponent);

   onClick(): void {

export type CellAction = (params) => void;

Use cellRendererFramework to add action Buttons.


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.


<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


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;

  viewRow() {
    let rowData = this.params;

After this we need to add this component in App.module.ts


  declarations: [AppComponent, CellCustomComponent],
  imports: [
  providers: [],
  entryComponents: [CellCustomComponent],
  bootstrap: [AppComponent]
export class AppModule {}

Now we can trigger a method in the component file using Button.


typescript – Angular 6 ag-grid cell renderer click function

Yes, use the cellRendererFramework to handle the rendering.

In your columnDefs:

this.columnDefs = [
    headerName: Header Name, field: field,
    cellRendererFramework: ColRenderer,
    cellRendererParams: { context: this },
    sortable: true, filter: true

Then in your ColRenderer:

  template: `<a (click)=clickHandler(rowData)>{{rowData.Member}}</a>`
export class ColRenderer implements ICellRenderer {
  public rowData: any;
  private params: any;

  public agInit(params: { data: any, context: any }) {
    this.rowData= params.data;
    this.params = params;

  public clickHandler(data: any) {

Change the names above obviously as needed. Just know the context is the key. You pass the context of your component to the renderer then use that context to call the function you want on click within your renderer.

Related posts on typescript :

Leave a Reply

Your email address will not be published.