Friday, January 11, 2013

Limit chars displayed in SharePoint List View

Here's how to do it, and yes it's a little complicated:

First, create a single-line text column, I'll call it Content

Second, create a calculated column, I'll call it ContentCalc, set the formula to =[Content]

Third, delete the first column Content, then recreate it as a multi-line text column

Fourth, create a third column, I'll call it Summary, and set the formula to =LEFT([ContentCalc],60)&"...", with 60 being any number of chars you want to truncate it to and it will be followed with "..." to indicate there is more text.

Finally, to get rid of the stuff, insert the following source into a Content Editor Web Part placed under the list hidden on the page:

<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) { theTDs[i].innerHTML = TDContent; } } catch(err){} i=i+1; } </script>

Related Link