You can use just a "cellRenderer" to implement a Dropdown in a cell of a ag-grid. It's not necessary a "cellEditor"
@Component({
selector: 'app-project-status-management',
templateUrl: './project-status-management.component.html',
styleUrls: ['./project-status-management.component.scss']
})
export class ProjectStatusManagementComponent implements OnInit {
// Template of the Grid
@ViewChild('agGrid', { static: false }) agGrid: AgGridAngular;
// Template to the Select (Dropdown)
@ViewChild('templateCell', { static: true }) templateCell: TemplateRef<any>;
columnDefs: any;
frameworkComponents: any;
gridContext: any;
data: any[];
// Values shown on Dropdown
availableStatus: WorkflowStatus[] = [
{
workflowStatusId: 1,
name: 'InDesign',
description: 'In Design'
},
{
workflowStatusId: 3,
name: 'SourceReviewed',
description: 'Source Reviewed'
},
{
workflowStatusId: 5,
name: 'Translated',
description: 'Translated'
},
];
ngOnInit() {
this.setUpGrid();
// Set the context of the ag-grid
this.gridContext = {
availableStatus: this.availableStatus,
};
}
setUpGrid() {
// setup columns
this.columnDefs = [
{
colId: 'projectStatus',
headerName: 'Status',
field: 'workflowStatus.workflowStatusId',
cellRenderer: 'GridActionButtonCell',
cellRendererParams: {
ngTemplate: this.stringStatusCell
},
width: 170,
}];
this.frameworkComponents = {
GridActionButtonCell: GridActionButtonComponent,
};
}
}
<div>
...
<ag-grid-angular #agGrid
[rowData]="data"
[columnDefs]="columnDefs" [context]="gridContext"
[suppressRowClickSelection]="true"
...
[frameworkComponents]="frameworkComponents">
</ag-grid-angular>
...
</div>
<ng-template #templateCell let-row let-context="params">
<div class="d-flex flex-row" style="height: 100%;">
<select [(ngModel)]="row.workflowStatus.workflowStatusId">
<option *ngFor="let status of context.context.availableStatus" [ngValue]="status.workflowStatusId">{{status.description}}</option>
</select>
</div>
</ng-template>
Define a template '#templateCell' containing a element.
Notes:
1 - "let-row" => each rowData of the Grid (in this case would be this.data[i])
2 - "let-context="params" => it's the context that we assigned to the Grid in order to pass it variables. In this case we set a variable in Context called "availableStatus":
availableStatus: WorkflowStatus[] = [
{
workflowStatusId: 1,
name: 'InDesign',
description: 'In Design'
},
{
workflowStatusId: 3,
name: 'SourceReviewed',
description: 'Source Reviewed'
},
{
workflowStatusId: 5,
name: 'Translated',
description: 'Translated'
},
];
ngOnInit() {
....
this.gridContext = {
availableStatus: this.availableStatus,
};
}