Question

I would like to format a column, so that when a user selects multiple choices, each choice is displayed on a single line rather than separated by comma (,).

I'm looking to leverage JSON formatting for this.

Était-ce utile?

La solution

Try using below JSON code on your choice field:

{
   "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
   "elmType": "div",
   "txtContent": "=join(@currentField, '\n')"
}

Official documentation: Use column formatting to customize SharePoint.

Reference for operators you can use in JSON formatting, JSON formatting - Operators.

How join() works:

join() takes 2 operands. The first is an array (multi-select person or choice field) and the second is the separating string.

Returns a string concatenation of the array values separated by the separating string.

Example for multi-select choice field:

"txtContent": "=join(@currentField, ', ')" --> This will result in Apple, Orange, Cherry (depending on the selected values)

Example for multi-select person field:

"txtContent": "=join(@currentField.title, '|')" --> This will result in Chris Kent|Vesa Juvonen|Jeff Teper (depending on the selected persons names).

Autres conseils

You can use this:

{
   "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
   "elmType": "div",
   "txtContent": "=join(@currentField, '\n'"
}

A little explanation:

join: takes 2 operands. The first is an array (multi-select person or choice field) and the second is the separating string. Returns a string concatenation of the array values separated by the separating string. - Only available in SharePoint Online

"txtContent": "=join(@currentField, ', ')" might result in "Apple, Orange, Cherry" (depending on the selected values)
"txtContent": "=join(@currentField.title, '|')" might result in "Chris Kent|Vesa Juvonen|Jeff Teper" (depending on the selected persons)

As they suggested, use the code they provided on your choice field:

{
    "$schema":
    "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "div",
    "txtContent": "=join(@currentField, '\n')"
 }

This works for me, the following is my test result:

enter image description here

Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top