简体   繁体   中英

Angular - Ag-grid cellRendering only on one column header

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

在此处输入图片说明

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;
  }
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM