简体   繁体   English

ag-grid Angular - 如何通过标记/HTML 自定义列

[英]ag-grid Angular - How to customize the column via Markup/HTML

I am new to ag-grid and planning to implement that for our Angular project.我是ag-grid的新手,并计划为我们的 Angular 项目实施它。 It looks great except it's support for cell templating .它看起来很棒,除了它支持单元格模板 Unlike PrimeNG or Devextreme I don't see a "templating" feature for the column.PrimeNGDevextreme不同,我没有看到该列的“模板”功能。

Most of the documentation of ag-grid explains how to customize the cell via "cellrenderer" in component.ts class. ag-grid 的大部分文档都解释了如何通过 component.ts class 中的“cellrenderer”自定义单元格。 I want to customize the cell via html instead of.ts我想通过 html 而不是.ts 自定义单元格

Below code is part of PrimeNG to customize the cell via template.下面的代码是PrimeNG的一部分,用于通过模板自定义单元格。 Can someone help me to implement the same in ag-grid via html有人可以帮助我通过 html 在ag-grid中实现相同的功能吗

<ng-template pTemplate="body" let-product>
        <tr>
            <td>{{product.name}}</td>
            <td><img [src]="'assets/showcase/images/demo/product/' + product.image" [alt]="product.name" width="100" class="p-shadow-4" /></td>
            <td>{{product.price | currency:'USD'}}</td>
            <td>{{product.category}}</td>
            <td><p-rating [ngModel]="product.rating" [readonly]="true" [cancel]="false"></p-rating></td>
            <td><span [class]="'product-badge status-' + product.inventoryStatus.toLowerCase()">{{product.inventoryStatus}}</span></td>
        </tr>
    </ng-template>

Thanks for your help on this.感谢您对此的帮助。

You can return an angular component instead of just plain text.您可以返回 angular 组件,而不仅仅是纯文本。 You can do this using cellRendererFramework that you can access from the column definition.您可以使用可以从列定义访问的cellRendererFramework来执行此操作。

{
          headerName: "CLIENT",
          field: "client",
          cellRendererFramework: (params) => {
            return <AgGridCellRenderer>
              
            </AgGridCellRenderer>
          },
        },

the params argument has all the agRid stuff like ´api and columApi` as well as the original cell value as well as the entire row data. params参数包含所有 agRid 内容,例如 'api and columApi' 以及原始单元格值以及整个行数据。

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

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