This is a migrated thread and some comments may be shown as answers.

Display text in cells?

1 Answer 122 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
jen
Top achievements
Rank 1
jen asked on 05 Jan 2017, 04:36 PM

Is it possible to display text values in the cells or does it have to be numerical only? I don't need any totals or aggregates. I have managed to get the control to display my rows and columns correctly, but I'm not sure how to get it to display the values I need since they are text values.

I want to use this control because I don't know how many columns I will need and its much simpler to matrix my data and let the control figure it out. I could achieve the same results with a GridView, manually adding columns and using a converter to find the correct values, but it would be MUCH simpler to use a PivotGrid.

I have attached an image of what I'm trying to display. My class and data are below.

public class SettingCompareMatrix : IComparable<SettingCompareMatrix>
{
    public int SettingGroupIndex { get; set; }
    public string SettingGroup { get; set; }
    public int SettingIndex { get; set; }
    public string SettingName { get; set; }
    public string Name { get; set; }
    public string Value { get; set; }

    //For sorting the rows, instead of by alphebetical order. Another issue to figure out!
    public int CompareTo(SettingCompareMatrix other)
    {
        if (this.SettingGroupIndex > other.SettingGroupIndex)
            return 1;
        else if (this.SettingGroupIndex < other.SettingGroupIndex)
            return -1;
        else
        {
            if (this.SettingIndex > other.SettingIndex)
                return 1;
            else if (this.SettingIndex < other.SettingIndex)
                return -1;
            else
                return 0;
        }
           
    }
}

private List<SettingCompareMatrix> GeneratePivotData()
{
    return new List<SettingCompareMatrix>()
    {
        new SettingCompareMatrix() { SettingGroupIndex = 0, SettingGroup="Store", SettingIndex=0, SettingName="Create Store", Name="Store 1", Value="True" },
        new SettingCompareMatrix() { SettingGroupIndex = 0, SettingGroup="Store", SettingIndex=0, SettingName="Create Store", Name="Store 2", Value="False" },
        new SettingCompareMatrix() { SettingGroupIndex = 0, SettingGroup="Store", SettingIndex=1, SettingName="Information", Name="Store 1", Value="Modify" },
        new SettingCompareMatrix() { SettingGroupIndex = 0, SettingGroup="Store", SettingIndex=1, SettingName="Information", Name="Store 2", Value="Display" },
        new SettingCompareMatrix() { SettingGroupIndex = 1, SettingGroup="Categories", SettingIndex=0, SettingName="Category", Name="Store 1", Value="Add" },
        new SettingCompareMatrix() { SettingGroupIndex = 1, SettingGroup="Categories", SettingIndex=0, SettingName="Category", Name="Store 2", Value="Display" },
        new SettingCompareMatrix() { SettingGroupIndex = 2, SettingGroup="Supplier", SettingIndex=0, SettingName="Information", Name="Store 1", Value="Display" },
        new SettingCompareMatrix() { SettingGroupIndex = 2, SettingGroup="Supplier", SettingIndex=0, SettingName="Information", Name="Store 2", Value="Add" },
        new SettingCompareMatrix() { SettingGroupIndex = 2, SettingGroup="Supplier", SettingIndex=1, SettingName="Settings Price Matrix", Name="Store 1", Value="Add" },
        new SettingCompareMatrix() { SettingGroupIndex = 2, SettingGroup="Supplier", SettingIndex=1, SettingName="Settings Price Matrix", Name="Store 2", Value="Display" },
    };
}

<pivot:LocalDataSourceProvider x:Key="LocalDataProvider" AggregatesPosition="Rows" >
    <pivot:LocalDataSourceProvider.RowGroupDescriptions>
        <pivot:PropertyGroupDescription PropertyName="SettingGroup" />
        <pivot:PropertyGroupDescription PropertyName="SettingName" />
    </pivot:LocalDataSourceProvider.RowGroupDescriptions>
    <pivot:LocalDataSourceProvider.ColumnGroupDescriptions>
        <pivot:PropertyGroupDescription PropertyName="Name" />
    </pivot:LocalDataSourceProvider.ColumnGroupDescriptions>
    <pivot:LocalDataSourceProvider.AggregateDescriptions>
        <pivot:PropertyAggregateDescription PropertyName="Value"/>
    </pivot:LocalDataSourceProvider.AggregateDescriptions>
</pivot:LocalDataSourceProvider>

<pivot:RadPivotGrid Grid.Row="1" DataProvider="{StaticResource LocalDataProvider}"
                    ColumnGrandTotalsPosition="None" ColumnSubTotalsPosition="None"
                    RowGrandTotalsPosition="None"  RowSubTotalsPosition="None" />

1 Answer, 1 is accepted

Sort by
0
Polya
Telerik team
answered on 10 Jan 2017, 12:32 PM
Hello Jen,

By design the RadPivotGrid is control used for data summarization and aggregation of a provided data and does not display the data itself (like the RadGridView). So one cell might represent the aggregated value of 10-15 records from the ItemsSource after the data is grouped. That said, I believe that the RadGridView control is more suitable for your scenario.

If you wish to change the aggregate cells of the RadPivotGrid you can use CellTemplateSelector. In the CellTemplateSelector you can get different information about the cell (row, column, parent cells, PropertyAggregateDescription name) and depending on them to apply different templates. You can check the CustomCellTemplate example from our developer focused examples which demonstrates actual usage of the CellTemplateSelector.

Hope this helps.

Regards,
Polya
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
PivotGrid
Asked by
jen
Top achievements
Rank 1
Answers by
Polya
Telerik team
Share this question
or