0

I have a SharePoint list which has 5 columns. My problem is that my data is not aligned with the columns. What do I have to changed so that my data is aligned with their columns:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",
  "hideColumnHeader": true,
  "hideSelection": true,
  "rowFormatter": {
    "elmType": "div",
    "style": {
      "display": "flex",
      "flex-direction": "column",
      "align-items": "flex-start"
    },
    "children": [
      {
        "elmType": "div",
        "attributes": {
          "class": "ms-bgColor-themePrimary ms-fontColor-white"
        },
        "style": {
          "display": "=if(@rowIndex == 0, 'flex', 'none')",
          "font-weight": "bold",
          "font-size": "12px",
          "width": "100%",
          "padding": "4px"
        },
        "children": [
          {
            "elmType": "div",
            "txtContent": "Datum",
            "style": {
              "flex-grow": "1"
            }
          },
          {
            "elmType": "div",
            "txtContent": "00:00 - 07:59",
            "style": {
              "flex-grow": "1"
            }
          },
          {
            "elmType": "div",
            "txtContent": "08:00 - 15:59",  
            "style": {
              "flex-grow": "1"
            }
          },
          {
            "elmType": "div",
            "txtContent": "16:00 - 23:59",  
            "style": {
              "flex-grow": "1"
            }
          },
          {
            "elmType": "div",
            "txtContent": "Opmerkingen",  
            "style": {
              "flex-grow": "1"
            }
          }
        ]
      },
      {
        "elmType": "div",
        "attributes": {
          "class": "ms-borderColor-neutralQuaternary"
        },
        "style": {
          "display": "flex",
          "font-size": "12px",
          "width": "100%",
          "padding": "0 4px",
          "border-bottom-width": "1px",
          "border-bottom-style": "solid"
        },
        "children": [
          {
            "elmType": "div",
            "txtContent": "[$Datum]",
            "style": {
              "flex-grow": "1"
            }
          },
          {
            "elmType": "div",
            "txtContent": "[$Before]",  
            "style": {
              "flex-grow": "1"
            }
          },
          {
            "elmType": "div",
            "txtContent": "[$Between]",  
            "style": {
              "flex-grow": "1"
            }
          },
          {
            "elmType": "div",
            "txtContent": "[$After]",  
            "style": {
              "flex-grow": "1"
            }
          },
          {
            "elmType": "div",
            "txtContent": "[$Opmerkingen]", 
            "style": {
              "flex-grow": "1"
            }
          }
        ]
      }
    ]
  }
}
enter code here

enter image description here

5
  • 1
    Post a sample input values and output values after JSON format has been applied Commented Feb 4 at 20:36
  • I do not understand Commented Feb 4 at 20:37
  • 1
    Screenshot of the issue that you're facing.. it's easier to understand when you have a visual clue to debug your code Commented Feb 4 at 22:39
  • Hi, thank you for your response. I have added an image. Gr. P Commented Feb 6 at 14:57
  • I hope someone can help me :) Commented Feb 7 at 21:27

1 Answer 1

1

Try the updated json below and let me know. The main difference is that I've added "max-width": "20%" for each div element. You can adjust css properties like text-alignment as you deem necessary.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",
  "hideColumnHeader": true,
  "hideSelection": true,
  "rowFormatter": {
    "elmType": "div",
    "style": {
      "display": "flex",
      "flex-direction": "column",
      "align-items": "flex-start"
    },
    "children": [
      {
        "elmType": "div",
        "attributes": {
          "class": "ms-bgColor-themePrimary ms-fontColor-white"
        },
        "style": {
          "display": "=if(@rowIndex == 0, 'flex', 'none')",
          "font-weight": "bold",
          "font-size": "12px",
          "width": "100%",
          "padding": "4px"
        },
        "children": [
          {
            "elmType": "div",
            "txtContent": "Datum",
            "style": {
              "flex-grow": "1",
              "max-width": "20%"
            }
          },
          {
            "elmType": "div",
            "txtContent": "00:00 - 07:59",
            "style": {
              "flex-grow": "1",
              "max-width": "20%"
            }
          },
          {
            "elmType": "div",
            "txtContent": "08:00 - 15:59",
            "style": {
              "flex-grow": "1",
              "max-width": "20%"
            }
          },
          {
            "elmType": "div",
            "txtContent": "16:00 - 23:59",
            "style": {
              "flex-grow": "1",
              "max-width": "20%"
            }
          },
          {
            "elmType": "div",
            "txtContent": "Opmerkingen",
            "style": {
              "flex-grow": "1",
              "max-width": "20%"
            }
          }
        ]
      },
      {
        "elmType": "div",
        "attributes": {
          "class": "ms-borderColor-neutralQuaternary"
        },
        "style": {
          "display": "flex",
          "font-size": "12px",
          "width": "100%",
          "padding": "0 4px",
          "border-bottom-width": "1px",
          "border-bottom-style": "solid"
        },
        "children": [
          {
            "elmType": "div",
            "txtContent": "=toLocaleDateString([$Datum])",
            "style": {
              "flex-grow": "1",
              "max-width": "20%"
            }
          },
          {
            "elmType": "div",
            "txtContent": "[$Before]",
            "style": {
              "flex-grow": "1",
              "max-width": "20%"
            }
          },
          {
            "elmType": "div",
            "txtContent": "[$Between]",
            "style": {
              "flex-grow": "1",
              "max-width": "20%"
            }
          },
          {
            "elmType": "div",
            "txtContent": "[$After]",
            "style": {
              "flex-grow": "1",
              "max-width": "20%"
            }
          },
          {
            "elmType": "div",
            "txtContent": "[$Opmerkingen]",
            "style": {
              "flex-grow": "1",
              "max-width": "20%"
            }
          }
        ]
      }
    ]
  }
}

enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.