Group Row Title Customization in Vue Grid
The Vue Data 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 receives a data object with properties such as field, headerText, key, and count, which can be used to dynamically render informative group captions.
The following example illustrates displaying the headerText, key, and count within a customized group caption.
<template>
<div id="app">
<ejs-grid :dataSource='data' :allowGrouping='true' :groupSettings='groupOptions' height='300px'>
<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>
</div>
</template>
<script setup>
import { provide } from "vue";
import { GridComponent as EjsGrid, ColumnDirective as EColumn, ColumnsDirective as EColumns, Group } from "@syncfusion/ej2-vue-grids";
import { data } from './datasource.js';
const groupOptions = { columns: ['CustomerID', 'ShipCity'], captionTemplate: captionTemplate };
const captionTemplate = '<span class="groupItems"> ${headerText} - ${key } : ${count} Items </span>';
provide('grid', [Group]);
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/material3.css";
</style><template>
<div id="app">
<ejs-grid :dataSource='data' :allowGrouping='true' :groupSettings='groupOptions' height='300px'>
<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>
</div>
</template>
<script>
import { GridComponent, ColumnsDirective, ColumnDirective, Group } from "@syncfusion/ej2-vue-grids";
import { data } from './datasource.js';
export default {
name: "App",
components: {
"ejs-grid":GridComponent,
"e-columns":ColumnsDirective,
"e-column":ColumnDirective
},
data() {
return {
data: data,
groupOptions: { columns: ['CustomerID', 'ShipCity'],
captionTemplate: '<span class="groupItems"> ${headerText} - ${key } : ${count} Items </span>' }
};
},
provide: {
grid: [Group]
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/material3.css";
</style>Adding custom text in group caption
The Vue Data 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.
<template>
<div id="app">
<ejs-grid :dataSource='data' :allowGrouping='true' :groupSettings='groupOptions' height='267px'>
<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>
</ejs-grid>
</div>
</template>
<script setup>
import { provide } from "vue";
import { GridComponent as EjsGrid, ColumnDirective as EColumn, ColumnsDirective as EColumns, Group } from "@syncfusion/ej2-vue-grids";
import { data } from './datasource.js';
const groupOptions = { columns: ['CustomerID'], captionTemplate: captionTemplate };
const captionTemplate = '<span class="groupItems"> ${key } - ${count } Records : ${headerText} </span>';
provide('grid', [Group]);
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/material3.css";
</style><template>
<div id="app">
<ejs-grid :dataSource='data' :allowGrouping='true' :groupSettings='groupOptions' height='267px'>
<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>
</ejs-grid>
</div>
</template>
<script>
import { GridComponent, ColumnsDirective, ColumnDirective, Group } from "@syncfusion/ej2-vue-grids";
import { data } from './datasource.js';
export default {
name: "App",
components: {
"ejs-grid":GridComponent,
"e-columns":ColumnsDirective,
"e-column":ColumnDirective
},
data() {
return {
data: data,
groupOptions: { columns: ['CustomerID'],
captionTemplate: '<span class="groupItems"> ${key } - ${count } Records : ${headerText} </span>' }
};
},
provide: {
grid: [Group]
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/material3.css";
</style>Customize group caption text using locale
The Vue Data 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.
<template>
<div id="app">
<ejs-grid :dataSource='data' :allowGrouping='true' height='300px'>
<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>
</div>
</template>
<script setup>
import { provide } from "vue";
import { L10n, setCulture } from '@syncfusion/ej2-base';
import { GridComponent as EjsGrid, ColumnDirective as EColumn, ColumnsDirective as EColumns, Group } from "@syncfusion/ej2-vue-grids";
import { data } from './datasource.js';
setCulture('ar');
L10n.load({
ar: {
grid: {
GroupDropArea: 'اسحب رأس العمود هنا لتجميع العمود',
Item: 'بند',
Items: 'العناصر',
GroupCaption: ' هي خلية تسمية توضيحية جماعية',
},
},
});
provide('grid', [Group]);
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/material3.css";
</style><template>
<div id="app">
<ejs-grid :dataSource='data' :allowGrouping='true' height='300px'>
<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>
</div>
</template>
<script>
import { L10n, setCulture } from '@syncfusion/ej2-base';
import { GridComponent, ColumnsDirective, ColumnDirective, Group } from "@syncfusion/ej2-vue-grids";
import { data } from './datasource.js';
setCulture('ar');
L10n.load({
ar: {
grid: {
GroupDropArea: 'اسحب رأس العمود هنا لتجميع العمود',
Item: 'بند',
Items: 'العناصر',
GroupCaption: ' هي خلية تسمية توضيحية جماعية',
},
},
});
export default {
name: "App",
components: {
"ejs-grid":GridComponent,
"e-columns":ColumnsDirective,
"e-column":ColumnDirective
},
data() {
return {
data: data,
};
},
provide: {
grid: [Group]
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/material3.css";
</style>Render custom component in group caption
The Vue Data 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.
<template>
<div id="app">
<ejs-grid :dataSource='data' :allowGrouping='true' :groupSettings='groupOptions'
:dataBound='dataBound' height='300px'>
<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>
</ejs-grid>
</div>
</template>
<script setup>
import { provide } from "vue";
import { GridComponent as EjsGrid, ColumnDirective as EColumn, ColumnsDirective as EColumns, Group } from "@syncfusion/ej2-vue-grids";
import { ChipList } from '@syncfusion/ej2-buttons';
import { data } from './datasource.js';
const groupOptions = { columns: ['CustomerID'], captionTemplate: captionTemplate };
const captionTemplate = '<div class="groupChip">${key}</div>';
const dataBound = () => {
var groupCaptions = document.getElementsByClassName('groupChip');
for (var i = 0; i < groupCaptions.length; i++) {
let chip = new ChipList({});
chip.appendTo(groupCaptions[i]);
}
}
provide('grid', [Group]);
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/material3.css";
</style><template>
<div id="app">
<ejs-grid :dataSource='data' :allowGrouping='true' :groupSettings='groupOptions'
:dataBound='dataBound' height='300px'>
<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>
</ejs-grid>
</div>
</template>
<script>
import { GridComponent, ColumnsDirective, ColumnDirective, Group } from "@syncfusion/ej2-vue-grids";
import { ChipList } from '@syncfusion/ej2-buttons';
import { data } from './datasource.js';
export default {
name: "App",
components: {
"ejs-grid":GridComponent,
"e-columns":ColumnsDirective,
"e-column":ColumnDirective
},
data() {
return {
data: data,
groupOptions: { columns: ['CustomerID'],
captionTemplate: '<div class="groupChip">${key}</div>' }
};
},
methods: {
dataBound(){
var groupCaptions = document.getElementsByClassName('groupChip');
for (var i = 0; i < groupCaptions.length; i++) {
let chip = new ChipList({});
chip.appendTo(groupCaptions[i]);
}
}
},
provide: {
grid: [Group]
}
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-base/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-buttons/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-calendars/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-dropdowns/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-inputs/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-navigations/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-popups/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-splitbuttons/styles/material3.css";
@import "../node_modules/@syncfusion/ej2-vue-grids/styles/material3.css";
</style>