Show field description in list view column header – updated version

I have previously posted this solution that lets you add the field description to the list view column header.

By request I have updated the solution to work in a web part page with multiple lists / libraries.

Put this code in a Content Editor Web Part at the bottom of your list view or web part page:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
var is2010 = typeof(_fV4UI)!=='undefined';

$("div[id^='WebPartWPQ']").each(function(){	
	var wpID, tCtxId, tCtx, myTooltipObj, toFind, fieldDisplayName
	wpID = $(this).attr('WebPartID').toUpperCase();	
	tCtxId = g_ViewIdToViewCounterMap["{"+wpID+"}"];
	if(tCtxId!==undefined){
		tCtx = eval("(ctx"+tCtxId+")");	
		myTooltipObj = customGetList(tCtx.listName);	
		toFind = "table.ms-listviewtable th";
		if(is2010){
			toFind = "div.ms-vh-div";
		}		
		$(this).find(toFind).each(function(){
			if(is2010){
				fieldDisplayName = $(this).attr('DisplayName');	
			}else{
				fieldDisplayName = $(this).find("table:first").attr('DisplayName');	
			}
			if(fieldDisplayName===undefined){
				fieldDisplayName = $(this).text();
			}
			if(myTooltipObj[fieldDisplayName]!==undefined){
				$(this).attr('title',myTooltipObj[fieldDisplayName]).find('a').attr('title',myTooltipObj[fieldDisplayName]);;
			}
		});
	}
});

function customGetList(listName){
	var xmlWrap, result;
	xmlWrap = [];
	xmlWrap.push("<?xml version='1.0' encoding='utf-8'?>");
	xmlWrap.push("<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>");
	xmlWrap.push("<soap:Body>");
	xmlWrap.push('<GetList xmlns="http://schemas.microsoft.com/sharepoint/soap/">');
	xmlWrap.push('<listName>' + listName + '</listName>');
	xmlWrap.push('</GetList>');
	xmlWrap.push("</soap:Body>");
	xmlWrap.push("</soap:Envelope>");
	result = {};
	$.ajax({
		async:false,
		type:"POST",
		url:L_Menu_BaseUrl + '/_vti_bin/lists.asmx',
		contentType:"text/xml; charset=utf-8",
		processData:false,
		data:xmlWrap.join(''),
		dataType:"xml",
		beforeSend:function(xhr){
			xhr.setRequestHeader('SOAPAction','http://schemas.microsoft.com/sharepoint/soap/GetList');
		},
		success:function(data){
			$('Field', data).each(function(i){
				if(result[$(this).attr('DisplayName')]===undefined || result[$(this).attr('DisplayName')]===''){
					result[$(this).attr('DisplayName')] = ($(this).attr('Description')===undefined)?'':$(this).attr('Description');
				}
			});
		}
	});
	return result;
}
</script>

If you like this solution, buy me a beer!

Alexander

4 Comments on “Show field description in list view column header – updated version

  1. Hello,

    Thanks for this amazing solution! This is exactly what I was searching for. Although I found a bug, it doesen’t show the description of an multi line text field column. Can you fix this?

    Thanks a lot.

    Cheers,
    Peter

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.