Tuesday, August 25, 2009

Change SharePoint 'Document library/List' Column width

Sometimes we need to change default column width of document library/list.To change sharepoint document library/list column we need to add a content editor webpart on that perticular page and need to write below code as javascript script. (use below code within javascript tag)

_spBodyOnLoadFunctionNames.push("ModifiyCommentWidth");
function ModifiyCommentWidth() {
for (var i = 0, l = document.getElementsByTagName("TH").length; i < l; i++) { var thisTH = document.getElementsByTagName("TH")[i]; if (thisTH.className == 'ms-vh2-nograd') { if (thisTH.innerText == 'Comments') {
thisTH.style.width = "300px";
}
}


Please ensure tag name before use this line of code because this is not same for all. This is working in my case but you need to update tag names accordingly.

No comments:

Post a Comment