Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 500
Rune Hansen Avatar asked Dec 18 '18 16:12

Rune Hansen


1 Answers

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

You want to use cellRendererFramework as seen in these examples:

  • https://www.ag-grid.com/ag-grid-angular2-support/
  • https://www.ag-grid.com/javascript-grid-cell-rendering-components/#example-rendering-using-more-complex-angular-components

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

like image 168
Kevin Doyon Avatar answered Oct 23 '22 05:10

Kevin Doyon