How to format a column in a Sharepoint online list?

Edison Tulcanazo 0 Reputation points
2023-05-11T13:53:27.25+00:00

Greetings community, wishing you success in your activities, he told you I have an online sharepoint list with a column where the country is selected, I formatted the column to show the flag and the name of the country, it was working correctly a couple of weeks ago I have checked the code and it works.

What happens is: in the default view of the list, the flag of the country they select is not displayed, only the name appears, but if they switch to grid view if the flag with their country appears, the flag is displayed in the same way when the form is opened by selecting the record.

I don't quite understand what is happening, I have checked the updates but there is nothing referring to this problem and for this reason I turn to you.

Thank you for your support and time, I am attentive to your comments

I attach images and json code as found

User's image

User's image

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "inlineEditField": "[$Country]",
  "children": [
    {
      "elmType": "img",
      "attributes": {
        "src": "=if(@currentField,('https://www.worldometers.info/img/flags/' + if(indexOf(@currentField,'Afganistán')==0,'af', 
if(indexOf(@currentField,'Albania')==0,'al',if(indexOf(@currentField,'Alemania')==0,'gm', if(indexOf(@currentField,'Argelia')==0,'ag',
 if(indexOf(@currentField,'Argentina')==0,'ar', if(indexOf(@currentField,'Andorra')==0,'an', 
if(indexOf(@currentField,'Antigua y Barbuda')==0,'ac',if(indexOf(@currentField,'Arabia Saudita')==0,'sa', 
if(indexOf(@currentField,'Vietnam')==0,'vm',if(indexOf(@currentField,'Yemen')==0,'ym',if(indexOf(@currentField,'Yibuti')==0,'dj',
if(indexOf(@currentField,'Zambia')==0,'za',if(indexOf(@currentField,'Zimbabue')==0,'zi','no')))))))))))))))))))))))) 
+ '-flag.gif'),'')",
        "title": ""
      },
      "style": {
        "max-width": "23px",
        "padding": "0 6px 0 0"
      }
    },
    {
      "elmType": "span",
      "txtContent": "@currentField"
    }
  ]
}
Microsoft 365 and Office | SharePoint | For business | Windows
{count} votes

1 answer

Sort by: Most helpful
  1. Ling Zhou_MSFT 23,670 Reputation points Microsoft External Staff
    2023-05-12T08:59:52.9166667+00:00

    Hi @Edison Tulcanazo ,

    Thank you for posting in the community.

    I checked the src section in your json and found a lot more mismatched right brackets, which is probably what is causing you to not see the image in the default view. I reorganized the src section:

    “src”:”=if(@currentField,('https://www.worldometers.info/img/flags/' + if(indexOf(@currentField,'Afganistán')==0,'af',
    if(indexOf(@currentField,'Albania')==0,'al',if(indexOf(@currentField,'Alemania')==0,'gm',if(indexOf(@currentField,'Argelia')==0,'ag',
    if(indexOf(@currentField,'Argentina')==0,'ar',if(indexOf(@currentField,'Andorra')==0,'an',
    if(indexOf(@currentField,'Antigua y Barbuda')==0,'ac',if(indexOf(@currentField,'Arabia Saudita')==0,'sa',
    if(indexOf(@currentField,'Vietnam')==0,'vm',if(indexOf(@currentField,'Yemen')==0,'ym',if(indexOf(@currentField,'Yibuti')==0,'dj',
    if(indexOf(@currentField,'Zambia')==0,'za',if(indexOf(@currentField,'Zimbabue')==0,'zi','no')))))))))))))+
    '-flag.gif'),'')”
    

    You can replace your src section, and then refresh the page to see if the images are displayed properly.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.