简体   繁体   English

Angular-Ag-grid单元仅在一个列标题上呈现

[英]Angular - Ag-grid cellRendering only on one column header

Right now i managed to render to columnheader for all columns (See Screenshot). 现在,我设法将所有列渲染为columnheader(请参见屏幕截图)。 But my goal is to apply the cell renderer only for 1 SPECIFIC column . 但是我的目标是仅将单元格渲染器应用于1 SPECIFIC列 I am using Angular 5 and ag-grid/ag-grid-angular 17.0.0 我正在使用Angular 5和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: 我的cellRenderer组件如下所示:

@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. 我认为您需要使用ColumnDef条目的headerComponentFramework属性,而不是frameworkComponents属性。 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. 您的TrophiesHomeCellRendererComponent类需要实现IHeaderAngularComp接口,而不是AgRendererComponent接口。

See this link for more information: ag-Grid Components 有关更多信息,请参见此链接: ag-Grid组件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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