Inputting conditional coding into alternating rows in Lists

Copper Contributor

Hello,

I am attempting to use both alternating rows and conditional formatting in Microsoft Lists.
The short of it is this;

If [$field_4] is == [$field_6] I want it to code the whole line gray and text red.
Otherwise, I just want it to use alternating rows to make the separated items easily identifiable.

I am not super familiar with coding; so I basically just tried to use a modified version of the code from the conditional JSON, and plug it into the code for alternating rows.

I am not sure what I would need to enter in order to use alternating rows AND the conditional together.
Basically wanting an IF, Then, Else... But I know that those aren't immediately usable in JSON without writing the logic for it.
Help please? Thanks in advance. 

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",
  "additionalRowClass": {
    "operator": ":",
    "operands": [
      {
        "operator": "==",
        "operands": [
          "[$field_4]",
          "[$field_6]"
        ]
      },
      "sp-css-backgroundColor-BgLightGray sp-field-fontSizeMedium sp-field-bold sp-css-color-DarkRedText sp-field-borderTopBottomSemibold sp-field-borderTopBottomSolid sp-css-borderTopColor-DarkRedText sp-css-borderBottomColor-DarkRedText",
      "",
      {
        "operator": "==",
        "operands": [
          {
            "operator": "%",
            "operands": [
              "@rowIndex",
              2
            ]
          },
          0
        ]
      },
      "sp-css-backgroundColor-BgCornflowerBlue40",
      {
        "operator": ":",
        "operands": [
          {
            "operator": "==",
            "operands": [
              {
                "operator": "%",
                "operands": [
                  "@rowIndex",
                  2
                ]
              },
              1
            ]
          },
          "sp-css-backgroundColor-noFill",
          ""
        ]
      }
    ]
  }
}

 


 

2 Replies

@TMalonson2205 you can't combine row and column formatting in the same JSON code. If you look at line 2 of your JSON you'll see that the schema is row-formatting. You would need to format the view with the alternating rows JSON and then format each column with the conditional formatting. I've not tried that but it could be quite a bit of work.

 

Rob
Los Gallardos
Microsoft Power Automate Community Super User.
Principal Consultant, SharePoint and Power Platform WSP Global (and classic 1967 Morris Traveller driver)

Hey @Rob_Elliott

So, this is Row formatting, it just happens to be conditional upon the information within a column.
I actually am modifying the provided JSON for alternating rows; I was just curious if there was a way to have it run this conditional first, then, if it is not met, default back to the alternating rows.

I really only care about the information within these 2 columns (and whether or not one is less than or equal to the other), all the others just need to be coded with the same formatting if the conditional is met.

IDK, putting in column by column wouldn't be too labor intensive, it's only one rule per column.
I wouldn't even need to use JSON.
Thanks for the idea.