We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Cell Template

Hi.

It's possible to apply cell-template on CustomSummary values?

Thanks.
Regards,
Juraj

9 Replies

SR Sabaridass Ramamoorthy Syncfusion Team December 13, 2016 11:15 AM UTC

Hi Juraj, 
  
No. We do not have the support to apply cell-template for particular value cells. You can apply the cell template for entire value cells by using ValueCellStyle of PivotGrid control. And also you can apply the style for particular value cell by using QueryCellInfo event handler available in InternalGrid. 
  
Regards,
Sabaridass R
 
 



JT Juraj Tomana December 15, 2016 07:43 AM UTC

Hi.

But how does it work? 

I was trying this:

    private void OnQueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
    {
      e.Style.Text = "xxx";
      e.Style.CellValue = "xxx";

      e.Style.CellItemTemplate = (DataTemplate) AssociatedObject.Resources["cellTemplate"];

      e.Style.ContextMenuItemSource = new string[]
      {
        "xx",
        "yy"
      };
    }

, but nothing happend.

Can you make some sample for me, please?

Thanks.
Regards,
Juraj


SR Sabaridass Ramamoorthy Syncfusion Team December 16, 2016 09:30 AM UTC

Hi Juraj, 
 
We have created a simple sample to achieve your requirement – “Apply cell template for custom summary values” and please find the samples from the following location. 
 
 
Please refer to the following code example. 
# MainWindow.Xaml 
 
<Window.Resources> 
        <DataTemplate x:Key="CustomSummaryTemplate"> 
            <Border     
            Name="Border" 
            Background="Green" 
            BorderBrush="#888" 
            BorderThickness="1" 
            CornerRadius="4"> 
            <TextBlock Text="{Binding Path=CellValue}" Padding="2" /> 
            </Border> 
        </DataTemplate> 
 
    </Window.Resources> 
# MainWindow.Xaml.cs 
 
private void PivotGrid1_Loaded(object sender, RoutedEventArgs e) 
        { 
            pivotGrid1.InternalGrid.QueryCellInfo += InternalGrid_QueryCellInfo; 
        } 
 
        private void InternalGrid_QueryCellInfo(object sender, Syncfusion.Windows.Controls.Grid.GridQueryCellInfoEventArgs e) 
        { 
            int startIndex = pivotGrid1.PivotColumns.Count + (pivotGrid1.PivotCalculations.Count > 1 ? 1 : 0); 
            if (pivotGrid1.PivotEngine[e.Cell.RowIndex,e.Cell.ColumnIndex].CellType.ToString().Contains("ValueCell") && pivotGrid1.PivotCalculations.Any(col => col.FieldName == pivotGrid1.PivotEngine[startIndex - 1,e.Cell.ColumnIndex].FormattedText && col.SummaryType == SummaryType.Custom)) 
            { 
                DataTemplate dt = this.Resources["CustomSummaryTemplate"] as DataTemplate; 
                pivotGrid1.InternalGrid.Model[e.Cell.RowIndex, e.Cell.ColumnIndex].CellItemTemplate = dt; 
                pivotGrid1.InternalGrid.Model[e.Cell.RowIndex, e.Cell.ColumnIndex].CellValue = pivotGrid1.PivotEngine[e.Cell.RowIndex, e.Cell.ColumnIndex].FormattedText; 
                pivotGrid1.InternalGrid.Model[e.Cell.RowIndex, e.Cell.ColumnIndex].Background = new SolidColorBrush(Colors.Gray); 
                pivotGrid1.InternalGrid.Model[e.Cell.RowIndex, e.Cell.ColumnIndex].Foreground = new SolidColorBrush(Colors.Red); 
                e.Handled = true; 
            } 
        } 
 
Regards, 
Sabaridass R. 



JT Juraj Tomana December 16, 2016 01:00 PM UTC

Hi.

Thanks, but I have 2 problems with this solution (see attached videos):

1) CellItemTemplate is not applied (Background and Foreground works fine)..

2) In my application in 'Loaded' event is pivotGrid.InternalGrid == null. Maybe this is because I'm using DockingManager (with document-container) and dynamically created documents?

Thanks.
Regards,
Juraj



Attachment: 127796_video_638535a0.zip


SR Sabaridass Ramamoorthy Syncfusion Team December 19, 2016 10:35 AM UTC

Hi Juraj, 
 
Please find the details below. 
 
CellItemTemplate is not applied (Background and Foreground works fine).. 
In order to apply the cell template for value cells, you need to set the CellType of current cell as “DataBoundTemplate”. We are extremely sorry for missing to mentioned that in our previous update. We have modified the attached sample based on your requirement and please find the sample from the following location. 
Please refer to following code example. 
#MainWindow.Xaml 
<Window.Resources> 
        <DataTemplate x:Key="CustomSummaryTemplate" > 
            <Border     
            Name="Border" 
            Background="Green" 
            BorderBrush="#888" 
            BorderThickness="1" 
            CornerRadius="4"> 
                <TextBlock Text="{Binding CellBoundValue}"  Background="BlueViolet"  Foreground="Orange" /> 
            </Border> 
        </DataTemplate> 
    </Window.Resources> 
# MainWindow.Xaml.cs 
private void PivotGrid1_Loaded(object sender, RoutedEventArgs e) 
        { 
            pivotGrid1.InternalGrid.QueryCellInfo += InternalGrid_QueryCellInfo; 
        } 
       
        private void InternalGrid_QueryCellInfo(object sender, Syncfusion.Windows.Controls.Grid.GridQueryCellInfoEventArgs e) 
        { 
            int startIndex = pivotGrid1.PivotColumns.Count + (pivotGrid1.PivotCalculations.Count > 1 ? 1 : 0); 
            if (pivotGrid1.PivotEngine[e.Cell.RowIndex, e.Cell.ColumnIndex].CellType.ToString().Contains("ValueCell") && pivotGrid1.PivotCalculations.Any(col => col.FieldName == pivotGrid1.PivotEngine[startIndex - 1, e.Cell.ColumnIndex].FormattedText && col.SummaryType == SummaryType.Custom)) 
            { 
                e.Style.CellType = "DataBoundTemplate"; 
                e.Style.CellItemTemplate = this.Resources["CustomSummaryTemplate"] as DataTemplate;  
                e.Style.CellValue = pivotGrid1.PivotEngine[e.Cell.RowIndex, e.Cell.ColumnIndex].FormattedText; 
                e.Handled = true; 
            } 
        } 
 In my application in 'Loaded' event is pivotGrid.InternalGrid == null. Maybe this is because I'm using DockingManager (with document-container) and dynamically created documents? 
As per the default behavior of PivotGrid control, InternalGrid for PivotGrid control has been rendered once the PivotGrid control was loaded. If you are trying to access the InternalGrid of PivotGrid control in loaded event handler of either Window or any other controls, it throws an exception as InternalGrid is null. So before access the InternalGrid, you must invoke/hook the loaded event of PivotGrid control and make sure that the control was rendered properly. Then you can access the InternalGrid within the PivotGrid_Loaded() event handler method. 
 
We had reviewed the video attached in your previous update and we suspect that the PivotGrid control was not loaded properly. Could you please ensure that the PivotGrid control was rendered properly within the controls (Docking Manager, Window, etc.,)? If possible, can you share your working sample with us, so that it would be helpful for us to check the same. 
 
Regards, 
Sabaridass R 
 



JT Juraj Tomana December 19, 2016 01:14 PM UTC

Hi.
In my application in 'Loaded' event is pivotGrid.InternalGrid == null. Maybe this is because I'm using DockingManager (with document-container) and dynamically created documents? 
I found the problem. I show the pivotGridControl just when it contains some data. So at the begining it didn't contain any data, so the visibility was set to  Collapsed. 
One more question about QueryCellInfo..Is it possible to change in QueryCellInfo just text-foreground?

Like:
..


            int startIndex = pivotGrid1.PivotColumns.Count + (pivotGrid1.PivotCalculations.Count > 1 ? 1 : 0);

            if (pivotGrid1.PivotEngine[e.Cell.RowIndex,e.Cell.ColumnIndex].CellType.ToString().Contains("ValueCell") &&

        pivotGrid1.PivotCalculations.Any(col => col.FieldName == pivotGrid1.PivotEngine[startIndex - 1,e.Cell.ColumnIndex].FormattedText && col.SummaryType == SummaryType.Custom))

            {

                pivotGrid1.InternalGrid.Model[e.Cell.RowIndex, e.Cell.ColumnIndex].CellValue = pivotGrid1.PivotEngine[e.Cell.RowIndex, e.Cell.ColumnIndex].FormattedText;

                pivotGrid1.InternalGrid.Model[e.Cell.RowIndex, e.Cell.ColumnIndex].Foreground = new SolidColorBrush(Colors.Red);

                e.Handled = true;

            }

 


without changing other style-attributes (alignment, padding, margin, background,...)?


Thanks.
Regards,
Juraj


SR Sabaridass Ramamoorthy Syncfusion Team December 20, 2016 09:27 AM UTC

Hi Juraj, 
 
Please find the details below. 
 
One more question about QueryCellInfo.. 
If you are try to set any style attribute for cell values, the entire style attributes for corresponding cell are also changing respectively. Since the CellType of the cell has been changed as “Static” and also the default style was applied as per the behavior of our base Grid control. We have set the CellType as “TemplateCell” for value cells and customizing the styles for accordingly while rendering the values into the cells. So if you want to change any style attribute for particular cell, you must customize all the style attributes based on the style applied for either value cells or summary cells. 
 
Please find the attached sample from the following location. 
 
Please refer to the following code example.  
#MainWindow.Xaml.cs 
 
private void InternalGrid_QueryCellInfo(object sender, Syncfusion.Windows.Controls.Grid.GridQueryCellInfoEventArgs e) 
        { 
            int startIndex = pivotGrid1.PivotColumns.Count + (pivotGrid1.PivotCalculations.Count > 1 ? 1 : 0); 
            if (pivotGrid1.PivotEngine[e.Cell.RowIndex, e.Cell.ColumnIndex].CellType.ToString().Contains("ValueCell") && pivotGrid1.PivotCalculations.Any(col => col.FieldName == pivotGrid1.PivotEngine[startIndex - 1, e.Cell.ColumnIndex].FormattedText && col.SummaryType == SummaryType.Custom)) 
            { 
                e.Style.CellValue = pivotGrid1.PivotEngine[e.Cell.RowIndex, e.Cell.ColumnIndex].FormattedText; 
                e.Style.Foreground = new SolidColorBrush(Colors.Yellow); 
                e.Style.HorizontalAlignment = HorizontalAlignment.Right; 
                e.Style.FlowDirection = pivotGrid1.FlowDirection; 
                e.Style.Borders.All = new Pen() { Brush = pivotGrid1.GridLineStroke, Thickness = 0.1 }; 
                if (pivotGrid1.PivotEngine[e.Cell.RowIndex, e.Cell.ColumnIndex].CellType.ToString().Contains("TotalCell")) 
                { 
                    e.Style.Background = pivotGrid1.SummaryCellStyle.Background; 
                    e.Style.Font.FontFamily = pivotGrid1.SummaryCellStyle.FontFamily; 
                    e.Style.Font.FontSize = pivotGrid1.SummaryCellStyle.FontSize; 
                    e.Style.Font.FontWeight = pivotGrid1.SummaryCellStyle.FontWeight; 
                     
                } 
                else 
                { 
                    e.Style.Background = pivotGrid1.ValueCellStyle.Background; 
                    e.Style.Font.FontFamily = pivotGrid1.ValueCellStyle.FontFamily; 
                    e.Style.Font.FontSize = pivotGrid1.ValueCellStyle.FontSize; 
                    e.Style.Font.FontWeight = pivotGrid1.ValueCellStyle.FontWeight; 
                } 
                e.Handled = true; 
            } 
        } 
 
In my application in 'Loaded' event is pivotGrid.InternalGrid == null. Maybe this is because I'm using DockingManager (with document-container) and dynamically created documents?  
Could you please confirm us whether the problem was resolved from your side and let us know if you require further assistance on this? 
 
Regards, 
Sabaridass R. 



JT Juraj Tomana December 22, 2016 12:01 PM UTC

Hi.

Both problems are now solved. Thanks.

Regards,
Juraj


SR Sabaridass Ramamoorthy Syncfusion Team December 23, 2016 05:35 AM UTC

Hi Juraj, 
 
Thanks for the update. 
 
Regards, 
Sabaridass R. 


Loader.
Up arrow icon