How can I help you?
Group Row Title Customization in Angular Grid
19 Mar 202611 minutes to read
The Syncfusion® Angular Grid provides the captionTemplate property to customize the text shown in group row titles. This feature enhances the visual presentation of grouped data by allowing the display of grouped values, record counts, and custom HTML elements such as icons or images.
The captionTemplate property allows for flexible customization. The data parameter within the template provides access to properties such as field (the column’s field name), headerText (column’s header display text), key (grouped value), and count (number of grouped records). These properties provide dynamic values that can be integrated into the caption for context-aware display.
The following example illustrates displaying the headerText, key, and count within a customized group caption.
import { Component, OnInit } from '@angular/core';
import { data } from './datasource';
import { GroupSettingsModel } from '@syncfusion/ej2-angular-grids';
@Component({
selector: 'app-root',
template: `<ejs-grid [dataSource]='data' [allowGrouping]='true' [groupSettings]='groupOptions' height='315px'>
<e-columns>
<e-column field='OrderID' headerText='Order ID' textAlign='Right' width=90></e-column>
<e-column field='CustomerID' headerText='Customer ID' width=100></e-column>
<e-column field='ShipCity' headerText='Ship City' width=100></e-column>
<e-column field='ShipName' headerText='Ship Name' width=120></e-column>
</e-columns>
<ng-template #groupSettingsCaptionTemplate let-data>
<span class="groupItems"> {{ data.headerText }} - {{ data.key }} : {{ data.count }} Items </span>
</ng-template>
</ejs-grid>`
})
export class AppComponent implements OnInit {
public data?: object[];
public groupOptions?: GroupSettingsModel;
ngOnInit(): void {
this.data = data;
this.groupOptions = { showDropArea: false, columns: ['CustomerID', 'ShipCity'] };
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Adding custom text in group caption
The Grid supports adding custom text to group captions through the captionTemplate property. This feature makes group captions more informative by including grouped values, record counts, or descriptive text, and can also display custom HTML elements such as icons or image.
In the example below, the data parameter is used to display the key, count, and headerText of the grouped column, along with custom text within the caption.
import { Component, OnInit } from '@angular/core';
import { data } from './datasource';
@Component({
selector: 'app-root',
template: `<ejs-grid [dataSource]='data' [allowGrouping]='true' height='290px'>
<e-columns>
<e-column field='OrderID' headerText='ID' textAlign='Right' width=90></e-column>
<e-column field='CustomerID' headerText='Name' width=100></e-column>
<e-column field='ShipCity' headerText='City' width=100></e-column>
<e-column field='Freight' headerText='Value' width=80></e-column>
</e-columns>
<ng-template #groupSettingsCaptionTemplate let-data>
<span class="groupItems">{{ data.key }} - {{ data.count }} Records : {{ data.headerText }}</span>
</ng-template>
</ejs-grid>`
})
export class AppComponent implements OnInit {
public data?: object[];
ngOnInit(): void {
this.data = data;
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Customize group caption text using locale
The Grid supports localization of group caption text based on the locale. This enables the display of translated or region-specific content within group captions.
Localization can be achieved using the L10n.load() and setCulture() methods from the @syncfusion/ej2-base package. The L10n.load() method defines localized strings, while setCulture() applies the desired locale to the Grid. The following example demonstrates customizing group caption text for the “ar” (Arabic) locale.
import { data } from './datasource';
import { Component, OnInit } from '@angular/core';
import { GridModule, GroupService } from '@syncfusion/ej2-angular-grids';
import { L10n, setCulture } from '@syncfusion/ej2-base';
L10n.load({
ar: {
grid: {
GroupDropArea: 'اسحب رأس العمود هنا لتجميع العمود',
Item: 'بند',
Items: 'العناصر',
GroupCaption: ' هي خلية تسمية توضيحية جماعية',
},
},
});
setCulture('ar');
@Component({
imports: [GridModule],
providers: [GroupService],
standalone: true,
selector: 'app-root',
template: `<ejs-grid [dataSource]='data' [allowGrouping]='true' height='290px'>
<e-columns>
<e-column field='OrderID' headerText='Order ID' textAlign='Right' width=90></e-column>
<e-column field='CustomerID' headerText='Customer ID' width=100></e-column>
<e-column field='ShipCity' headerText='Ship City' width=100></e-column>
<e-column field='ShipName' headerText='Ship Name' width=120></e-column>
</e-columns>
</ejs-grid>`
})
export class AppComponent implements OnInit {
public data?: object[];
ngOnInit(): void {
this.data = data;
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Render custom component in group caption
The Grid supports rendering custom components within group captions using the captionTemplate property. This functionality enables the integration of interactive UI elements such as buttons, icons, or dropdowns directly within the group caption row, enhancing both functionality and presentation.
In the example below, the Chips component is rendered through the caption template, with its text value dynamically assigned based on the group key.
import { data } from './datasource';
import { Component, OnInit } from '@angular/core';
import { ChipListModule } from '@syncfusion/ej2-angular-buttons';
import { GridModule, GroupService } from '@syncfusion/ej2-angular-grids';
@Component({
imports: [ GridModule, ChipListModule ],
providers: [GroupService],
standalone: true,
selector: 'app-root',
template: `<ejs-grid [dataSource]='data' [allowGrouping]='true' height='290px'>
<e-columns>
<e-column field='OrderID' headerText='ID' textAlign='Right' width=90></e-column>
<e-column field='CustomerID' headerText='Name' width=100></e-column>
<e-column field='ShipCity' headerText='City' width=100></e-column>
<e-column field='Freight' headerText='Value' width=80></e-column>
</e-columns>
<ng-template #groupSettingsCaptionTemplate let-data>
<ejs-chiplist id="chip" [text]="data.key"></ejs-chiplist>
</ng-template>
</ejs-grid>`
})
export class AppComponent implements OnInit {
public data?: object[];
ngOnInit(): void {
this.data = data;
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));