DevExtreme Angular - Customize Group Headers
By default, group headers contain the text of the key field in a bold font. You can define a custom template for group headers if you need to. For AngularJS and Knockout apps, DevExtreme provides the dxTemplate markup component. The following code shows how to use dxTemplate to define a template for group headers.
If you use jQuery alone, use DOM manipulation methods to combine the HTML markup for group headers. To apply this markup, use the groupTemplate callback function as shown in the following code.
- var fruitsVegetables = [{
- // ...
- // omitted for brevity
- // see the AngularJS code
- }];
- $(function() {
- $("#listContainer").dxList({
- dataSource: new DevExpress.data.DataSource({
- store: fruitsVegetables,
- map: function(groupedItem) {
- var overallCount = 0;
- groupedItem.items.forEach(function(item) {
- overallCount += item.count;
- });
- return $.extend(groupedItem, { overallCount: overallCount })
- }
- }),
- grouped: true,
- groupTemplate: function(groupData, _, groupElement) {
- groupElement.append(
- $("<p>").text(groupData.key + " | " + groupData.overallCount)
- )
- },
- itemTemplate: function(data, _, element) {
- element.append(
- $("<p>").text(data.name + " | " + data.count).css("margin", 0)
- )
- }
- });
- });
In addition, you can use a 3rd-party template engine to perform the needed customizations. For more information, see the 3rd-Party Template Engines article.
See Also
If you have technical questions, please create a support ticket in the DevExpress Support Center.