Forum Discussion
Sharepoint List Column Formatting
- Jun 28, 2021
DevHuws Not sure if I understood it correctly. But, either of below JSON codes should work for you:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json", "additionalRowClass": "=if(([$DueDate] && [$DueDate] <= @now) || ([$EndDate] && [$EndDate] <= @now) || ([$AnyOtherDateColumn] && [$AnyOtherDateColumn] <= @now), 'sp-field-severity--severeWarning', '')" }OR
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json", "additionalRowClass": "=if((Number([$DueDate]) !=0 && [$DueDate] <= @now) || (Number([$EndDate]) !=0 && [$EndDate] <= @now) || (Number([$AnyOtherDateColumn]) !=0 && [$AnyOtherDateColumn] <= @now), 'sp-field-severity--severeWarning', '')" }Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
ganeshsanap Hi thanks for the reply, this works well with formatting based on multiple columns, however I have date fields which do not contain dates and these are being formatted as well. Is there anyway to include if the date field = 0, it will ignore it? While still formatting all that have late dates?
DevHuws Great, glad it worked for you.
For your another question about blank date field:
This is not possible using the view formatting code I provided as it colors the whole row. However, you can override the view formatting by applying column formatting for specific date columns. You can use the JSON similar to this:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"style": {
"background-color": "=if(Number(@currentField) == 0, 'white', '#FDE7E9')"
}
}
You can change the background-color in above JSON as per your requirements. The output of above JSON will look something like below:
More ways to check if date field is blank: SharePoint JSON formatting: Check if date & time column is blank/empty
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
- DevHuwsJun 28, 2021Copper ContributorHi thanks for the quick reply. Sorry not sure if I explained properly, I don't mind the whole row being coloured I just dont want the row to be coloured if for example start date was empty, and only colour the row if it includes a date which has expired. If this is not possible I will use the example you have mentioned with column formatting. Thank you for your help!
- ganeshsanapJun 28, 2021MVP
DevHuws Not sure if I understood it correctly. But, either of below JSON codes should work for you:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json", "additionalRowClass": "=if(([$DueDate] && [$DueDate] <= @now) || ([$EndDate] && [$EndDate] <= @now) || ([$AnyOtherDateColumn] && [$AnyOtherDateColumn] <= @now), 'sp-field-severity--severeWarning', '')" }OR
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json", "additionalRowClass": "=if((Number([$DueDate]) !=0 && [$DueDate] <= @now) || (Number([$EndDate]) !=0 && [$EndDate] <= @now) || (Number([$AnyOtherDateColumn]) !=0 && [$AnyOtherDateColumn] <= @now), 'sp-field-severity--severeWarning', '')" }Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
- J27Sep 03, 2021Copper Contributorganeshsanap,
Hi Ganesh,
I have a same scenario in Sharepoint where if column value is >0, then it need to be in red color. It's a calculated column like below
if([DueDate]-[ActivationDate]>28, "[Other column] * 1000", 0$). I don't want to do anything with this formula. Only color formatting need to be applied if column value >0, then red color.
Do you have any suggestions, please.
Regards
Janaa