2

Could I edit the way the Lookup column displays information, if possible without code? (Or an easy explanation as to how to do it?).

Currently it is displaying as "Name; Name; Name; Name". I would like there to be at least line breaks between each item.

If possible, my second goal would be to make the two columns I got from the Lookup (main Lookup + joint column) to display in a table. Any of this easily done?

1

Note:

in June 2017, Microsoft disabled the use of JavaScript in a Calculated Column

That means given answers may not apply for newer SharePoint versions

For long explanation and work arounds see:
June 13th 2017 Microsoft blocked handling HTML markup in SharePoint calculated fields - how to get the same functionality back


Original answer:

This works in VIEWS on SP2010,13,16 & Online, and does not require jQuery or any extra JavaScript files or (Content Editor) WebParts

Disclaimer: you need minor JavaScript skills (just to understand what you are copy pasting), and debugging this code is PITA

The Lookup info you are after is actually available in the Context object once the VIEW has loaded, so you can access it with either CSR (Client side Rendering) or....

Stuff some Javascript in a Calculated Column... less lines compared to CSR.. but difficult to debug if you don't get the syntax right.

instructions

On the View page, Open F12 console and check the exact spelling for your Lookup Column (internal fieldname) in: ctx.ListData.Row[0] (paste this Array reference and hit enter, it will display the value for the first displayed List-Item)

Then create a Calculated Column, set the datatype to Number so it executes the HTML! (You only want this on the List, if you have ContentTypes, do NOT add this Column to ContentTypes)

Formula:

="<div style=""text-align:left""><img src=""/_layouts/images/blank.gif"" onload=""{"
  &"var TR=this;while(TR.tagName!='TR'){TR=TR.parentNode}"
  &"var item=ctx.ListData.Row[TR.rowIndex-1];"
  &"this.parentNode.innerHTML=item['Title'].replace(/;/g,'<br>');"
&"}""></div>"

replace Title with the internal fieldname of your Column (The internal name is the name of the Column when you first created it)

explanation

  • The onload function is triggered once the blank image is loaded.
  • The Table Row has the rowIndex.. but the first table row in the View Table is the Header row so we have to subtract -1
  • at the end the whole IMG tag is overwritten with the Lookup string replacing ; with BR tags

Detailed explanation and Pros & Cons at www.ViewMaster365.com/#How

iCC

  • However this may work, I'm keeping it as a last resort since I'm reluctant to start in what I consider difficult code... – Tomverff Mar 16 '16 at 19:50
  • I am trying to make this work. I have pasted code into calculated column, I'm in F12 console. Where do I find the exact internal fieldname? I can only find the code I entered, nothing's changed. Could you maybe show me by having the name of my lookupcolumn as 'Test' and the name of my calculated column as 'Test2'? – Tomverff Mar 16 '16 at 20:16
  • Paste ctx.ListData.Row[0] in the F12 Console and hit enter, that will show the values of first Item in the list. if Test is your columnname replace YOURINTERNALNAME with Test – Danny '365CSI' Engelman Mar 17 '16 at 8:12
  • Rewritten Formula should be easier to use – Danny '365CSI' Engelman Mar 17 '16 at 8:45
  • This works for the views, but any idea on how to make it work in DispForm.aspx? – Tomverff Mar 17 '16 at 18:26
0

Look at the content query webpart, this should do just what you're looking for. It grabs information from a list and the output can be styled to your fitting

  • You mean, instead of using Lookup column? – Tomverff Mar 16 '16 at 19:49
  • Users need to select info from the list, that's why I used lookup. Is there a way to let users make a selection that I can then use to retrieve files? – Tomverff Mar 16 '16 at 20:52
0

Try this (Modified answer):

  1. Download jQuery and save it to /SiteAssets/
  2. Create a JavaScript file named comma-break.js and save it in /SiteAssets/ with the contents of:

$(document).ready(function () { var str = $('.ms-listviewtable').html(); //; $('.ms-listviewtable').html(str.replace( new RegExp("</a>;","g"),"</a>;</br>")); });

  1. Add a Content Editor Web Part to your list and link to the jquery.min.js file.
  2. Add a Content Editor Web Part to your list and link to the comma-break.js file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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