When I first started thinking on Conditional Formatting, I thought it would be hard to make it easy. I do hope that implementation you see below will meet your expectations and give you a nice, easy way to use it. What is conditional formatting? Well, imagine you want to show values higher or lower than some value, and that you want to make it clear. That's what this feature is all about. But I've gone a bit further and allowed for coloring table as you want it with conditions.
I've taken the same code as before and added conditional formatting to it. I wanted to see text colored in BlueViolet if a value in the ID column is greater than 10000. I also wanted coloring to apply to the whole row, and not just value.
What you see above is I've opened a bracket for Table, and inside a table, I've defined TableConditionalFormatting. I needed to define comparison a ComparisonType (number or string). Then we need to set the operator. I'm using a few standard Powershell operators to make it easy to remember. The list is limited to eq, lt, le, ge, gt. Now I've Value parameter which should be evident for you. Finally, we have two more settings. First one is Color. This is related to text coloring. The other one is called Row. This is a switch parameter. It tells conditional formatting that if Value of 10000 is found the whole row should be colored, a not just that particular value. If you do not use Row switch, it will only apply to Value. What is great about Conditional Formatting feature it doesn't just apply once. You actually can define multiple conditions and they DON'T HAVE TO BE RELATED. Let's see this on an example.
$Process = Get-Process | Select-Object -First 30
Dashboard -Name 'Dashimo Test' -FilePath $PSScriptRoot\DashboardSimplestTable.html -Show {
Table -DataTable $Process -HideFooter {
TableConditionalFormatting -Name 'ID' -ComparisonType number -Operator gt -Value 10000 -Color BlueViolet -Row
TableConditionalFormatting -Name 'Name' -ComparisonType string -Operator eq -Value 'chrome' -Color White -BackgroundColor Crimson -Row
}
}
Do you see what I did there? I've added another condition where I told Table I want to highlight every row that has chrome as process name. It's not at all related to the first condition. It also changed the background color and text color as well. But wait? I also want to highlight all processes that are Idle.
$Process = Get-Process | Select-Object -First 30
Dashboard -Name 'Dashimo Test' -FilePath $PSScriptRoot\DashboardSimplestTable.html -Show {
Table -DataTable $Process -HideFooter {
TableConditionalFormatting -Name 'ID' -ComparisonType number -Operator gt -Value 10000 -Color BlueViolet -Row
TableConditionalFormatting -Name 'Name' -ComparisonType string -Operator eq -Value 'chrome' -Color White -BackgroundColor Crimson -Row
TableConditionalFormatting -Name 'PriorityClass' -ComparisonType string -Operator eq -Value 'Idle' -Color White -BackgroundColor Green
}
}
Easy right? I hope so! Keep in mind the coloring part is done from top to bottom. It's entirely possible that the first condition will never show if your second condition will match the same data.