Articles in this section
Category / Section

How to customize pivot table headers

3 mins read

This article explains how to customize Blazor Pivot Table headers

Customize pivot table headers

In some scenarios, it may be necessary to customize the row and column headers of the pivot table by incorporating additional data from the data source. This can be achieved by using the CellTemplate option.

The following code demonstrates how to retrieve relevant cell data information from the data source based on the data Index and customize row headers by concatenating the retrieved data with the current data. For example, here, we obtain the Country field from the relevant data and add it along with the ProductID field on the row axis.

Note: In order to obtain specific cell’s data information from the data source while using the cell template, it is important to set the AllowDrillThrough property to true.

Index.razor

<SfPivotView TValue="PivotVirtualData" Width="100%" Height="500" EnableVirtualization="true" AllowDrillThrough="true">
    <PivotViewTemplates>
        <CellTemplate>
            @{
                var data = (context as AxisSet);
                if (data != null)
                {
                    if (data.Axis == "row" && data.Type != "grand sum")
                    {
                        data.FormattedText = data.FormattedText + "-" + Data[data.Index[0]].Country;
                        @data.FormattedText
                    }
                    else
                    {
                        @data.FormattedText
                    }
                }
            }
        </CellTemplate>
    </PivotViewTemplates>
    <PivotViewDataSourceSettings DataSource="@Data" EnableSorting="false">
    </PivotViewDataSourceSettings>
</SfPivotView>

The following screenshot portrays the results of the code snippet mentioned above.

Screenshot

custom-format.png

For a practical demonstration, refer to the sample of blazor playground

Conclusion:

I hope you enjoyed learning how to customize pivot table headers.

You can also refer to our Pivot Table feature tour feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Pivot Table example example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied