Поделиться через


How to display images in a calculated column of a SharePoint list

How to display an Image in a SharePoint List

Many times I 've been asked by customers about how to display an image in a calculated column of a SharePoint list.
One of the scenario I mention here where, customer wanted to display a Red or Green button based on another column's value.

SharePoint list : MyTasksList

Column 1:

Column Name : Completed

Column Type : Yes/No

 Requirement:

There is another column named “StatusIcon”, Customer wanted to display an image on this column based on value of column “Completed”. Below is the condition

If "Completed" =Yes, then Display a Green button

If "Completed" = No, then Display a Red button, as shown below in the picture

 

           
   
  
There are many blogs which explains how to achieve this, However nothing seemed to be working.

When adding the formula 

="<DIV><img
src='"&IF([Completed], "/_layouts/images/KPIDefault-0.GIF", "/_layouts/images/KPIDefault-2.GIF")&"'></DIV>"   

 in the calculated column SharePoint throws error or just displays the text in the column instead of the button image.

Cause:

 SharePoint do not honor the escape characters and displaying the html text as normal text and displays it.

How to fix it

1. Open the site in SharePoint Designer

2. Open the List view where you wanted to display Image ie in my case” AllItems.aspx”

3. Select the first item from the calculated column “StatusIcon”

4. Click on tag <xsl:value-of> Select Edit Tage>

            

5. Add the tag disable-output-escaping="yes" and save

            

 

That's it...Now you will see the Images in the column :)

Comments

  • Anonymous
    January 01, 2003
    I'm not sure why you are unable to select single item. Ideally you should be able to select a single item using SharePoint Designer. Please test this on a normal list and see if you can select single item. Thank you,

  • Anonymous
    July 03, 2013
    Hi  there, thanks for the post. Can you please provide further details for step #3? I was able to open my list view and I can only select the entire set of records from it instead of the first one as you said. Therefore I can't reach the "Edit Tag" menu option from your screenshot of step #4. Thanks

  • Anonymous
    July 16, 2013
    The comment has been removed

  • Anonymous
    December 06, 2013
    Thanks! 2 problems: 1: It only works for the view you set it on. If I create a second view, I have to repeat the xsl change 2:It does not work in a web part. When I create a webpart for the list and use a view that I lready edited, the image does not display.

  • Anonymous
    September 12, 2014
    Amazing...loved it.

  • Anonymous
    September 16, 2014
    What if you don't have sp designer?

  • Anonymous
    September 29, 2014
    Worked perfectly. You saved me.
    Thanks.

  • Anonymous
    October 08, 2014
    Danny's tip worked for me. Thanks!

  • Anonymous
    December 23, 2014
    Cool.. You are the man

  • Anonymous
    January 20, 2015
    can we do it without sharepoint designer in MOSS 2007?

  • Anonymous
    February 17, 2015
    The comment has been removed

  • Anonymous
    April 13, 2015
    thank you!! the "number" change worked perfectly!

  • Anonymous
    July 30, 2015
    So what if you have Yes, No and Blank? I'm having issues with the adding a No
    =" ","hyphen.jpg'>")&""

    That formula works for NO or blank it shows hyphen but I'm trying to add No", "red-no.jpg'
    and it doesn't like it.

  • Anonymous
    February 24, 2016
    Thanks for the post, this worked for our site to show images in one of the KPI columns