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:**
- You want to record the Title for each displayed row
- then after all are displayed, hide the ones not having dublicate titles
Client Side Rendering or a jQuery script would be the obvious solutiuon.
Alternative is to jam that code into every ListItem as a Calculated Column.
Biggest benefit, it just executes anywhere it is displayed, no need for loading jQuery, no need for setting JSLinks on every webpart.
Paste the Formula in a Calculated Column, set datatype to Number and include it as last column in a View:
="<img src=/_layouts/images/blank.gif onload=""{"
&"var rowvalue='count_" & [Title] & "'"
&",counters=window.counters=window.counters||{};"
&"var TR=this;while(TR.tagName!='TR'){TR=TR.parentNode}"
&"counters[rowvalue]=counters[rowvalue] || 0;"
&"counters[rowvalue]++;"
&"_spYield(function(){"
&" TR.style.display=counters[rowvalue]>1 ? 'table-row' : 'none'; "
&"},1);"
&"}"">"
- Each item displays a blank IMG to trigger JavaScript code (the SCRIPT tag is disabled by Microsoft)
- You can then built a JavaScript variable with the value you want to check doubles for
Since this code is always executed for every ListItem we need some special bookkeeping of Global variables
- we check if a Global variable (object) exists, use it or declare it (once) as a new object
- we check if the value exists in the global object (a previous occurence) or set the counter to 0
- then always add 1 to the count
At this stage you could hide double values if the counter is >1 .. but you want the reverse, so it is essential we count all items first.
- _spYield (declared in SP.js, but you won't find any blogs or documentation) makes JavaScript execution wait (something not possible out of the box with JavaScript)
We need this wait/delay because IMGs are loaded async, thus this code as well and we want to make sure all ListItems are processed/counted.. a yield/Wait of 1 millisecond seems to be enough
So once all ListItems are counted they execute their own function
- the executed function sets the display based on the counter (for that rowvalue).
You could also not hide rows add apply coloring here:
&" TR.style.bacgrkound=counters[rowvalue]>1 ? 'lightcoral' : 'beige'; "
.
There are some Pros & Cons to this method. Read: https://www.365csi.nl/vm365com/#/How
iCC
&"console.log(rowvalue,counters[rowvalue]);"just before the _spYield line to trace whats going on. And try increasing that 1 millisecond, maybe the IMGs are loading too slow. You want to execute this function AFTER all items are displayed – Danny '365CSI' Engelman Jan 17 '17 at 20:18