0
votes

Right now i managed to render to columnheader for all columns (See Screenshot). But my goal is to apply the cell renderer only for 1 SPECIFIC column. I am using Angular 5 and ag-grid/ag-grid-angular 17.0.0

enter image description here

My parent component looks like (For the sake of simplicity i cut the irrelevant thing out):

export class ClanModalComponent implements OnChanges {

  @Input() clanInfo: ClansByClantagType;

  rowData: ClanMembersType[];
  columnDefs;
  frameworkComponents;

  constructor(private router: Router) {
    this.columnDefs = [
      {headerName: 'Tag', field: 'tag', width: 120 },
      {headerName: 'Name', field: 'name', width: 170 },
      {headerName: 'Role', field: 'role', width: 120},
      {headerName: 'Level', field: 'expLevel', width: 80},
      {headerName: 'Home', field: 'trophies', width: 120},
      {headerName: 'Trophies Night', field: 'versusTrophies', width: 120}
    ];
    this.frameworkComponents = { agColumnHeader: TrophiesHomeCellRendererComponent };

  ngOnChanges(): void {
    if (this.clanInfo) {
      this.rowData = this.clanInfo.memberList;
    }
  }
  }

And my cellRenderer component looks like this:

@Component({
  selector: 'app-trophy-home',
  template: `<img [src]="trophyHomeImg" width="25px" height="auto">`
})
export class TrophiesHomeCellRendererComponent implements  AgRendererComponent {

  public trophyHomeImg = 'expected/image/path';

  agInit() {}

  refresh(){
    return false;
  }
}
1

1 Answers

3
votes

I think you need to use the headerComponentFramework property of the ColumnDef entry, instead of the frameworkComponents property. For example:

...
{
  headerName: 'Trophies Night',
  field: 'versusTrophies',
  width: 120,
  headerComponentFramework: TrophiesHomeCellRendererComponent
}
...

Your TrophiesHomeCellRendererComponent class needs to implement the IHeaderAngularComp interface, instead of the AgRendererComponent interface.

See this link for more information: ag-Grid Components