I'm trying to add a simple component in ag-grid table cell . I flow the instructions in aggrid website but it dos'nt render the component . here is my code :
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,
}
]
the gridoptiopns is :
this.gridOptions = <GridOptions>{
rowData: this.rowData,
columnDefs: this.columnDefs,
context: {
componentParent: this
},
enableColResize: true
};
and the componet is :
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;
}
}
in operation html I just have a button. but nothing appear in aggrid cell.
The component you are using as the cell renderer should implement the ICellRendererAngularComp given from ag-grid.
operation.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() { }
}
Then you must tell aggrid to use this operation component as a custom component. It is done by providing them in the 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 { }