下面是在单元格渲染器自定义组件中使用 ng-template 的示例,您可以创建多个跨度,并且可以使用 ngif 显示和隐藏或根据属性控制要显示的元素。在下面的代码中,我只使用了一个跨度,您可以根据需要进行修改。同样在编写完这个单元格渲染器组件后,我将名称分配给coldefs 中ag-grid 的单元格渲染器。
import { Component } from "@angular/core";
import { ICellRendererAngularComp } from "ag-grid-angular";
@Component({
selector: 'tooltip-cell',
template: `<ng-template #popTemplate>
<div class="tooltip-renderer">
Created By: {{creator}} <br/>
Created On: {{crDateTime | date:'short'}} <br/>
Revised By: {{revisor}} <br/>
Revised On: {{revDateTime | date:'short'}} <br/>
</div>
</ng-template>
<span [tooltip]="popTemplate" placement="left" container="body" triggers="mouseenter mouseleave dblclick">{{params.value}}</span>` })
export class ToolTipRenderer implements ICellRendererAngularComp {
public params: any;
public creator: any;
public crDateTime: any;
public revisor: any;
public revDateTime: any;
agInit(params: any): void {
this.params = params;
this.creator = params.data["Creator"];
this.crDateTime = params.data["CrDate"];
this.revisor = params.data["Revisor"];
this.revDateTime = params.data["RevDate"];
}
refresh(): boolean {
return false;
}
}
var colDef1 = {
cellRenderer: "tooltipRenderer",
...
}