Formatting Pivot Table Column Headers

In my dataset for a pivot table I have four fields for drill down columns (Year, Quarter, Month, Week). Those fields hold an integer to represent the year, quarter, month and week respectively.

How can I bind a formatter to the column headers? E.g. to show the month as JAN, FEB, etc?

I tried "Caption" in <PivotViewColumn> but I don't have a context and if I bind a function that returns a string, that string is never rendered

I tried <PivotViewFormatSetting> but that doesn't seem to work either

I also tried changing my model class so that it returns already formatted fields. But then I'm losing sortability (February showing up before January)


1 Reply

AP AngelinFaithSheeba PaulvannanRajadurai Syncfusion Team May 5, 2022 04:08 PM UTC

Hi Matthew,


To sort number field by month, please covert the interger type to date type and assign it to the provided data source in the OnInitialized(). Additionally, to show the date in month order in the header, use the format settings for the chosen field. Please see the code below for an example.


Code Example:


protected override void OnInitialized()

    {

        List<ProductDetails> data = ProductDetails.GetProductData().ToList();

        for (int i = 0, count = data.Count; i < count; i++)

        {

            ProductDetails currentData = data[i];

            if (currentData.Month != null)

            {

                int month = Convert.ToInt32(currentData.Month);

                if (month > 0 && month <= 12)

                {

                    currentData.Month = new DateTime(2015, month, 1); // here the month field converted into DateTime format and reassigned to the "object" type field "Month".

                }

            }

        }

        this.dataSource = data;

    }


Meanwhile, we have prepared a sample for your reference.

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/PivotTesting-1469517449


Also, please refer the following documentation for more details about “Formatting”.

Document: Number Formatting in Blazor Pivot Table Component | Syncfusion


Please let us know if you have any concerns.


Regards,

Angelin Faith Sheeba.


Loader.
Up arrow icon