1

I wanna do exactly the same thing http://blog.pathtosharepoint.com/2008/09/01/using-calculated-columns-to-write-html/. But it doesn't work. It shows me just a simple text like : <DIV><a href='https://taf.sharepoint.com/KB/SitePages/Home.aspx'>Branding</a></DIV>. And I want it to appear just 'Branding'.

Thanks for helping

3
  • Have you added the Content Editor Web Part to the page and added the script you are linking to?
    – Robban1980
    Commented Sep 3, 2014 at 4:27
  • Yes I added the content editor web part
    – user32762
    Commented Sep 3, 2014 at 4:28
  • Can you mark your question as answered, It keeps popping up in the Unanswered list Commented Aug 10, 2015 at 11:05

2 Answers 2

2

When you set the Calculated datatype to Number in SP2010, SP2013 or Office365 the contents of the Calculated Column is interpreted as HTML without the need for any additional coding.

In SP2013 the proper way to do it is coding CSR/JSlink but the above workaround (setting datatype to Number) still works

your example

="<DIV><a href='https://taf.sharepoint.com/KB/SitePages/Home.aspx'>Branding</a></DIV>"

Displays the same link for every table row

If you have a URL for a ListItem in a TEXT column named: URL

you can built the Calculated Column HTML more dynamic:

="<DIV><a href='"&[URL]&"'>Branding</a></DIV>"

Remember to set the datatype to number:

Some notes:

A lot is possible in the Calculated Column it is just a pain to debug

  • You can not use the SCRIPT tag since SP2013 update of around may 2013.. might still work in 2010
  • Only Text, Choice, & Date fields are available for Calculated Columns; eg. the Multiline Text / Description field is not accessible (on 2013 again you can use CSR/JSlink)
  • Because the datatype is Number the Column header will be aligned to the right
  • It is undocumented behaviour.. so like the SCRIPT tag being filtered, functionality might be changed by Microsoft without any warning

  • and this one took me some days to figure out: If you need a double quote inside a Calculated Column string you have to use the double notation to escape eg:

    ="<button onclick=""alert('I am ID: "&[ID]&"  ')"">My ID is "&[ID]&"</button>"
    

The example code itself is stupid.. but proves you can execute Javascript

Next suggested read: Calculated column with link - remove space / whitespace / slash

HTH

Danny Engelman

0

The blog that you are using is quite old and for 2007. Assuming you are using 2013, you can't add javascript in content editor anymore, see : http://social.msdn.microsoft.com/forums/sharepoint/en-US/dc299877-ac9e-4493-bf85-801faf0ec1d3/content-editor-webpart-losing-its-javascript

The new way to change css is using jquery. I'm newbie to jquery, so bear my mistakes. It looks like doing a lot of work, but when you get the hand of it, you won't regret it. And you won't need calculated field.

a) Install Firebug in Firefox, find the /right click/inspect element, go up and find the table's id. Add reference to jquery and in script editor:

var tableId = "what you have found";
$('#'+tableId + ' tr td:nth-child(1)).each(function() {
$(this).css('font-weight','bold');
}

If table id contains $, then it's a litle different.

2

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.