Unplanned
Last Updated: 30 Sep 2025 09:27 by Thomas
Thomas
Created on: 23 Sep 2025 16:33
Category: PivotGrid
Type: Feature Request
2
PivotGrid enable specific comparer to order rows/columns

It would be nice to be able to customize the comparer used to display data in a specific order.

I think by default it uses a simple alphabetic comparison

But we have a lot of data using alpha and numeric information like:

  • Label1
  • Label2
  • ...
  • Label100

And the user wants data in the numeric order, so we often implement our own comparer everywhere for it to work.

The PivotGrid doesn't seem to provide a way to customize the order of data even with a provider Local, ordering the source in a specific way before giving it to the component doesn't work either.

Thanks
Thomas

2 comments
Thomas
Posted on: 30 Sep 2025 09:27

Hello,

Thanks for your answer.

I see what you want to do, it should be doable indeed like this, I'll try it thank you.

Regards,

Thomas

ADMIN
Dimo
Posted on: 30 Sep 2025 08:18

Hi Thomas,

I am confirming this feature request and marking it as "Unplanned". In the meantime, a possible workaround is to:

  • Prepend a string to the row/column headers, so that the PivotGrid sorts them in the desired order.
  • Remove the prepended strings in a ColumnHeaderTemplate and RowHeaderTemplate.

The following example sorts all row and column headers in a descending order. This is a built-in feature, but shows the idea for a more complex sorting scenario.

<TelerikPivotGridContainer>

    <TelerikPivotGridConfigurator />

    <TelerikPivotGridConfiguratorButton />

    <TelerikPivotGrid Data="@PivotData"
                      DataProviderType="@PivotGridDataProviderType.Local"
                      ColumnHeadersWidth="160px">
        <PivotGridColumns>
            <PivotGridColumn Name="@nameof(PivotModel.Country)" Title="Country" />
            <PivotGridColumn Name="@nameof(PivotModel.City)" Title="City" />
        </PivotGridColumns>
        <PivotGridRows>
            <PivotGridRow Name="@nameof(PivotModel.Category)" Title="Category" />
            <PivotGridRow Name="@nameof(PivotModel.Product)" Title="Product" />
        </PivotGridRows>
        <PivotGridMeasures>
            <PivotGridMeasure Name="@nameof(PivotModel.ContractValue)"
                              Title="Contract Value"
                              Aggregate="@PivotGridAggregateType.Sum" />
        </PivotGridMeasures>
        <ColumnHeaderTemplate>
            @{
                var ctx = (PivotGridColumnHeaderTemplateContext)context;
                int underscoreIndex = ctx.Text.IndexOf("_");
                string text = ctx.Text;
                if (underscoreIndex > 0)
                {
                    text = text.Replace(text.Substring(0, underscoreIndex + 1), "");
                    <span>@text</span>
                }
                else
                {
                    <span>@ctx.Text</span>
                }
            }
        </ColumnHeaderTemplate>
        <RowHeaderTemplate>
            @{
                var ctx = (PivotGridRowHeaderTemplateContext)context;
                int underscoreIndex = ctx.Text.IndexOf("_");
                string text = ctx.Text;
                if (underscoreIndex > 0)
                {
                    text = text.Replace(text.Substring(0, underscoreIndex + 1), "");
                    <span>@text</span>
                }
                else
                {
                    <span>@ctx.Text</span>
                }
            }
        </RowHeaderTemplate>
    </TelerikPivotGrid>

</TelerikPivotGridContainer>

@code {
    private List<PivotModel> PivotData { get; set; } = new();

    protected override void OnInitialized()
    {
        var dataItemCount = 100;
        var categoryCount = 3;
        var productCount = 10 + 1;
        var countryCount = 2;
        var cityCount = 4 + 1;
        var rnd = Random.Shared;

        for (int i = 1; i <= dataItemCount; i++)
        {
            var productNumber = Random.Shared.Next(1, productCount);
            var categoryNumber = productNumber % categoryCount + 1;
            var cityNumber = rnd.Next(1, cityCount);
            var countryNumber = cityNumber % countryCount + 1;

            PivotData.Add(new PivotModel()
            {
                Category = $"{100 - categoryNumber}_Category {categoryNumber}",
                Product = $"{100 - productNumber}_Product {productNumber}",
                Country = $"{100 - countryNumber}_Country {countryNumber}",
                City = $"{100 - cityNumber}_City {cityNumber}",
                ContractDate = DateTime.Now.AddDays(-rnd.Next(1, 31)).AddMonths(-rnd.Next(1, 12)).AddYears(-rnd.Next(0, 5)),
                ContractValue = (productNumber == 3 || cityNumber == 2 || categoryNumber == 1) ? 0 : rnd.Next(123, 987)
            });
        }

        base.OnInitialized();
    }

    public class PivotModel
    {
        public string Category { get; set; } = string.Empty;
        public string Product { get; set; } = string.Empty;
        public string Country { get; set; } = string.Empty;
        public string City { get; set; } = string.Empty;
        public DateTime ContractDate { get; set; }
        public decimal ContractValue { get; set; }
    }
}

 

Regards,
Dimo
Progress Telerik

Your perspective matters! Join other professionals in the State of Designer-Developer Collaboration 2025: Workflows, Trends and AI survey to share how AI and new workflows are impacting collaboration, and be among the first to see the key findings.
Start the 2025 Survey