0

I have a Modern SharePoint document library that includes a column header that is slightly too long, and cuts off:

enter image description here

This "Date Last Declared" column is a Date and Time column. I'm able to write JSON to expand the width of the column, but it only affects the content, not the header.

Is there a way I can either expand the column to fit the header, or wrap the header?

2 Answers 2

1

You cannot format the column headers using JSON formatting in SharePoint online.

But you can manually increase the width of column header by dragging it to the right & save the library view.

For detailed steps, check: SharePoint Modern List - Increase column width with JSON Issue


Updates from comments:

I can re-size the column header & save the view in web part added on SharePoint page as well.

Document library: Default document library page

enter image description here

Library web part: library web part added on SharePoint modern page

enter image description here

3
  • I actually tried doing that manually and saving it as a new view. The set up is like this...I have a page in which the library is displaying via web part. When I edited the web part to point to the new view I saved, the column width doesn't apply.
    – Chris
    May 19, 2021 at 16:54
  • I just tried this & it is working fine for me. Check screenshots in updated answer. May 19, 2021 at 17:17
  • 1
    Actually it now looks like saving the manually adjusted columns as a new view, and pointing the web part to that view works. I had to refresh a couple of times, but I think I'm in the clear. Thanks again for the assistance!
    – Chris
    May 19, 2021 at 17:29
0

If you are willing to hide the OOB column headers and create customized column headers using JSON, you can take a reference to the json code in my answer: https://docs.microsoft.com/en-us/answers/questions/386485/sharepoint-list-formatting-34hideselection34-does.html

I set hideColumnHeader to true and use rowFormatter to define a totally custom layout. Then I designed DIV in this part:

"children": [
       {
         "elmType": "div",
         "txtContent": "Title",
         "style": {
           "width": "80px"
         }
       },
       {
         "elmType": "div",
         "txtContent": "Departure",
         "style": {
           "width": "100px"
         }
       },
       {
         "elmType": "div",
         "txtContent": "Arrival",
         "style": {
           "width": "100px"
         }
       }
     ]
   },
2
  • Thanks for you response. I'm unclear as to what part of your script would expand the column headers.
    – Chris
    May 22, 2021 at 10:40
  • Sorry, I have updated my answer.
    – Allen_MSFT
    May 26, 2021 at 7:19

Your Answer

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