Search code examples
angularfont-awesomeag-gridag-grid-angular

Ag-grid cellRenderer with Font Awesome Icons


I am attempting to add Font Awesome Icons via cellRenderer in ag-grid.

How can I properly render <fa-icon> tags within a cell render?

Here is what I attempted:

    {
      width: 150,
      headerName: 'Events',
      // tslint:disable-next-line: object-literal-shorthand
      cellRenderer: (params: any) => {
        const PHD: boolean = params.data.PHD;
        const DG: boolean = params.data.DG;
        const HOT: boolean = params.data.HOT;
        let result = '';
        if (PHD) {
          result = result + '<fa-icon [icon]="faCoffee"></fa-icon>';
        }
        if (DG) {
          result = result + '';
        }
        if (HOT) {
          result = result + '';
        }
        return result;
      },
      resizable: true,
      filter: false,
    },

Here is how it renders from cellRenderer:

Placing the tag within the component HTML works and renders to the page like this:


Solution

  • fa-icon is a custom angular component which won't be parsed by your simple cell renderer.

    Instead of this

    '<fa-icon [icon]="faCoffee"></fa-icon>'
    

    you should use the simpler <i> approach

    '<span><i class="fa fa-coffee"></i></span>';
    

    for your simple cell renderer to work.

    However if you want still want to use the fa-icon angular component, then you should look into implementing a cell Renderer component as described here.