Color Grid PCF Control with Formulas and Functions
Color Grid PCF Control allows the user to personalize the colors of the grid like Header color, row Color and cell color.
Instead of just static color values, Color Grid allows the
user to set the row background Color and Cell background dynamically using Excel-like
formulas and custom functions.
Currently PCF control samples do not illustrate any way to implement formulas and functions that can be used in Control Properties. This article is an attempt to address that, to show a way how we can implement formulas and custom functions in PCF.
You can find the links to the source code and the solution file below:
Solution File Link
Below are the steps to use the control in Dynamics 365.
1. Import the solution ColorGridControl.zip to CRM
2. Open the “Active Accounts” view for Account entity and add column “Open Revenue” to the view.
3. Click on “Custom Controls” link in View.
4. Click on “Add Control”
5. Select Web, Phone and Tablet radio buttons.
6. Set the headerBackgroundColor and headerForegroundColor.
6. Set the headerBackgroundColor and headerForegroundColor.
=(GETFIELDVALUE('openrevenue') > 100000) ? 'green': 'red';
=Condition?TrueResult:FalseResult
Condition
An expression which is used as a condition. Such formulas commonly contain comparison operators (such as <, >, == and %) and functions such as GETFIELDVALUE.
An expression which is used as a condition. Such formulas commonly contain comparison operators (such as <, >, == and %) and functions such as GETFIELDVALUE.
In above scenario, (GETFIELDVALUE('openrevenue') > 100000) is condition.
GETFIELDVALUE is a custom function, which accepts field’s schema name as input, and returns the field value.
TrueResult
The corresponding value to return for a condition that evaluates to true.
In above case, it returns green when condition evaluates to true.
FalseResult
The corresponding value to return for a condition that evaluates to false.
In above case, it returns red when condition evaluates to false.
8. Set the Color Control rowBackColor property with Formula as shown below
=((ROWNUMBER() % 2) == 0) ? 'lightblue' : 'white';
This follows conditional formula format shown below
=Condition?TrueResult:FalseResult
Condition
((ROWNUMBER() % 2) == 0)
Here we are using ROWNUMBER function which returns the current row number. We are using % which is modulus operator, that returns the remainder left over, when ROWNUMBER is divided by 2 and that is compared with zero.
TrueResult
The corresponding value to return for a condition that evaluates to true.
The corresponding value to return for a condition that evaluates to true.
In above case, it returns lightblue when condition evaluates to true.
FalseResult
The corresponding value to return for a condition that evaluates to false.
In the above case, it returns white when condition evaluates to false.
9. Navigate to Active Accounts view in CRM.
Hi Sriram
ReplyDeleteYour PCF it's great I tested it, but I was wondering if you could make some improvements for example allow sort by clicking at header columns and allow to insert as a parameter the text color. Also I found probably a bug, the header background color always is darkblue, no matter what color have on the headerBackgroundColor parameter
Best regards
Hey ,
ReplyDeleteI also had a similar question if we are applying Pcf control to any homegrid how can we make command work as it is.
Suppose I have control for opportunity how can I make close as won , close as lost button available when I apply control for the home grid
Hello, i implemented this and i was able to change the cell color based on my condition. but I noticed the header of the view always change to dark blue and user can no longer filter the column using the dynamics out of the box filters in the headers. I also noticed the links in the view no longer work. no matter where you click it will always take you to the record like in my case the case record even if you are clicking in the name of the owner of the record it will not take you to the user profile. and all the letters in the view turn to light blue. can you please let me know how i can change the color of the cell without m messing up the basic functionality of the view like filtering and links
ReplyDeleteYes true, the header color doesn't change,
DeleteIt's a great tool but would have been ideal if the default layout mimics exactly the Dynamics read only grid and then we can update colors on top of it
Right now the grid look so much different and hence makes it almost unusable
Great job! Very much appreciated.
ReplyDelete