The grid group settings has an option for captionTemplate to customize the group caption in html:
https://ej2.syncfusion.com/vue/documentation/api/grid/groupSettings/#captiontemplate
But how do you customize the group caption when exporting to Excel or PDF? The function
PdfExport.prototype.processGroupedRecords in pdf-export.js has code:
```
var value = this_1.parent.getColumnByField(dataSourceItems.field).headerText + ': ' + (!col.enableGroupByFormat ? this_1.exportValueFormatter.formatCellValue(args) : dataSourceItems.key) + ' - ' + dataSourceItems.count + (dataSource.count > 1 ? ' items' : ' item');
var cArgs = { captionText: value, type: 'PDF' };
```
How do you customize that caption text?
Below is a potential patch to override the formatted group value, although the overall format (i.e., 'HEADERTEXT: FORMATTED_VALUE: N items') is not overridable.
|
<template>
<div id="app">
<ejs-grid
ref="grid"
:dataSource="data"
---
:groupSettings="groupOptions"
:exportGroupCaption="exportGroupCaption"
>
---
</ejs-grid>
</div>
</template>
<script>
Vue.use(GridPlugin);
export default {
data() {
return {
groupOptions: {
captionTemplate: '<span class="groupItems" style="color:blue">${field}: ${key}</span>',
},
};
},
methods: {
exportGroupCaption: function (args) {
// Here you can customize the groupcaption text as per your requirement
args.captionText = args.captionText.split("-")[0].trim();
},
},
};
</script>
|
Hi Rajapandiyan,
Thank you for that information. I hadn't noticed the exportGroupCaption event. However, that event doesn't provide all the arguments I need:
I need the dataSource argument passed into:
This dataSource argument enables access to the rows that are part of that group. The patch in my previous message acquires access to the dataSource. Can you add dataSource to exportGroupCaptionEventArgs?
The use-case os that my custom caption text includes data from associated fields in any of those rows. I can't just make a column that has all of that text and group by it, because the text itself may have duplicates in another groups that I don't want to combine. For example, when grouping by user, the userId column is what is grouped specifically, but want to display userName in the group caption. userName can't be grouped, in case there are two users with the same name. Perhaps if the column definition could contain a groupKey function, then it would alleviate that issue.
|
methods: {
exportGroupCaption: function (args) {
var groupedItemDetail = args.data; // get the grouped item detail
args.captionText = args.captionText.split('-')[0].trim();
}
}
|
Thanks Rajapandiyan. That's very helpful.