【问题标题】:Angular - Ag-grid cellRendering only on one column headerAngular - Ag-grid cellRendering 仅在一个列标题上
【发布时间】:2018-10-09 17:39:11
【问题描述】:

现在我设法为所有列渲染到列标题(参见屏幕截图)。 但我的目标是将单元格渲染器仅应用于 1 个特定列。 我正在使用 Angular 5 和 ag-grid/ag-grid-angular 17.0.0

我的父组件看起来像(为了简单起见,我把不相关的东西删掉了):

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

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

【问题讨论】:

    标签: angular typescript ag-grid ag-grid-ng2


    【解决方案1】:

    我认为您需要使用ColumnDef 条目的headerComponentFramework 属性,而不是frameworkComponents 属性。例如:

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

    您的TrophiesHomeCellRendererComponent 类需要实现IHeaderAngularComp 接口,而不是AgRendererComponent 接口。

    查看此链接了解更多信息:ag-Grid Components

    【讨论】:

    • 是的,你是对的,解决了我的问题,但忘记发布答案。谢谢你:)
    猜你喜欢
    • 1970-01-01
    • 2018-09-21
    • 2016-03-11
    • 1970-01-01
    • 2019-10-13
    • 2019-04-19
    • 2022-01-23
    • 2019-06-14
    • 2019-08-22
    相关资源
    最近更新 更多