Expand-Collapse for Multiline Text columns in SharePoint

Sometimes, when working with the Multiline fields, they may occupy the whole page :-).

We can solve this issue by introducing Expand-Collapse Trick with jQuery. On clicking on the little Arrow that row will be expanded, then again clicking will collapse.

Expand-Collapse for Multiline Text columns in Sharepoint

Here is How: Add the CEWP webpart and place the below code, then hide the web part.

<script type="text/javascript">
if(typeof jQuery=='undefined'){
	var jQPath = 'https://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js'
	document.write('<script src="',jQPath,'" type="text/javascript"><\/script>');
}
</script>

<script type="text/javascript">
function ExpGroupRenderData(htmlToRender, groupName, isLoaded) {
	$("#tbod"+groupName+"_").attr("isloaded",isLoaded)
	.html(htmlToRender)
	.show("fast",collapseText("#tbod"+groupName+"_"));
}

function collapseText(group){
	if (!group) group = "#MSO_ContentTable";
	var html ="<img alt='collapseText' style='cursor:pointer;' src='/_layouts/images/menudark.gif'/>";
	$(group+" td.ms-vb2>div").each(function(i,e){
	$(e).css({display:"inline-block"});
	if (e.clientHeight > 35){
		$(e).toggleClass("collapseText")
		.prepend(html);
	}
	});
	$(group+" img[alt='collapseText']").click(function(event){
		$(event.target).parent().toggleClass("collapseText");
	});
}
$(function() {
	collapseText();
});
</script>

<style type="text/css">
.expandText {height:auto;}
.collapseText {height:28px;overflow:hidden}
.ms-vb{
vertical-align: middle
}
.ms-vb2{
vertical-align: middle;
}
.ms-vh2-nograd
{
text-align: center;
}
</style>

Another way:
Codeplex project: http://spcollapser.codeplex.com/, You can download the JS file from here

Wpcollapser collapsed

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

9 thoughts on “Expand-Collapse for Multiline Text columns in SharePoint

  • October 28, 2016 at 8:43 PM

    Has this been looked at lately? I am attempting to do this in SP 2013 but am running into the same issues as Steve and Anon.

    Reply
  • May 11, 2016 at 5:48 AM

    please let me know Expand-Collapse for Multiline Text columns in Sharepoint works in SharePoint 2013, i am trying it but i cannot able to make it work, what i am missing? please let me know.

    Reply
  • July 10, 2015 at 1:49 AM

    I like the simplicity of this solution, but just can’t get it to work with SP2013. I’ve raised a thread http://sharepoint.stackexchange.com/questions/148639/sharepoint-collapse-list, so if you have any suggestions, please help!

    Reply
  • December 16, 2014 at 8:32 PM

    Is there a new way to do this? Nothing happens when I add it to my page.

    Reply
  • January 22, 2014 at 7:41 PM

    Awesome Code .. Works like charm !!!

    Reply
  • December 12, 2013 at 7:01 PM

    I have tried this one in sharepoint 2010, after changing the path to a local jQuery + changing the path to some local copy of menudark.gif
    still not working for me.

    can you please assist?

    Reply
  • March 12, 2012 at 5:53 PM

    this does not work well with grouping. If grouping is set to auto-expand, this script forces it to auto-collapse. if user then selects expand grouping but then tries to click to go onto a new page this script forces the group to auto-collapse again… 🙁

    Reply
  • March 12, 2012 at 5:51 PM

    when grouping is added onto a list, this script always forces the list group to be collapsed. So for every page change it collapses the grouping by default regardless if grouping is set to auto-expand by default

    Reply

Leave a Reply