Ag-grid cellRenderer with Font Awesome Icons

本秂侑毒 提交于 2020-05-13 19:28:08

问题


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:


回答1:


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.



来源:https://stackoverflow.com/questions/61505741/ag-grid-cellrenderer-with-font-awesome-icons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!