UPDATE: Find the 2010 version here !!
Struggling to find a good way to display a url in a list (output generated by the codeplex listsearch project), I found this solution from PathToSharePoint.
Normally, when you use a calculated column to create a dynamic link, you get the full url, like “http://www.test.com?id=9876”, when you want the link to just say ”customer 9876” or something.
What you can do is create the full html in the calculated field, which looks like this:
<div><a href=”http://www.test.com?id=&ID”>&Title</a></div>
This will also be displayed in your list.
So, how can we make this url to look the ”customer 9876” we really want ?
Simple: add a Content Editor WebPart on the page, and add following script:
<script type=”text/javascript”>
var theTDs = document.getElementsByTagName(“TD”);
var i=0;
var TDContent = ” “;
while (i < theTDs.length) {
try {
TDContent = theTDs[i].innerText || theTDs[i].textContent;
if ((TDContent.indexOf(“<DIV”) == 0) && (TDContent.indexOf(“</DIV>”) >= 0)) {
theTDs[i].innerHTML = TDContent;
}
}
catch(err){}
i=i+1;
}
function ExpGroupRenderData(htmlToRender, groupName, isLoaded) {
var tbody=document.getElementById(“tbod”+groupName+”_”);
var wrapDiv=document.createElement(“DIV”);
wrapDiv.innerHTML=”<TABLE><TBODY id=\”tbod”+ groupName+”_\” isLoaded=\””+isLoaded+ “\”>”+htmlToRender+”</TBODY></TABLE>”;
var theTBODYTDs = wrapDiv.getElementsByTagName(“TD”); var j=0; var TDContent = ” “;
while (j < theTBODYTDs.length) {
try {
TDContent = theTBODYTDs[j].innerText || theTBODYTDs[j].textContent;
if ((TDContent.indexOf(“<DIV”) == 0) && (TDContent.indexOf(“</DIV>”) >= 0)) {
theTBODYTDs[j].innerHTML = TDContent;
}
}
catch(err){}
j=j+1;
}
tbody.parentNode.replaceChild(wrapDiv.firstChild.firstChild,tbody);
}
</script>
This scripts lets the html that is on the page (and not parsed by the server) to be parsed client-side
Just add the script to the source editor of the CEWP and refresh the page, your code will now look like the real deal!!!
I encounter an issue here, if the user has only read access to the page the column value shows up as the HTML tag and not the desired format.
please help
regards,
Swami
hmm, good question, i dont have that issue right here..
Maybe you can alter the read rights to include some permission to execute code on the page ?
Can you post the contents of your calculated field? I'm trying to make a link to another list (the user provides the FDS ID). This is what mine looks like:
=CONCATENATE("<_DIV><_a href='http://intranetsite/sites/AnotherSite/AnotherList/DispForm.aspx?ID=",[FDS ID],"'>",[FDS ID],"<_/a>_/DIV>")
Is this the best way to do this? Also, I'm not getting any rendering of the HTML even though I've added the <_script><_/script> from the other blogs. If nothing else, I'll just do the URL, but I'll need to add a condition to check if [FDS ID] isn't empty. Thanks!
lijkt bij mij toch niet te werken hoor.
It is best that you copy the original code from the url on top. That should make things work.
Also make sure your javascript in under the list you wish to apply the code on!!
Joe, What is up with the _ ?
the rest is looking ok to me..
How can I use this to execute a custom workflow from a view?
Thanks for the script.
Does this also work in SharePoint 2010? It seems not to work in SP 2010.
Does this also work in sharepoint 2010?
I put a link to the article on the first line on how to do that in SP2010
It is exactly what Im looking for, however, it does not work. I try already for hours. If you enter &Title into the formula field it says "The formula contains a syntax error or is not supported"
I have not looked into it but would it be possible to inherit from the calculated field but just not escape the output… actually make a HTML calculated field?
Ofcourse you can.
Hi,
I have tried in this way. I have added 2 column in discussion board.
First column name i have given was color and selected the data type Calculated column.
In Formula I have provided below values.
=IF(OR(Status=”Not Started”,Status=”Deferred”),”Yellow”,IF(OR(Status=”In Progress”,Status=”Complete”),”Green”,IF(Status=”Waiting on Someone Else”,”Red”)))
2nd column called Indicator of the data type Calculated column. In formula field I have entered =”•”
I have also added a Content editor web part andgiven link to the indicator1.js file which was saved in document library.
The indicator1.js file hols the above mentioned script.
Unfortunately I can still see the HTML code still.
Please advice.
Did you try it with the link on top of my post? That points to an improved version of the script.
Hi,
I have a calculate column that calculate today date dynamically
I followed the link below
https://sharepoint2020.wordpress.com/2015/05/17/display-todays-date-in-a-calculated-column-with-javascript/#comment-715
problem is calculated column in number data type. I want it as Date and Time date format.
I want to calculate date difference between dynamic today date and another Overdue date field.
Can you help me please…