Search code examples
angulartypescriptag-grid-angular

How to Render an Angular routerLink inside the cell of an ag-Grid?


The link I am trying to render looks like this when I just try to render it on a basic HTML page:

<a [routerLink]="['/leverance/detail', 13]">A new link</a>

When trying to render it on the ag-Grid, I try to do like below:

src\app\leverancer\leverancer.component.ts

ngOnInit() {
    this.dataGridColumnDefs = [
          { 
            headerName: 'Type', 
            field: 'leveranceType.name', 
            width: 150,
            cellRenderer: this.customCellRendererFunc       
          }
    ];
}

customCellRendererFunc(params): string {
  const cellContent `<a [routerLink]="['/leverance/detail', 13]">A new link</a>`;
  return cellContent;
}

but I don't see a working routerLink in my ag-Grid. Can you tell me what I need to do to render a working routerLink in my ag-Grid?


Solution

  • I think cellRenderer only supports normal HTML (without any angular-specific stuff).

    You want to use cellRendererFramework as seen in these examples:

    Since you use RouterLink, you probably need RouterModule in the moduleImports