3

What I'm trying to do is achieve making my own header and hiding the original header so that the users can't change the setting.

To accomplish this, I found that I can change the "Format View".

 {
   "$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
   "hideColumnHeader": true,

   "rowFormatter": {
     "elmType": "div",
     "style": {
       "display": "flex",
       "flex-direction": "column",
       "align-items": "flex-start"
     },
     "children": [
       {
         "elmType": "div",
         "attributes": {
           "class": "ms-fontColor-black"
         },
         "style": {
           "display": "=if(@rowIndex == 0, 'flex', 'none')",
           "font-weight": "bold",
           "font-size": "18px",
           "width": "100%",
           "padding": "4px"
         },
         "children": [
           {
             "elmType": "div",
             "txtContent": "Title",
             "style": {
               "width": "80px"
             }
           }
         ]
       },
       {
         "elmType": "div",
         "attributes": {
           "class": "sp-row-listpadding"
         },
         "children": [
           {
             "elmType": "div",
             "style": {
               "text-align": "left"
             },
             "children": [
               {
                 "elmType": "div",
                 "style": {
                   "float": "left",
                   "width": "80px",
                   "font-size": "1.2em",
                   "margin-left": "2px"
                 },
                 "attributes": {
                   "class": "sp-row-title"
                 },
                 "txtContent": "[$Title]"
               }
             ]
           }
         ]
       }
     ]
   }
 }

The code above allows me to make my own heading and display the corresponding data, and I just wrote the code for one column. The problem I have is, when I display the data, and when the data is greater than width of 80px (as written in the code), it doesn't wrap and keeps on going down. I tried many methods but they all don't seem to work.

Could someone tell me how to wrap this text?

1 Answer 1

3

You can use "white-space": "break-spaces" to wrap the text. Try using JSON like:

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
    "hideColumnHeader": true,
    "rowFormatter": {
        "elmType": "div",
        "style": {
            "display": "flex",
            "flex-direction": "column",
            "align-items": "flex-start"
        },
        "children": [
            {
                "elmType": "div",
                "attributes": {
                    "class": "ms-fontColor-black"
                },
                "style": {
                    "display": "=if(@rowIndex == 0, 'flex', 'none')",
                    "font-weight": "bold",
                    "font-size": "18px",
                    "width": "100%",
                    "padding": "4px"
                },
                "children": [
                    {
                        "elmType": "div",
                        "txtContent": "Title",
                        "style": {
                            "width": "80px",
                            "white-space": "break-spaces"
                        }
                    }
                ]
            },
            {
                "elmType": "div",
                "attributes": {
                    "class": "sp-row-listpadding"
                },
                "children": [
                    {
                        "elmType": "div",
                        "style": {
                            "text-align": "left"
                        },
                        "children": [
                            {
                                "elmType": "div",
                                "style": {
                                    "float": "left",
                                    "width": "80px",
                                    "white-space": "break-spaces",
                                    "font-size": "1.2em",
                                    "margin-left": "2px"
                                },
                                "attributes": {
                                    "class": "sp-row-title"
                                },
                                "txtContent": "[$Title]"
                            }
                        ]
                    }
                ]
            }
        ]
    }
}

Output:

enter image description here

3
  • It works Ganesh, thank you so much. Just one quick question. When I run that, the coding I had on 'Format Columns' disappears. Dyou know how to include that in the coding?
    – TM1
    Commented Aug 25, 2022 at 9:13
  • You added "white-space": "break-spaces" in column formatting as well? Commented Aug 25, 2022 at 11:05
  • 1
    View formats using rowFormatter are responsible for drawing the whole thing. If you'd like to use your column formats you can include them in your view format as an element like this {"columnFormatterReference": "[$InternalNameOfColumn]"} Commented Aug 25, 2022 at 17:38

Your Answer

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

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