{"id":1565,"date":"2014-12-07T22:26:14","date_gmt":"2014-12-08T03:26:14","guid":{"rendered":"http:\/\/www.a2life.info\/w\/?p=1565"},"modified":"2021-09-11T16:21:19","modified_gmt":"2021-09-11T20:21:19","slug":"hiding-sharepoint-list-column-from-list-view","status":"publish","type":"post","link":"https:\/\/www.a2life.info\/w\/?p=1565","title":{"rendered":"Hiding SharePoint list column from list view"},"content":{"rendered":"<p>This article is about a JavaScript snippet that hides a specific column from a SharePoint list view. If I google this subject, most of the articles found on the Internet is about hiding a specific column from new, display or edit form. Although Javascript can do this, you can do the same thing without use of JavaScript by enabling list content-type as well. <a title=\"See here\" href=\"http:\/\/blogs.interfacett.com\/creating-hidden-columns-in-sharepoint-2010\">See here.<\/a><\/p>\n<p>Not many articles talks about hiding columns from the list view though. (<a title=\"Toggling SharePoint list columns\" href=\"http:\/\/spjsblog.com\/2010\/04\/18\/toggle-column-visibility-in-list-view\/\">This one is an exception<\/a>)<br \/>\nThe link above shows the solution for toggling the particular columns. I only needed to hide a column from the list. But why do I even want to do that when one can simply create a view without that specific column you don&#8217;t want to see?<br \/>\nThe reason is that I want to show the list based on filtered value from the column in question. I can add the filter webpart that I can connect to the target list, then specify the column to which the filter webpart will be connected to. In another word, for the filter to work, the column need to be a part of the list view (This is no longer the case with SharePoint 2013 or SharePoint online. \u00a0See below). Since the column will always show the same value for all displayed items(filtered value) I want to hide this column. If your company allows the use of SharePoint Designer, then you can use the Dataview webpart where you can use the column that is not shown to filter the items list. But Dataview creation and editing requires SPD. I wanted a easier solution, hence this javascript snippet.<br \/>\n<code><\/code><\/p>\n<pre>if (typeof jQuery === 'undefined') { throw new Error('hide column snippet requires jQuery') }\r\n\r\n\/\/This function gets targetTable object and columnindex to hide\r\n\/\/targetTable is a jQuery object with single element.\r\nfunction doHideColumn(targetTable,col) {\r\n    targetTable.find(\".ms-viewheadertr &gt;*[class^='ms-v']\").eq(col).hide();\r\n    targetTable.find(\" &gt;tbody &gt;tr\").each(function(){$(this).find(\"&gt;td:eq(\"+col+\")\").hide();});\r\n}\r\n$(function() {\/\/this hide the colName column from all table in the page\r\n    var    colName=\"colToHide\";\r\n    var    tarray=$(\"tr.ms-viewheadertr th:contains('\"+ colName +\"')\");\r\n    var    tlength=tarray.length;\r\n    var    colindex;\r\n    for (var i=0; i&lt;tlength; i++) {\r\n        colindex=$(tarray[i])[0].cellIndex;\r\n        doHideColumn($(tarray[i]).closest('.ms-listviewtable'), colindex);\r\n    }\r\n});\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><code><\/code><br \/>\nThis code snippet requires jQuery. You can use content editor Web Parts (CEWP) to include this code (don&#8217;t forget to wrap the code with script tag.) It works with SP2007 (My office&#8217;s current version) I may need to look at the code again when our IT upgrades the server to either 2013 or O365. \u00a0*Edit* \u00a0On SharePoint 2013 and SharePoint online filter can be applied to any list column regardless of if the target liist view contains the filtered column. \u00a0Therefore, solution explained here is unnecessary. *end Edit *<br \/>\nThe code above scans the entire page for column headers with &#8220;colToHide&#8221; name and hide the column. (or columns if there are multiple lists in the page and if they contains the column with same name)<br \/>\nSince this code uses jQuery array object to hold the column information, it wont be difficult to modify the code to accept more than one column names to hide multiple columns from single list. For now, this snippet achieves what I need.<\/p>\n<p>Filter Web parts are nice. For instance, URL query web parts let me create a page that contents are based on the filtered value in url query. For instance,<br \/>\nhttp:\/\/projectpage.aspx?projphase=1<br \/>\nhttp:\/\/projectpage.aspx?projphase=3<br \/>\nboth link goes to the same page but the first link will show project phase 1 list items where the next link will show project phase 3 list.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article is about a JavaScript snippet that hides a specific column from a SharePoint list view. If I google this subject, most of the articles found on the Internet is about hiding a specific column from new, display or edit form. Although Javascript can do this, you can do the same thing without use of JavaScript by enabling list content-type as well. See here. Not many articles talks about hiding columns from the list view though. (This one is an exception) The link above shows the solution for toggling the particular columns. I only needed to hide a column from the list. But why do I even want to &hellip; <a href=\"https:\/\/www.a2life.info\/w\/?p=1565\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48,30],"tags":[33,59],"class_list":["post-1565","post","type-post","status-publish","format-standard","hentry","category-programming","category-sharepoint","tag-jquery","tag-sharepoint"],"_links":{"self":[{"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=\/wp\/v2\/posts\/1565","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1565"}],"version-history":[{"count":12,"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=\/wp\/v2\/posts\/1565\/revisions"}],"predecessor-version":[{"id":1568,"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=\/wp\/v2\/posts\/1565\/revisions\/1568"}],"wp:attachment":[{"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}