mar*_*ral 2 cellrenderer angular ag-grid-angular
我正在尝试在 ag-grid table cell 中添加一个简单的组件。我在 aggrid 网站中流动指令,但它不呈现组件。这是我的代码:
columnDefs = [
{ headerName: "Name", field: "name" ,width: 400},
{ headerName: "GoodsFinalCode", field: "goodsFinalCode" ,width: 200},
{ headerName: "operation", field: "operation" ,cellRendererFramework: OperationComponent, width: 450}
];
rowData = [ {
name : 'b',
goodsFinalCode :6,
}
]
Run Code Online (Sandbox Code Playgroud)
gridoptions 是:
this.gridOptions = <GridOptions>{
rowData: this.rowData,
columnDefs: this.columnDefs,
context: {
componentParent: this
},
enableColResize: true
Run Code Online (Sandbox Code Playgroud)
};
组件是:
import { Component } from '@angular/core';
@Component({
selector: 'app-operation',
templateUrl: './operation.component.html',
styleUrls: ['./operation.component.scss']
})
export class OperationComponent {
private params: any;
agInit(params: any): void {
this.params = params;
}
}
Run Code Online (Sandbox Code Playgroud)
在操作 html 中,我只有一个按钮。但aggrid单元格中没有出现任何内容。
您用作单元格渲染器的组件应该实现从 ag-grid 给出的 ICellRendererAngularComp。
操作.component.ts
import { Component } from '@angular/core';
import { ICellRendererAngularComp } from 'ag-grid-angular';
@Component({
selector: 'app-operation',
templateUrl: './operation.component.html',
styleUrls: ['./operation.component.css']
})
export class OperationComponent implements ICellRendererAngularComp {
private params: any;
agInit(params: any): void {
this.params = params;
}
refresh(): boolean {
return false;
}
constructor() { }
}
Run Code Online (Sandbox Code Playgroud)
然后你必须告诉aggrid使用这个操作组件作为自定义组件。这是通过在 AgGridModule 中提供它们来完成的。
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { AgGridModule } from 'ag-grid-angular';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';
import { OperationComponent } from './grid/options-cell-renderer/options-cell-renderer.component';
@NgModule({
declarations: [
AppComponent,
OperationComponent
],
imports: [
BrowserModule,
FormsModule,
CommonModule,
NgbModule,
HttpClientModule,
AgGridModule.withComponents([
OperationComponent
])
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4182 次 |
| 最近记录: |