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

PivotGrid - Conditional Formatting (Sort of...)

8 Answers 97 Views
PivotGrid and PivotFieldList
This is a migrated thread and some comments may be shown as answers.
Speedy
Top achievements
Rank 1
Speedy asked on 02 May 2017, 12:19 PM

Please see the attached image. Can someone explain to me how to have the forecolor of the text, currently shown in red, to only display as red if the Source <> Employee?  In the image, only one employees hours / units should be displayed in red (the employee whose source = Third Party).

Apologies to admins for the double posting, but my deadline to complete this requirement is running out.

Can someone please offer some advice?  Surely this scenario has come up before.

Thanks in advance.

8 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 02 May 2017, 01:22 PM
Hi James,

Thank you for writing.

You can use the following approach for this:
private void RadPivotGrid1_CellFormatting(object sender, PivotCellEventArgs e)
{
    if (e.CellElement.Row.Name == "October")
    {
        e.CellElement.ForeColor = Color.Red;
    }
    else
    {
        e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
    }
}

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Speedy
Top achievements
Rank 1
answered on 02 May 2017, 01:58 PM

Okay, so if Row.Name = Source...

 

Then how to I evaluate the data in the Source column (in this case, row?) to see if its equal to 'Third Party'?

0
Speedy
Top achievements
Rank 1
answered on 02 May 2017, 02:12 PM

Dess was able to provide me an example which I was able to modify to my own usage. For anyone who has the same issue, see sample code and image to see how to acheive the formatting.

' Display hours as red if employee is a non-company employee         Dim groupNode As PivotGroupNode = TryCast(e.CellElement.Row, PivotGroupNode)         Dim parentGroupNode As PivotGroupNode = TryCast(e.CellElement.Row.Parent, PivotGroupNode)         If groupNode IsNot Nothing AndAlso groupNode.Name = "Source" Then             e.CellElement.ForeColor = Color.Red         ElseIf parentGroupNode IsNot Nothing AndAlso parentGroupNode.Name = "Third Party" Then             e.CellElement.ForeColor = Color.Red         Else             e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local)         End If

 

 

Thank Dess and Dimitar!

 

 

0
Speedy
Top achievements
Rank 1
answered on 02 May 2017, 06:31 PM

And I thought I was done, but...

 

How would I apply the same logic in PrintElementFormatting of a PivotGrid?

 

 

0
Dimitar
Telerik team
answered on 03 May 2017, 05:29 AM
Hello James,

The approach is similar you just need to cast the PrintElement in order to access the Row property. For example:
Private Sub RadPivotGrid1_PrintElementFormatting(ByVal sender As Object, ByVal e As PrintElementEventArgs)
    Dim cell As PivotCellPrintElement = TryCast(e.PrintElement, PivotCellPrintElement)
    If cell IsNot Nothing AndAlso cell.Row.Name = "October" Then
        cell.BackColor = Color.Red
    End If
End Sub

Please let me know if there is something else I can help you with. 
 
Regards,
Dimitar
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Speedy
Top achievements
Rank 1
answered on 03 May 2017, 12:09 PM

Getting closer, but that changes everything.  Perhaps I am asking wrong...

Can you explain how I can implement the below code, which works for CellFormatting, to work for PrintElementFormatting ?

 

Dim groupNode As PivotGroupNode = TryCast(e.CellElement.Row, PivotGroupNode)
 
Dim parentGroupNode As PivotGroupNode = TryCast(e.CellElement.Row.Parent, PivotGroupNode)
 
If groupNode IsNot Nothing AndAlso groupNode.Name = "Source" Then
 
e.CellElement.ForeColor = Color.Red
 
ElseIf parentGroupNode IsNot Nothing AndAlso parentGroupNode.Name <> "Employee" Then
 
e.CellElement.ForeColor = Color.Red
 
Else
 
e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local)
 
End If
 
End If
0
Dimitar
Telerik team
answered on 03 May 2017, 01:31 PM
Hello James,

You have to replace "e.CellElement" with the casted object "cell", no need to the reset the values. Here is the code:
Private Sub RadPivotGrid1_PrintElementFormatting(ByVal sender As Object, ByVal e As PrintElementEventArgs)
    Dim cell As PivotCellPrintElement = TryCast(e.PrintElement, PivotCellPrintElement)
    If cell IsNot Nothing Then
        Dim groupNode = TryCast(cell.Row, PivotGroupNode)
        Dim parentgroupNode = TryCast(cell.Row.Parent, PivotGroupNode)
 
        If groupNode IsNot Nothing AndAlso groupNode.Name = "Source" Then
            cell.ForeColor = Color.Red
        ElseIf parentgroupNode IsNot Nothing AndAlso parentgroupNode.Name <> "Employee" Then
            cell.ForeColor = Color.Red
        End If
 
    End If
End Sub

Do not hesitate to contact us if you have other questions.

Regards,
Dimitar
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Speedy
Top achievements
Rank 1
answered on 03 May 2017, 01:52 PM
Absolutely perfect.  Thank you so much.
Tags
PivotGrid and PivotFieldList
Asked by
Speedy
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Speedy
Top achievements
Rank 1
Share this question
or