Forum Discussion
JSON view and column formatting
It's always a concern, 'customizating' SharePoint to do what you need. But the way they're doing the column/view formatting with JSON - I like that it's a bit more lightweight than customizing with Javascript - and the way they do it is pretty insulated from the actual structure of the page. And if you break something, it's usually only limited to that list/page - it's not something that will necessarily take down your whole site.
As to breaking, I'm sure MS will eventually put in a change and break something, or stop supporting a feature. They've had breaking changes since SharePoint 2007 - but I've only run into maybe 2 changes in 13 years where I had to recode anything.
I do wish they'd allow us to use a link to a separate file of JSON custom data - that would at least prevent the total loss of data if someone deletes it accidentally. It is concerning that a site user could totally destroy your customization, since on teams sites especially they have Edit control.
For now, I'm using a DevOps project and putting all my SharePoint column and view customizations in there (using VS Code to keep a local working copy and using a DevOps connector to Teams to log the commits). My file names contain the site/list/view/column name. At least then I've got a standard place to copy/paste from, I can control who has access, and we can see changes that are made. Granted I can't directly push the code. but it's better than burying the code on a network share somewhere. See if your work is using DevOps and if they'd let your create a new organization to hold your SharePoint customizations.
And as for others picking it up, I working on documentation in the DevOps readme - with links to how JSON works, the links to the Microsoft Documentation site, and instructions for setting up VSCode to commit to DevOps.
So, just some of my general thoughts...
Robin Nilsson THANK YOU for your speedy and thorough response!
I totally agree with you about being able to reference a JSON file - I'm creating a JSON file and storing it in Site Assets to help document, but that takes manual updating in two places, which typically doesn't get handled. I'm also trying to create a single document that I can use as a reference, pulling together information from a number of sources that I figure will help me work faster, but ...
I was thinking since you and I both like the idea of referencing a file that one of us should create a UserVoice entry, and found that there actually is one, but it had only one vote, as did some other SharePoint UserVoice entries about JSON. Perhaps a better way to approach it is to create an entry that is more inclusive of various ideas? E.g. "Enhance view and column formatting" to be something like (more ideas would be wonderful):
Enhance view and column formatting
- Provide an out of the box facility via the web interface to allow users to make selections to modify the formatting rather than having to generate the JSON themselves.
- Allow the JSON to be specified with a file reference rather than having to put the code directly in a field. (See also user voice entry: Allow View Formatting to reference external file, https://sharepoint.uservoice.com/forums/329214-sites-and-collaboration/suggestions/35836723-allow-view-formatting-to-reference-external-file).
- Prompt for updating view formatting JSON when someone with appropriate rights changes the display width of a field.
- Allow the Name field for a document to be formatted via view formatting and improve the formatting capabilities via column formatting (some things can be done using @currentField)
- Allow comments in JSON used for formatting (or at least provide tools to limit VS Code to allow only what SharePoint JSON formatting allows)
- Display an indicator on the list or library Settings page for each column that has column formatting set.
- Provide JSON formatting controls to modify grouping display.
- Robin NilssonOct 23, 2019Bronze ContributorThat looks great - you did the thinking work there , go ahead and post the UserVoice so it's in your name and I'll vote and get some other visibility to it.
- lindabusdieckerOct 23, 2019Brass Contributor
Robin Nilsson As you suggested, it's now done!
If it helps with anything you write up to generate interest, this is what I sent to some folks in my sphere of influence:
Please help raise Microsoft’s awareness that we want SharePoint Online view and column formatting to be improved by voting for my https://sharepoint.uservoice.com/forums/329214-sites-and-collaboration/suggestions/38876674-enhance-view-and-column-formatting.
There some neat stuff that can be done using JSON, but it’s complicated and I haven’t run into a site owner or contributor yet who wants to learn how to write up the JSON.
In order to vote, you’re clicking on a Subscribe button that causes updates to be sent to you about the suggestion, but there’s a link at the bottom of every email message update that allows you to unsubscribe.
There are other people interested in this type of thing, but so far all the UserVoice suggestions are disjointed and haven’t gotten many votes, which you need in order to get Microsoft’s attention. (And … I thought it was pretty cool - I actually had someone from Oregon encourage me to post the idea.
)Thank you!
- theChrisKentOct 24, 2019MVP
lindabusdiecker These are some great ideas!
If you are looking for a way to manage files and deployment directly from VS Code, DavidWarner has put together some samples of ways to do this with either PowerShell or the O365CLI. You can find all of that here: (fair warning, that, while powerful, it's definitely much more in the realm of development. But if things get daunting, David or I would be happy to help): https://github.com/SharePoint/sp-dev-list-formatting/tree/master/tools/general-dynamic-deployment-with-vscode
Your suggestion of providing out of the box interfaces to generate the JSON is a great one and one that Microsoft is actively working on. You'll see it in action on certain column types (datetime, choice, yes/no and a few others) and it's called Design Mode: https://www.youtube.com/watch?v=0sR7peVBNPk&list=PLR9nK3mnD-OXgMjDBdjWUTRia89oixBhx&index=14&t=0s
These are somewhat simplistic now but much more is coming in the future. The team demoed it at SPC last May and it should be pretty awesome. Hoping to see more about that soon.
You can implement comments in your JSON file by simply adding an attribute and setting the value. It's not super intuitive and could be better but it can be far better than forgetting how something works later. Fortunately, these values are totally ignored by the formatting engine and so they don't cause any problems. Here's a simple example:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json", "elmType": "div", "txtContent": "Hey there!", "comment": "Totally useless format that just shows 'Hey there!', Wowee!" }The use of "comment" above is totally arbitrary (you can use whatever key you want).
I too would like to be able to reference a file for my formatting (similar to JS Link)! But in the meantime here are a couple of tips that I use:
- Site Columns can contain formats and this makes for a more centralized place to use them across your site collection. If a user changes the format on a list field you can simply update the site column and have it push down it's changes.
- PnP Provisioning templates fully support column and view formats. You can extract a template of your site and reapply at any time.
- Formats can be applied via PowerShell and the O365CLI (see above for examples) so writing centralized deployment scripts is fully possible
You can find other tips/demos here: https://www.youtube.com/playlist?list=PLR9nK3mnD-OXgMjDBdjWUTRia89oixBhx