Joe*_*Joe 0 angular7 ag-grid-angular
ag-grid 社区 v20,Angular 7。
我ag-grid在我的Angular 7应用程序中有一个工作。我想在一列中显示图像。该https地址包含在列field。我搜索了 ag-grid 的文档和网络,但没有找到这个基本场景的例子。有人可以为columnDef. 是cellRenderer这样做的方法吗?
{ headerName: 'Select', field: 'Image', width: 75, sortable: false,
cellRenderer: '<span><img border="0" width = "15" height="10" src=xxxx ></span>' },
Run Code Online (Sandbox Code Playgroud)
这是一个多步骤的过程。
创建自定义组件。'ImageFormatterComponent.ts'
import { Component } from "@angular/core";
@Component({
selector: 'app-image-formatter-cell',
template: `<img border="0" width="50" height="50" src=\"{{ params.value }}\">` })
export class ImageFormatterComponent {
params: any;
agInit(params: any){
this.params = params;
}
}
Run Code Online (Sandbox Code Playgroud)
在注册 app.module.ts
import { ImageFormatterComponent } from "./album/ImageFormatterComponent";
@NgModule({
declarations: [ImageFormatterComponent],
imports: [
AgGridModule.withComponents([ImageFormatterComponent])
],
Run Code Online (Sandbox Code Playgroud)
在您使用它的组件中:
import { ImageFormatterComponent } from "./ImageFormatterComponent";
columnDefs = [
{ headerName: 'Select',
field: 'Image',
width: 60,
sortable: false,
autoHeight: true,
cellRendererFramework: ImageFormatterComponent
}
Run Code Online (Sandbox Code Playgroud)