Angular Data GridCustom Components

You can create your own Custom Components to customise the behaviour of the grid. For example you can customise how cells are rendered, how values are edited and also create your own filters.

Angular Custom Components thumbnail

The full list of component types you can provide in the grid are as follows:

The remainder of this page gives information that is common across all the component types.

Registering Custom Components

There are two ways to register custom components:

  • Direct reference.
  • By name.

1. By Direct Reference

When registering an Angular Component by reference you simply pass the Component to the place you want it used (i.e. Cell Renderer, Filter etc).

In this example we're specifying that we want our Angular CubeComponent as a Cell Renderer in the Cube column:

//...other imports
import { Component } from '@angular/core';
import { CubeComponent } from './cube.component';

@Component({
selector: 'app-root',
template: `
  <ag-grid-angular [columnDefs]="columnDefs"
                   ...other properties />
`
})
export class AppComponent {
  columnDefs: [
      {
          field: "cube",
          cellRenderer: CubeComponent,     
      }
  ]

  //...other properties & methods
}

The advantage of referencing Components directly is cleaner code, without the extra level of indirection added when referencing by name.

2. By Name

When registering an Angular component by name you need to first register the component within the grid components property, then reference the component by name where you want it used (i.e. as a Cell Renderer, Filter etc).

In this example we've registered our Angular CubeComponent and given it a name of cubeComponent (this can be any name you choose). We then specify that we want the previously registered cubeComponent to be used as a Cell Renderer in the Cube column:

//...other imports
import { Component } from '@angular/core';
import { CubeComponent } from './cube.component';

@Component({
selector: 'app-root',
template: `
  <ag-grid-angular [columnDefs]="columnDefs" [components]="components"
                   ...other properties />
`
})
export class AppComponent {
  components = {
      'cubeComponent': CubeComponent
  };          
  columnDefs = [
      {
          field: "cube",
          cellRenderer: 'cubeComponent',     
      }
  ]

  //...other properties & methods
}

The advantage of referencing components by name is definitions (eg Column Definitions) can be composed of simple types (ie JSON), which is useful should you wish to persist Column Definitions.

Providing Additional Parameters

Each Custom Component gets a set of parameters from the grid. For example, for Cell Component the grid provides, among other things, the value to be rendered. You can provide additional properties to the Custom Component (e.g. what currency symbol to use) by providing additional parameters specific to your application.

To provide additional parameters, use the property [prop-name]Params, e.g. cellRendererParams.

<ag-grid-angular
    [columnDefs]="columnDefs"
    /* other grid options ... */ />

this.columnDefs = [
    { 
        field: 'price',
        cellRenderer: PriceCellRenderer,
        cellRendererParams: {
            currency: 'EUR'
        }
    },
];

Component Lifecycle Hook agInit

Each custom Angular component must implement the agInit(params) lifecycle hook. AgInit is called by AG Grid before any of the Angular Lifecycle hooks, including ngOnInit. This order is deterministic and applies to all component types.

Mixing JavaScript and Angular

When providing Custom Components you have a choice of the following:

  1. Provide an AG Grid component as an Angular Component.
  2. Provide an AG Grid component in JavaScript.

The following code snippet shows how both JavaScript and Angular Components can be used at the same time:

//...other imports
import { Component } from '@angular/core';
import JavascriptComponent from './JavascriptComponent.js';
import { AngularComponent }  from './angular.component';

@Component({
selector: 'app-root',
template: `
  <ag-grid-angular [columnDefs]="columnDefs" [components]="components"
                   ...other properties />
`
})
export class AppComponent {
  // JS and Angular components, only need register if looking up by name
  components = {
      'javascriptComponent': JavascriptComponent,
      'angularComponent': AngularComponent
  };
  columnDefs = [
      {
          headerName: "JS Cell",
          field: "value",
          cellRenderer: 'javascriptComponent', // JS comp by Name
      },
      {
          headerName: "JS Cell",
          field: "value",
          cellRenderer: JavascriptComponent, // JS comp by Direct Reference
      },
      {
          headerName: "Angular Cell",
          field: "value",
          cellRenderer: 'angularComponent', // Angular comp by Name
      },
      {
          headerName: "Angular Cell",
          field: "value",
          cellRenderer: AngularComponent, // Angular comp by Direct Reference
      }
  ];

  //...other properties & methods
}

Javascript components are run outside of NgZone. If they initiate calls into your Angular application you may need to wrap these calls within ngZone.run() for Change Detection to correctly run.

Change the documentation view to JavaScript to see how to create a plain JavaScript component.

Child to Parent Communication

There are a variety of ways to manage component communication in Angular (shared service, local variables etc), but you often need a simple way to let a "parent" component know that something has happened on a "child" component. In this case the simplest route is to use the Grid's context feature to hold a reference to the parent, which the child can then access.

//...other imports
import {Component} from '@angular/core';
import {ICellRendererAngularComp} from 'ag-grid-angular';
import {CubeComponent} from './cube.component';

@Component({
  selector: 'app-root',
  template: `
      <ag-grid-angular [context]="context" /* ...other properties */ />
  `
})
export class AppComponent {
  constructor() {
      this.context = {
          componentParent: this
      }
  }

  parentMethod() {
      // do something
  }
  //...other properties & methods
}

@Component({
  selector: 'cell-renderer',
  template: `
      ...component template...
  `
})
export class CellRendererComponent implements ICellRendererAngularComp {
  params: any;
  componentParent: any;

  agInit(params) {
      this.params = params;
      this.componentParent = this.params.context.componentParent;
      // the grid component can now be accessed - for example: this.componentParent.parentMethod()
  }

  //...other properties & methods
}

Note that although we've used componentParent as the property name here it can be anything - the main point is that you can use the context mechanism to share information between the components.

Component Usage

The below table gives a summary of the components, where they are configured and using what attribute.

ComponentWhereAttribute
Cell ComponentColumn DefinitioncellRenderer
cellRendererParams
cellRendererSelector
Editor ComponentColumn DefinitioncellEditor
cellEditorParams
cellEditorSelector
FilterColumn Definitionfilter
filterParams
Floating FilterColumn DefinitionfloatingFilter
floatingFilterParams
Header ComponentColumn DefinitionheaderComponent
headerComponentParams
Inner Header ComponentColumn DefinitioninnerHeaderComponent
innerHeaderComponentParams
Header Group ComponentColumn DefinitionheaderGroupComponent
headerGroupComponentParams
Inner Header Group ComponentColumn DefinitioninnerHeaderGroupComponent
innerHeaderGroupComponentParams
Tooltip ComponentColumn DefinitiontooltipComponent
tooltipComponentParams
Group Row Cell ComponentGrid OptiongroupRowRenderer
groupRowRendererParams
Group Row Inner Cell ComponentGrid OptioninnerRenderer
innerRendererParams
Detail Cell ComponentGrid OptiondetailCellRenderer
detailCellRendererParams
Full Width Cell ComponentGrid OptionfullWidthCellRenderer
fullWidthCellRendererParams
Loading Cell ComponentGrid Option
Column Definition
loadingCellRenderer
loadingCellRendererParams
Loading OverlayGrid OptionloadingOverlayComponent
loadingOverlayComponentParams
No Rows OverlayGrid OptionnoRowsOverlayComponent
noRowsOverlayComponentParams
Drag and Drop ImageGrid OptiondragAndDropImageComponent
dragAndDropImageComponentParams
Date ComponentGrid OptiondateComponent
dateComponentParams
Status Bar ComponentGrid Option -> Status BarstatusPanel
statusPanelParams
Tool PanelGrid Option -> Side BartoolPanel
toolPanelParams
Menu ItemGrid Option -> MenumenuItem
menuItemParams

Grid Provided Components

The grid comes with pre-registered components that can be used. Each component provided by the grid starts with the namespaces 'ag' to minimise naming conflicts with user provided components. The full list of grid provided components are in the table below.

Drag And Drop
agDragAndDropImageDefault cover element when grid parts are being dragged
Date Inputs
agDateInputDefault date input used by filters
Column Headers
agColumnHeaderDefault column header
agColumnHeaderGroupDefault column group header
Column Filters
agSetColumnFilter (e)Set filter (default when using AG Grid Enterprise)
agTextColumnFilterSimple text filter (default when using AG Grid Community)
agNumberColumnFilterNumber filter
agDateColumnFilterDate filter
agMultiColumnFilter (e)Multi filter
agGroupColumnFilter (e)Group column filter
Floating Filters
agSetColumnFloatingFilter (e)Floating set filter
agTextColumnFloatingFilterFloating text filter
agNumberColumnFloatingFilterFloating number filter
agDateColumnFloatingFilterFloating date filter
agMultiColumnFloatingFilter (e)Floating multi filter
agGroupColumnFloatingFilter (e)Floating group column filter
Cell Components
agAnimateShowChangeCellRendererCell Component that animates value changes
agAnimateSlideCellRendererCell Component that animates value changes
agGroupCellRendererCell Component for displaying group information
agLoadingCellRenderer (e)Cell Component for loading row when using Enterprise row model
agSkeletonCellRenderer (e)Cell Component for displaying skeleton cells
agCheckboxCellRendererCell Component that displays a checkbox for boolean values
Overlays
agLoadingOverlayLoading overlay
agNoRowsOverlayNo rows overlay
Cell Editors
agTextCellEditorText cell editor
agSelectCellEditorSelect cell editor
agRichSelectCellEditor (e)Rich select editor
agLargeTextCellEditorLarge text cell editor
agNumberCellEditorNumber cell editor
agDateCellEditorDate cell editor
agDateStringCellEditorDate represented as string cell editor
agCheckboxCellEditorCheckbox cell editor
Master Detail
agDetailCellRenderer (e)Detail panel for master / detail grid
Column Menu / Context Menu
agMenuItem (e)Menu item within column or context menu

Overriding Grid Components

It is also possible to override components. Where the grid uses a default value, this means the override component will be used instead. The default components, where overriding makes sense, are as follows:

  • agDragAndDropImage: To change the default drag and drop image when dragging grid parts.
  • agDateInput: To change the default date selection across all filters.
  • agColumnHeader: To change the default column header across all columns.
  • agColumnGroupHeader: To change the default column group header across all columns.
  • agLoadingCellRenderer: To change the default loading cell renderer for Enterprise Row Model.
  • agSkeletonCellRenderer: To change the default skeleton loading cell renderer for Enterprise Row Model.
  • agLoadingOverlay: To change the default 'loading' overlay.
  • agNoRowsOverlay: To change the default 'no rows' overlay.
  • agCellEditor: To change the default cell editor.
  • agDetailCellRenderer: To change the default detail panel for master / detail grids.
  • agMenuItem: To change the default menu item for column and context menus.

To override the default component, register the custom component in the GridOptions components property under the above name.

@Component({
    selector: 'my-app',
    template: `
        <ag-grid-angular
            [components]="components"
            ...other properties...  
        />
    `
})
export class AppComponent {
    // Here is where we specify the components to be used instead of the default
    public components = {
        agDateInput: CustomDateComponent,
        agColumnHeader: CustomHeaderComponent
    };