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

How to bind a property which is in the collection to RadPivotgrid CellTemplate

4 Answers 110 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
Ramya
Top achievements
Rank 1
Ramya asked on 01 Jun 2014, 07:57 PM
Hi Team,

Thank you for your continuous support.I have the urgent issue with the Rad Pivot Grid,Please help me out.

Here is the Scenario,I have the Rad Pivot Grid Cell Template Where a Text block is placed i need to set the foreground based on the condition,have used multi binding for it, i need to pass few parameters which are in the collection which is bound to the item source of data provider,how can i access those objects in order to bind it to the foreground, i have browsed for it , where we only bind the data as Text="{Binding Data}",but could not bind any property which is in the collection.How can i do this....
  <DataTemplate x:Key="CellTemplate">
            <TextBlock Margin="6" VerticalAlignment="Center" HorizontalAlignment="Right"  Text="{Binding Data,Mode=OneWay,Converter={StaticResource PpcConverter}}"  FontSize="{Binding Path=FontSize,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type pivot:RadPivotGrid}}}">
                <TextBlock.Foreground>
                    <MultiBinding Converter="{StaticResource MultiConverter}" >
                        <Binding Path="Data" Mode="OneWay"/>
                        <Binding Path="Product1"/>
                        <Binding Path="Product2" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type pivot:RadPivotGrid}}"></Binding>
                                             
                    </MultiBinding>
                </TextBlock.Foreground>
            </TextBlock>
        </DataTemplate>

Many Thanks,
Ruth

4 Answers, 1 is accepted

Sort by
0
Kalin
Telerik team
answered on 02 Jun 2014, 08:59 AM
Hello Ramya,

The PivotGrid is designed to display calculated values of the data in the ItemsSource, not the data itself. So one cell might represent the aggregated value of 10-15 records from the ItemsSource. In the CellTemplateSelector you can get different information about the cell (row, column, parent cells, PropertyAggregateDescription name) and depending on them to change the Foreground color of the TextBlock as required.

Hope this helps.

Regards,
Kalin
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Ramya
Top achievements
Rank 1
answered on 02 Jun 2014, 09:01 AM
Hi Kalin,
Thankyou for your post,but i need to bind the foreground the properties which has been used in the collection which bound to the itemsource,is there anyway to achieve it?

Thanks,
Ruth
0
Ramya
Top achievements
Rank 1
answered on 02 Jun 2014, 03:35 PM
Hi ,

It means the properties are there in the itemsource of pivot grid but need to access those in the celltemplate and they are not part of column or row group descriptions
0
Kalin
Telerik team
answered on 03 Jun 2014, 11:41 AM
Hello Ramya,

I understand the requirement and the only solution I can suggest would be using the same MultiValueConverter to pass the collection in the ViewModel as well as the Data displayed in the cell. This way will have the underlying collection in the converter and depending on the value of the Data you can return the desired colors. The binding should looks as follows:

<TextBlock.Foreground>
    <MultiBinding Converter="{StaticResource MultiConverter}" >
        <Binding Path="Data" Mode="OneWay"/>
        <Binding Path="DataContext.Orders" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type pivot:RadPivotGrid}}" />
    </MultiBinding>
</TextBlock.Foreground>

And an example for the converter Convert method:

public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
    var value = (double)((CellAggregateValue)values[0]).Value;
    var itemsSource = ((IEnumerable)values[1]).Cast<Order>().ToList();
 
    // you can implement custom logic here
    if (value < 1500)
    {
        return Brushes.Yellow;
    }
 
    return Brushes.Blue;
}

However please note that the information displayed in each cell doesn't represent a single item from the ItemsSource - it represents multiple items.

Hope this will help you to achieve the desired.

Regards,
Kalin
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
PivotGrid
Asked by
Ramya
Top achievements
Rank 1
Answers by
Kalin
Telerik team
Ramya
Top achievements
Rank 1
Share this question
or