Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

javascript - 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. It looks great except it's support for cell templating. Unlike PrimeNG or Devextreme I don't see a "templating" feature for the column.

Most of the documentation of ag-grid explains how to customize the cell via "cellrenderer" in component.ts class. I want to customize the cell via html instead of .ts

Below code is part of PrimeNG to customize the cell via template. Can someone help me to implement the same in ag-grid via html

<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.

question from:https://stackoverflow.com/questions/65853492/ag-grid-angular-how-to-customize-the-column-via-markup-html

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can return an angular component instead of just plain text. You can do this using cellRendererFramework that you can access from the column definition.

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

the params argument has all the agRid stuff like ′apiandcolumApi` as well as the original cell value as well as the entire row data.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...