3

I have two lists: List B has two columns called [name] and [link] (both single line of text). E.g.:

Name: Google
Link: www.google.com

In list A I want a look-up to the values in list B. So I added [name] and [name:link] as lookup columns. But essentially I want to display the hyperlink to www.google.com as Google.

If these were normal list columns, I could simply create a calculated column with:

"<a href='[Link]'>"&[Name]&"</a>"

But as [name] and [name:link] are lookup columns, I can not use them within a calculated column. I also tried to create a designer workflow, but filling out a calculated field or a hyperlink field did not do the trick.

Besides CSR, is there a different way around it?

1 Answer 1

3

You don't have to go the CSR route but some JavaScript is required.

You already know the HTML in Calculated Column trick...

Let's extend that, the data you are after is in the global ctx object

disclaimer; I did not test this exact code, might be typos

="<img src=""/_layouts/images/blank.gif"" onload=""{"
    &"var TR=this.parentNode.parentNode.parentNode,"
    &"    item=ctx.ListData.Row[TR.rowIndex-1];"

    &"    console.log( TR.rowIndex-1 , item );"

    &"this.parentNode.innerHTML="<a href='"+ item.Link +"'>" +item.Name +"</a>"
&"}"">"
5
  • item.Link and item.Name can be used by the JavaScript within onload? Commented Jun 3, 2016 at 13:38
  • 1
    if they are in the View (ctx object,just like with CSR) yes. Check the item with a console.log statement Commented Jun 3, 2016 at 14:04
  • Unfortunately I discovered that I can't display the other columns in the view, which kicks out this approach. Commented Jun 6, 2016 at 8:34
  • You mean you do not want to display them. Ductape solution is to display them and hide them with some javascript then.. With about the same number of JS lines you might as well go the JSOM route then and fetch the Item from the server. But CSR might be easier then Commented Jun 6, 2016 at 8:46
  • "Displaying and hiding" the columns would be a solution, I agree. But as I won't be the one maintaining the site in the long run, I want to be as near to OOTB as possible. I will just change the behaviour of my lists. Commented Jun 6, 2016 at 9:09

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.