The Rich Select Cell Editor supports cell renderers, value formatting, search and typing behaviour, multi-selection, and complex object values.
Cell Renderer Copy Link
The cell renderer used within the editor can be customised as shown below:
import {
ClientSideRowModelModule,
ColDef,
GridApi,
GridOptions,
IRichCellEditorParams,
ModuleRegistry,
TextEditorModule,
createGrid,
enableDevValidations,
} from "ag-grid-community";
import { RichSelectModule } from "ag-grid-enterprise";
import { colors } from "./colors";
import { ColourCellRenderer } from "./colourCellRenderer";
if (process.env.NODE_ENV !== "production") {
// Enable extended validations only for development
enableDevValidations();
}
ModuleRegistry.registerModules([
TextEditorModule,
ClientSideRowModelModule,
RichSelectModule,
]);
const columnDefs: ColDef[] = [
{
headerName: "Rich Select Editor",
field: "color",
cellRenderer: ColourCellRenderer,
cellEditor: "agRichSelectCellEditor",
cellEditorParams: {
values: colors,
cellRenderer: ColourCellRenderer,
valueListMaxHeight: 220,
} as IRichCellEditorParams,
},
];
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 { color };
});
let gridApi: GridApi;
const gridOptions: GridOptions = {
defaultColDef: {
width: 200,
editable: true,
},
columnDefs: columnDefs,
rowData: data,
};
const gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);
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 type { ICellRendererComp, ICellRendererParams } from 'ag-grid-community';
export class ColourCellRenderer implements ICellRendererComp {
eGui!: HTMLDivElement;
init(params: ICellRendererParams) {
const eGui = (this.eGui = document.createElement('div'));
eGui.style.overflow = 'hidden';
eGui.style.textOverflow = 'ellipsis';
const { value } = params;
const colorSpan = document.createElement('span');
const text = document.createTextNode(value ?? '');
if (value != null) {
colorSpan.style.borderLeft = '10px solid ' + params.value;
colorSpan.style.paddingRight = '5px';
}
eGui.appendChild(colorSpan);
eGui.append(text);
}
getGui() {
return this.eGui;
}
refresh() {
return false;
}
}
<div id="myGrid" style="height: 100%"></div>
columnDefs: [
{
cellEditor: 'agRichSelectCellEditor',
cellRenderer: ColourCellRenderer,
cellEditorParams: {
values: ['AliceBlue', 'AntiqueWhite', 'Aqua', /* .... many colours */ ],
cellRenderer: ColourCellRenderer,
valueListMaxHeight: 220
}
// ...other props
}
]The interface for the Cell Component is as follows:
interface ICellEditorRendererComp {
// Optional - props for rendering.
init?(props: IRichCellEditorRendererParams): void;
// Mandatory - Return the DOM element of the component, this is what the grid puts into the cell
getGui(): HTMLElement;
// Optional - Gets called once by grid after rendering is finished - if your renderer needs to do any cleanup,
// do it here
destroy?(): void;
}The Component is provided props containing, amongst other things, the value to be rendered.
class MyCustomEditorRenderer {
// ...
init(props) {
// create the cell
this.eGui = document.createElement('div');
this.eGui.innerHTML = props.value;
}
// ...
}The provided props (interface IRichCellEditorRendererParams) are:
any |
The value to be rendered by the renderer. May be null — for example on group rows or when the field is absent from the row data; the renderer must handle this. |
The value to be renderer by the renderer formatted by the editor |
Gets the current value of the editor |
Sets the value of the editor |
Used to set a tooltip to the renderer |
The grid api. |
Application context as set on gridOptions.context. |
Search Values Copy Link
Different types of search are possible within the editor list as shown below:
The type of search algorithm that is used when searching for values. match - Matches if the value starts with the text typed. matchAny - Matches if the value contains the text typed. fuzzy - Matches the closest value to text typed. |
import {
ClientSideRowModelModule,
ColDef,
GridApi,
GridOptions,
IRichCellEditorParams,
ModuleRegistry,
TextEditorModule,
createGrid,
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([
TextEditorModule,
ClientSideRowModelModule,
RichSelectModule,
]);
const columnDefs: ColDef[] = [
{
headerName: "Fuzzy Search",
field: "color",
cellEditor: "agRichSelectCellEditor",
cellEditorParams: {
values: colors,
} as IRichCellEditorParams,
},
{
headerName: "Match Search",
field: "color",
cellEditor: "agRichSelectCellEditor",
cellEditorParams: {
values: colors,
searchType: "match",
} as IRichCellEditorParams,
},
{
headerName: "Match Any Search",
field: "color",
cellEditor: "agRichSelectCellEditor",
cellEditorParams: {
values: colors,
searchType: "matchAny",
} as IRichCellEditorParams,
},
];
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 { color };
});
let gridApi: GridApi;
const gridOptions: GridOptions = {
defaultColDef: {
width: 200,
editable: true,
},
columnDefs: columnDefs,
rowData: data,
};
const gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);
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',
];
<div id="myGrid" style="height: 100%"></div>
columnDefs: [
{
cellEditor: 'agRichSelectCellEditor',
cellEditorParams: {
values: ['AliceBlue', 'AntiqueWhite', 'Aqua', /* .... many colours */ ],
searchType: 'match',
}
// ...other props
}
] Allow Typing Copy Link
The editor input can be configured to allow text input, which is used to match different parts of the editor list items as shown below:
Set to true to be able to type values in the display area. |
import {
ClientSideRowModelModule,
ColDef,
GridApi,
GridOptions,
IRichCellEditorParams,
ModuleRegistry,
TextEditorModule,
createGrid,
enableDevValidations,
} from "ag-grid-community";
import { RichSelectModule } from "ag-grid-enterprise";
import { colors } from "./colors";
import { ColourCellRenderer } from "./colourCellRenderer";
if (process.env.NODE_ENV !== "production") {
// Enable extended validations only for development
enableDevValidations();
}
ModuleRegistry.registerModules([
TextEditorModule,
ClientSideRowModelModule,
RichSelectModule,
]);
const columnDefs: ColDef[] = [
{
headerName: "Allow Typing (Match)",
field: "color",
cellRenderer: ColourCellRenderer,
cellEditor: "agRichSelectCellEditor",
cellEditorParams: {
values: colors,
searchType: "match",
allowTyping: true,
filterList: true,
highlightMatch: true,
valueListMaxHeight: 220,
} as IRichCellEditorParams,
},
{
headerName: "Allow Typing (MatchAny)",
field: "color",
cellRenderer: ColourCellRenderer,
cellEditor: "agRichSelectCellEditor",
cellEditorParams: {
values: colors,
searchType: "matchAny",
allowTyping: true,
filterList: true,
highlightMatch: true,
valueListMaxHeight: 220,
} as IRichCellEditorParams,
},
];
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 { color };
});
let gridApi: GridApi;
const gridOptions: GridOptions = {
defaultColDef: {
flex: 1,
editable: true,
},
columnDefs: columnDefs,
rowData: data,
};
const gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);
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 type { ICellRendererComp, ICellRendererParams } from 'ag-grid-community';
export class ColourCellRenderer implements ICellRendererComp {
eGui!: HTMLDivElement;
init(params: ICellRendererParams) {
const eGui = (this.eGui = document.createElement('div'));
eGui.style.overflow = 'hidden';
eGui.style.textOverflow = 'ellipsis';
const { value } = params;
const colorSpan = document.createElement('span');
const text = document.createTextNode(value ?? '');
if (value != null) {
colorSpan.style.borderLeft = '10px solid ' + params.value;
colorSpan.style.paddingRight = '5px';
}
eGui.appendChild(colorSpan);
eGui.append(text);
}
getGui() {
return this.eGui;
}
refresh() {
return false;
}
}
<div id="myGrid" style="height: 100%"></div>
columnDefs: [
{
cellEditor: 'agRichSelectCellEditor',
cellRenderer: ColourCellRenderer,
cellEditorParams: {
values: ['AliceBlue', 'AntiqueWhite', 'Aqua', /* .... many colours */ ],
allowTyping: true,
filterList: true,
highlightMatch: true,
}
// ...other props
}
] Format Values Copy Link
Items in the editor list can be formatted as shown below:
A callback function that allows you to change the displayed value for simple data. The value argument may be null or undefined; the callback must handle this. |
import {
ClientSideRowModelModule,
ColDef,
GridApi,
GridOptions,
IRichCellEditorParams,
ModuleRegistry,
TextEditorModule,
createGrid,
enableDevValidations,
} from "ag-grid-community";
import { RichSelectModule } from "ag-grid-enterprise";
if (process.env.NODE_ENV !== "production") {
// Enable extended validations only for development
enableDevValidations();
}
ModuleRegistry.registerModules([
TextEditorModule,
ClientSideRowModelModule,
RichSelectModule,
]);
const languages = ["English", "Spanish", "French", "Portuguese", "(other)"];
function getRandomNumber(min: number, max: number) {
// min and max included
return Math.floor(window.agRandom() * (max - min + 1) + min);
}
const columnDefs: ColDef[] = [
{
headerName: "Rich Select Editor",
field: "language",
cellEditor: "agRichSelectCellEditor",
cellEditorParams: {
values: languages,
formatValue: (values) => values.toUpperCase(),
} as IRichCellEditorParams,
},
];
let gridApi: GridApi;
const gridOptions: GridOptions = {
defaultColDef: {
width: 200,
editable: true,
},
columnDefs: columnDefs,
rowData: new Array(100)
.fill(null)
.map(() => ({ language: languages[getRandomNumber(0, 4)] })),
};
const gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);
<div id="myGrid" style="height: 100%"></div>
columnDefs: [
{
cellEditor: 'agRichSelectCellEditor',
cellEditorParams: {
values: ['English', 'Spanish', 'French', 'Portuguese', '(other)'],
formatValue: value => value.toUpperCase()
}
// ...other props
}
] Multi Selection Copy Link
The editor can be configured to allow the selection of multiple values as shown below:
If true this component will allow multiple items from the list of values to be selected.
|
When multiSelect=true the editor will automatically show the selected items as "pills". Set this property to true suppress this behaviour.
|
import {
ClientSideRowModelModule,
ColDef,
GridApi,
GridOptions,
IRichCellEditorParams,
ModuleRegistry,
TextEditorModule,
ValueFormatterParams,
ValueParserParams,
createGrid,
enableDevValidations,
} from "ag-grid-community";
import { RichSelectModule } from "ag-grid-enterprise";
import { colors } from "./colors";
import { ColourCellRenderer } from "./colourCellRenderer";
if (process.env.NODE_ENV !== "production") {
// Enable extended validations only for development
enableDevValidations();
}
ModuleRegistry.registerModules([
TextEditorModule,
ClientSideRowModelModule,
RichSelectModule,
]);
const valueFormatter = (params: ValueFormatterParams) => {
const { value } = params;
if (Array.isArray(value)) {
return value.join(", ");
}
return value;
};
const valueParser = (params: ValueParserParams) => {
const { newValue } = params;
if (newValue == null || newValue === "") {
return null;
}
if (Array.isArray(newValue)) {
return newValue;
}
return params.newValue.split(",");
};
type MultiSelectExampleConfig = {
allowTyping: boolean;
suppressMultiSelectPillRenderer: boolean;
useCustomCellRenderer: boolean;
};
const config: MultiSelectExampleConfig = {
allowTyping: false,
suppressMultiSelectPillRenderer: false,
useCustomCellRenderer: false,
};
function getColumnDefs(exampleConfig: MultiSelectExampleConfig): ColDef[] {
const {
allowTyping,
suppressMultiSelectPillRenderer,
useCustomCellRenderer,
} = exampleConfig;
return [
{
headerName: "Colours",
field: "colors",
cellRenderer: useCustomCellRenderer ? ColourCellRenderer : undefined,
cellEditor: "agRichSelectCellEditor",
cellEditorParams: {
values: colors,
cellRenderer: useCustomCellRenderer ? ColourCellRenderer : undefined,
allowTyping,
suppressMultiSelectPillRenderer,
multiSelect: true,
searchType: "matchAny",
filterList: true,
highlightMatch: true,
valueListMaxHeight: 220,
} as IRichCellEditorParams,
},
];
}
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 numberOfOptions = getRandomNumber(1, 4);
const selectedOptions: string[] = [];
for (let i = 0; i < numberOfOptions; i++) {
const color = colors[getRandomNumber(0, colors.length - 1)];
if (selectedOptions.indexOf(color) === -1) {
selectedOptions.push(color);
}
}
selectedOptions.sort();
return { colors: selectedOptions };
});
let gridApi: GridApi;
const gridOptions: GridOptions = {
defaultColDef: {
flex: 1,
editable: true,
valueFormatter: valueFormatter,
valueParser: valueParser,
},
columnDefs: getColumnDefs(config),
rowData: data,
};
function getCheckboxValue(id: string): boolean {
return document.querySelector<HTMLInputElement>(id)?.checked ?? false;
}
function applyExampleConfig(): void {
config.allowTyping = getCheckboxValue("#allow-typing");
config.suppressMultiSelectPillRenderer = getCheckboxValue(
"#suppress-multi-select-pill-renderer",
);
config.useCustomCellRenderer = getCheckboxValue("#custom-cell-renderer");
if (gridApi) {
const activeEdit = gridApi.getEditingCells()[0];
if (activeEdit) {
gridApi.stopEditing();
}
gridApi.setGridOption("columnDefs", getColumnDefs(config));
if (activeEdit) {
requestAnimationFrame(() => {
gridApi.startEditingCell({
rowIndex: activeEdit.rowIndex,
rowPinned: activeEdit.rowPinned,
colKey: "colors",
});
});
}
}
}
const gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);
if (typeof window !== "undefined") {
// Attach external event handlers to window so they can be called from index.html
(<any>window).applyExampleConfig = applyExampleConfig;
}
.controls {
margin-bottom: 10px;
display: flex;
flex-wrap: wrap;
gap: 12px;
align-items: center;
}
.option {
display: flex;
gap: 6px;
align-items: center;
}
.option input[type='text'] {
width: 160px;
}
.grid-wrapper {
display: flex;
flex: 1 1 0px;
}
.grid-wrapper > div {
width: 100%;
height: 100%;
}
.container {
display: flex;
flex-direction: column;
height: 100%;
}
.custom-color-cell-renderer.color-tag {
overflow: 'hidden';
text-overflow: 'ellipsis';
}
.custom-color-cell-renderer.color-tag span {
border-left-width: 10px;
border-left-style: solid;
padding-left: 5px;
}
.ag-picker-field-display .custom-color-cell-renderer.color-pill {
display: flex;
}
.custom-color-cell-renderer.color-pill span {
padding: 0 5px;
border-radius: 5px;
border: 1px solid transparent;
}
.custom-color-cell-renderer.color-pill span:not(:first-child) {
margin-left: 5px;
}
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 type { ICellRendererComp, ICellRendererParams } from 'ag-grid-community';
const createPill = (color: string) => {
const colorSpan = document.createElement('span');
const text = document.createTextNode(color);
colorSpan.style.backgroundColor = `color-mix(in srgb, transparent, ${color} 20%)`;
colorSpan.style.boxShadow = `0 0 0 1px color-mix(in srgb, transparent, ${color} 50%)`;
colorSpan.style.borderColor = color;
colorSpan.append(text);
return colorSpan;
};
const createTag = (color: string) => {
const colorSpan = document.createElement('span');
const text = document.createTextNode(color);
colorSpan.style.borderColor = color;
colorSpan.appendChild(text);
return colorSpan;
};
export class ColourCellRenderer implements ICellRendererComp {
eGui!: HTMLDivElement;
init(params: ICellRendererParams) {
const eGui = (this.eGui = document.createElement('div'));
eGui.classList.add('custom-color-cell-renderer');
const { value } = params;
let values: string[] = [];
if (Array.isArray(value)) {
eGui.classList.add('color-pill');
values = value;
} else {
eGui.classList.add('color-tag');
values = [value];
}
const len = values.length;
for (let i = 0; i < len; i++) {
const currentValue = values[i];
if (currentValue == null || currentValue === '') {
continue;
}
const el = eGui.classList.contains('color-pill') ? createPill(currentValue) : createTag(currentValue);
eGui.appendChild(el);
}
}
getGui() {
return this.eGui;
}
refresh() {
return false;
}
}
<div class="container">
<div class="controls">
<label class="option">
<input id="allow-typing" class="js-rich-select-toggle" onchange="applyExampleConfig()" type="checkbox" />
allowTyping
</label>
<label class="option">
<input
id="suppress-multi-select-pill-renderer"
class="js-rich-select-toggle"
onchange="applyExampleConfig()"
type="checkbox"
/>
suppressMultiSelectPillRenderer
</label>
<label class="option">
<input
id="custom-cell-renderer"
class="js-rich-select-toggle"
onchange="applyExampleConfig()"
type="checkbox"
/>
Custom Cell Renderer
</label>
</div>
<div class="grid-wrapper">
<div id="myGrid"></div>
</div>
</div>
columnDefs: [
{
cellEditor: 'agRichSelectCellEditor',
cellEditorParams: {
values: ['AliceBlue', 'AntiqueWhite', 'Aqua', /* .... many colours */ ],
multiSelect: true,
}
// ...other props
}
] Complex Objects Copy Link
When working with complex objects, a formatValue callback function is required to convert that complex object into a string that can be rendered by the Rich Select Editor. If the Grid Column being edited is not using complex values, or if the Rich Select Editor value object has a different format (different properties) than the object used by the Grid Column, a parseValue callback function is required to convert the editor format into the grid column's format.
A callback function that allows you to change the displayed value for simple data. The value argument may be null or undefined; the callback must handle this. |
A callback function that allows you to convert the value of the Rich Select Editor to the data format of the Grid Column when they are different.
|
When working with Cell Renderers, a formatValue callback should still be provided so it will be possible to use functionality that relies on string values such as allowTyping.
import {
ClientSideRowModelModule,
ColDef,
GridApi,
GridOptions,
IRichCellEditorParams,
ModuleRegistry,
TextEditorModule,
createGrid,
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([
TextEditorModule,
ClientSideRowModelModule,
RichSelectModule,
]);
const columnDefs: ColDef[] = [
{
headerName: "Color (Column as String Type)",
field: "color",
width: 250,
cellEditorParams: {
formatValue: (v) => v.name,
parseValue: (v) => v.name,
values: colors,
searchType: "matchAny",
allowTyping: true,
filterList: true,
valueListMaxHeight: 220,
} as IRichCellEditorParams,
},
{
headerName: "Color (Column as Complex Object)",
field: "detailedColor",
width: 290,
valueFormatter: (p) => `${p.value.name} (${p.value.code})`,
valueParser: (p) => p.newValue,
cellDataType: "object",
cellEditorParams: {
formatValue: (v) => v.name,
values: colors,
searchType: "matchAny",
allowTyping: true,
filterList: true,
valueListMaxHeight: 220,
} as IRichCellEditorParams,
},
];
let gridApi: GridApi;
const gridOptions: GridOptions = {
defaultColDef: {
width: 200,
editable: true,
cellEditor: "agRichSelectCellEditor",
},
columnDefs: columnDefs,
rowData: colors.map((v) => ({ color: v.name, detailedColor: v })),
};
const gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);
export const colors: { name: string; code: string }[] = [
{ name: 'Pink', code: '#FFC0CB' },
{ name: 'Purple', code: '#A020F0' },
{ name: 'Blue', code: '#0000FF' },
{ name: 'Green', code: '#008000' },
];
<div id="myGrid" style="height: 100%"></div>
const colors = [
{ name: "Pink", code: "#FFC0CB" },
// ...other values
];
columnDefs: [
{
cellEditor: 'agRichSelectCellEditor',
valueFormatter: (p) => `${p.value.name} (${p.value.code})`,
valueParser: (p) => p.newValue,
cellDataType: 'object',
cellEditorParams: {
values: colors,
formatValue: (v) => v.name,
}
// ...other props
}
] API Copy Link
Properties available on the IRichCellEditorParams<TData = any, TValue = any, GValue = any> interface.
The list of values to be selected from. Required when valuesPage is not provided. |
Optional paged datasource for very large value lists. When provided, values are loaded incrementally and additional pages are requested as the user scrolls. If both values and valuesPage are set, valuesPage takes precedence.
|
Initial page start row when using valuesPage. Can be a fixed number or a callback that derives the start row from the current editor value. Only applied for the initial, unfiltered load. Filtered searches always start from row 0. |
Number of rows requested per page when using valuesPage. |
Number of rows from the end of the loaded list at which the next page is requested. |
The row height, in pixels, of each value. |
The cell renderer to use to render each value. Cell renderers are useful for rendering rich HTML values, or when processing complex data. |
The custom parameters to be used by the cell render. |
Set to true to be able to type values in the display area. |
If true it will filter the list of values as you type (only relevant when allowTyping=true). |
Set to true to enable asynchronous filtering of values via the values or valuesPage callback. (only relevant when allowTyping=true and filterList=true). |
The type of search algorithm that is used when searching for values. match - Matches if the value starts with the text typed. matchAny - Matches if the value contains the text typed. fuzzy - Matches the closest value to text typed. |
If true, each item on the list of values will highlight the part of the text that matches the input. Note: It only makes sense to use this option when filterList is true and searchType is not fuzzy. |
If true this component will allow multiple items from the list of values to be selected.
|
If true the option to remove all selected options will not be displayed. Note: This feature only works when multiSelect=true.
|
When multiSelect=true the editor will automatically show the selected items as "pills". Set this property to true suppress this behaviour.
|
The value in ms for the search algorithm debounce delay |
A string value to be used when no value has been selected. |
The space in pixels between the value display and the list of items. |
The maximum height of the list of items. If the value is a number it will be treated as pixels, otherwise it should be a valid CSS size string. |
The maximum width of the list of items. If the value is a number it will be treated as pixels, otherwise it should be a valid CSS size string. Default: Width of the cell being edited.
|
A callback function that allows you to change the displayed value for simple data. The value argument may be null or undefined; the callback must handle this. |
A callback function that allows you to convert the value of the Rich Select Editor to the data format of the Grid Column when they are different.
|