I have been looking into using view formatting to alternate the colors of rows in order to recreate what came out of the box in the classic views. However it seems like I can't access the row ID as a criteria nor can I use Mod as an operator. I kinda found a work around using a calculated column to do the MOD, but it is not an elegant solution. Is there really no easy way to alternate the row colors?

  • Plain old CSS tr:nth-child(odd) and tr:nth-child(even) is not sufficient? – Dylan Cristy Dec 18 '18 at 17:00
  • Sure, but how would I inject that on a modern list view? – Kasper Bo Larsen Jan 19 '19 at 12:39
  • Unfortunately, I couldn't tell you. I'm still stuck on 2013/2016 on-prem. – Dylan Cristy Jan 19 '19 at 16:53

All Items, Format current view, put the following in the JSON box.

  "$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
  "additionalRowClass": "=if(@rowIndex % 2 == 0,'ms-bgColor-themeLighter ms-bgColor-themeLight--hover','')"
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.