PivotGrid - Conditional Formatting (Sort of...)

9 posts, 0 answers
  1. Speedy
    Speedy avatar
    21 posts
    Member since:
    Feb 2016

    Posted 02 May Link to this post

    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.

  2. Dimitar
    Admin
    Dimitar avatar
    1877 posts

    Posted 02 May Link to this post

    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.
  3. Speedy
    Speedy avatar
    21 posts
    Member since:
    Feb 2016

    Posted 02 May in reply to Dimitar Link to this post

    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'?

  4. Speedy
    Speedy avatar
    21 posts
    Member since:
    Feb 2016

    Posted 02 May in reply to Speedy Link to this post

    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!

     

     

  5. Speedy
    Speedy avatar
    21 posts
    Member since:
    Feb 2016

    Posted 02 May in reply to Speedy Link to this post

    And I thought I was done, but...

     

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

     

     

  6. Dimitar
    Admin
    Dimitar avatar
    1877 posts

    Posted 03 May Link to this post

    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.
  7. Speedy
    Speedy avatar
    21 posts
    Member since:
    Feb 2016

    Posted 03 May in reply to Dimitar Link to this post

    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
  8. Dimitar
    Admin
    Dimitar avatar
    1877 posts

    Posted 03 May Link to this post

    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.
  9. Speedy
    Speedy avatar
    21 posts
    Member since:
    Feb 2016

    Posted 03 May in reply to Dimitar Link to this post

    Absolutely perfect.  Thank you so much.
Back to Top