The grid comes with some cell editors provided out of the box. These cell editors are listed here.
- Text Cell Editor
- Large Text Cell Editor
- Select Cell Editor
- Rich Select Cell Editor (e)
- Formula Cell Editor (e)
There are also some additional cell editors that are generally used with Cell Data Types:
Example - Provided Cell Editors Copy Link
import { Component } from "@angular/core";
import { AgGridAngular } from "ag-grid-angular";
import {
ClientSideRowModelModule,
ColDef,
ColGroupDef,
GridApi,
GridOptions,
GridReadyEvent,
ILargeTextEditorParams,
IRichCellEditorParams,
ISelectCellEditorParams,
ITextCellEditorParams,
LargeTextEditorModule,
ModuleRegistry,
SelectEditorModule,
TextEditorModule,
enableDevValidations,
} from "ag-grid-community";
import { RichSelectModule } from "ag-grid-enterprise";
import { colors } from "./colors";
if (process.env.NODE_ENV !== "production") {
// Enable extended validations only for development
enableDevValidations();
}
ModuleRegistry.registerModules([
ClientSideRowModelModule,
RichSelectModule,
SelectEditorModule,
TextEditorModule,
LargeTextEditorModule,
]);
import { ColourCellRenderer } from "./colour-cell-renderer.component";
@Component({
selector: "my-app",
standalone: true,
imports: [AgGridAngular, ColourCellRenderer],
template: `<ag-grid-angular
style="width: 100%; height: 100%;"
[columnDefs]="columnDefs"
[defaultColDef]="defaultColDef"
[rowData]="rowData"
/> `,
})
export class AppComponent {
columnDefs: ColDef[] = [
{
headerName: "Text Editor",
field: "color1",
cellRenderer: ColourCellRenderer,
cellEditor: "agTextCellEditor",
cellEditorParams: {
maxLength: 20,
} as ITextCellEditorParams,
},
{
headerName: "Select Editor",
field: "color2",
cellRenderer: ColourCellRenderer,
cellEditor: "agSelectCellEditor",
cellEditorParams: {
values: colors,
} as ISelectCellEditorParams,
},
{
headerName: "Rich Select Editor",
field: "color3",
cellRenderer: ColourCellRenderer,
cellEditor: "agRichSelectCellEditor",
cellEditorParams: {
values: colors,
cellRenderer: ColourCellRenderer,
filterList: true,
searchType: "match",
allowTyping: true,
valueListMaxHeight: 220,
} as IRichCellEditorParams,
},
{
headerName: "Large Text Editor",
field: "description",
cellEditorPopup: true,
cellEditor: "agLargeTextCellEditor",
cellEditorParams: {
maxLength: 250,
rows: 10,
cols: 50,
} as ILargeTextEditorParams,
flex: 2,
},
];
defaultColDef: ColDef = {
flex: 1,
editable: true,
};
rowData: any[] | null = data;
}
function getRandomNumber(min: number, max: number) {
// min and max included
return Math.floor(window.agRandom() * (max - min + 1) + min);
}
const data = Array.from(Array(20).keys()).map(() => {
const color = colors[getRandomNumber(0, colors.length - 1)];
return {
color1: color,
color2: color,
color3: color,
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
};
});
export const colors: string[] = [
'AliceBlue',
'AntiqueWhite',
'Aqua',
'Aquamarine',
'Azure',
'Beige',
'Bisque',
'Black',
'BlanchedAlmond',
'Blue',
'BlueViolet',
'Brown',
'BurlyWood',
'CadetBlue',
'Chartreuse',
'Chocolate',
'Coral',
'CornflowerBlue',
'Cornsilk',
'Crimson',
'Cyan',
'DarkBlue',
'DarkCyan',
'DarkGoldenrod',
'DarkGray',
'DarkGreen',
'DarkGrey',
'DarkKhaki',
'DarkMagenta',
'DarkOliveGreen',
'DarkOrange',
'DarkOrchid',
'DarkRed',
'DarkSalmon',
'DarkSeaGreen',
'DarkSlateBlue',
'DarkSlateGray',
'DarkSlateGrey',
'DarkTurquoise',
'DarkViolet',
'DeepPink',
'DeepSkyBlue',
'DimGray',
'DodgerBlue',
'FireBrick',
'FloralWhite',
'ForestGreen',
'Fuchsia',
'Gainsboro',
'GhostWhite',
'Gold',
'Goldenrod',
'Gray',
'Green',
'GreenYellow',
'Grey',
'Honeydew',
'HotPink',
'IndianRed',
'Indigo',
'Ivory',
'Khaki',
'Lavender',
'LavenderBlush',
'LawnGreen',
'LemonChiffon',
'LightBlue',
'LightCoral',
'LightCyan',
'LightGoldenrodYellow',
'LightGray',
'LightGreen',
'LightGrey',
'LightPink',
'LightSalmon',
'LightSeaGreen',
'LightSkyBlue',
'LightSlateGray',
'LightSlateGrey',
'LightSteelBlue',
'LightYellow',
'Lime',
'LimeGreen',
'Linen',
'Magenta',
'Maroon',
'MediumAquamarine',
'MediumBlue',
'MediumOrchid',
'MediumPurple',
'MediumSeaGreen',
'MediumSlateBlue',
'MediumSpringGreen',
'MediumTurquoise',
'MediumVioletRed',
'MidnightBlue',
'MintCream',
'MistyRose',
'Moccasin',
'NavajoWhite',
'Navy',
'OldLace',
'Olive',
'OliveDrab',
'Orange',
'OrangeRed',
'Orchid',
'PaleGoldenrod',
'PaleGreen',
'PaleTurquoise',
'PaleVioletRed',
'PapayaWhip',
'PeachPuff',
'Peru',
'Pink',
'Plum',
'PowderBlue',
'Purple',
'Rebeccapurple',
'Red',
'RosyBrown',
'RoyalBlue',
'SaddleBrown',
'Salmon',
'SandyBrown',
'SeaGreen',
'Seashell',
'Sienna',
'Silver',
'SkyBlue',
'SlateBlue',
'SlateGray',
'SlateGrey',
'Snow',
'SpringGreen',
'SteelBlue',
'Tan',
'Teal',
'Thistle',
'Tomato',
'Turquoise',
'Violet',
'Wheat',
'White',
'WhiteSmoke',
'Yellow',
'YellowGreen',
];
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import type { ICellRendererAngularComp } from 'ag-grid-angular';
import type { ICellRendererParams } from 'ag-grid-community';
@Component({
standalone: true,
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div [style.overflow]="'hidden'" [style.textOverflow]="'ellipsis'">
<span [style.borderLeft]="'10px solid ' + value()" [style.paddingRight]="'5px'"></span>{{ value() }}
</div>
`,
styles: [
`
:host {
overflow: hidden;
}
`,
],
})
export class ColourCellRenderer implements ICellRendererAngularComp {
value = signal<string>('');
agInit(params: ICellRendererParams): void {
this.value.set(params.value);
}
refresh() {
return false;
}
}
import '@angular/compiler';
import { provideHttpClient } from '@angular/common/http';
import { enableProdMode } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
if (new URLSearchParams(window.location.search).get('prod') !== 'false') {
enableProdMode();
}
const app = bootstrapApplication(AppComponent, {
providers: [provideHttpClient()],
});
Example - Cell Data Types Cell Editors Copy Link
import { Component } from "@angular/core";
import { AgGridAngular } from "ag-grid-angular";
import {
CheckboxEditorModule,
ClientSideRowModelModule,
ColDef,
ColGroupDef,
DateEditorModule,
GridApi,
GridOptions,
GridReadyEvent,
INumberCellEditorParams,
ModuleRegistry,
NumberEditorModule,
ValueFormatterParams,
enableDevValidations,
} from "ag-grid-community";
if (process.env.NODE_ENV !== "production") {
// Enable extended validations only for development
enableDevValidations();
}
ModuleRegistry.registerModules([
ClientSideRowModelModule,
NumberEditorModule,
DateEditorModule,
CheckboxEditorModule,
]);
@Component({
selector: "my-app",
standalone: true,
imports: [AgGridAngular],
template: `<ag-grid-angular
style="width: 100%; height: 100%;"
[columnDefs]="columnDefs"
[defaultColDef]="defaultColDef"
[rowData]="rowData"
/> `,
})
export class AppComponent {
columnDefs: ColDef[] = [
{
headerName: "Number Editor",
field: "number",
cellEditor: "agNumberCellEditor",
cellEditorParams: {
precision: 0,
} as INumberCellEditorParams,
},
{
headerName: "Date Editor",
field: "date",
valueFormatter: (params: ValueFormatterParams<any, Date>) => {
if (!params.value) {
return "";
}
const month = params.value.getMonth() + 1;
const day = params.value.getDate();
return `${params.value.getFullYear()}-${month < 10 ? "0" + month : month}-${day < 10 ? "0" + day : day}`;
},
cellEditor: "agDateCellEditor",
},
{
headerName: "Date as String Editor",
field: "dateString",
cellEditor: "agDateStringCellEditor",
},
{
headerName: "Checkbox Cell Editor",
field: "boolean",
cellEditor: "agCheckboxCellEditor",
},
];
defaultColDef: ColDef = {
flex: 1,
editable: true,
};
rowData: any[] | null = data;
}
const data = Array.from(Array(20).keys()).map((val: any, index: number) => ({
number: index,
date: new Date(2023, 5, index + 1),
dateString: `2023-06-${index < 9 ? "0" + (index + 1) : index + 1}`,
boolean: !!(index % 2),
}));
import '@angular/compiler';
import { provideHttpClient } from '@angular/common/http';
import { enableProdMode } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
if (new URLSearchParams(window.location.search).get('prod') !== 'false') {
enableProdMode();
}
const app = bootstrapApplication(AppComponent, {
providers: [provideHttpClient()],
});