6/10/2009

SharePoint: Hide List and Library Column Headings

 

Updated 1/13/2012 with notes for SharePoint 2010

A 2013 version of this article is available here: http://techtrainingnotes.blogspot.com/2015/07/sharepoint-2013-hide-list-and-library.html

I had a request for hiding the column headings of a list displayed in a web part. First thought was the toolbar, but they were asking about the clickable column headings. I think they were wanting to make a page look more like a regular web page instead a page full of lists. By the way this makes for a better way to display a view with only one column…

Note: This will of course remove the ability of the site visitor to sort and filter the web part.

Note: This will also work right in the view page (view pages use web parts!), but in SharePoint 2010 adding a web part to a view page will change how the ribbon gets displayed and will remove the View dropdown menu from the title area crumb trail.

 

Before (2007):

image

After (2007):

image

 

Before (2010):

image

After (2010):

image

Note: after this customization the checkbox column disappears, at least until you mouse over a document. Bug? I think it’s a bonus!

 

Steps:

  • Add your web part for the list to a page
  • For a minimal look set the toolbars to “none”
  • Below this web part add a Content Editor Web Part (CEWP)
    • Modify the CEWP and use the Source Editor button
    • Copy an paste the JavaScript below
    • If the CEWP displays it’s title bar then in the Appearance section set the Chrome to “none”
  • Or (preferred for SP 2010 other than view pages)
    • Copy the JavaScript to a Notepad file (name it something like “HideHeading.html”) and upload this file to a library
    • In the library where you uploaded this file, right-click this file and copy it’s shortcut / url
    • Below your web part add a Content Editor Web Part (CEWP)
    • Modify the CEWP and paste the URL copied above into the Content Link box
    • Save your changes
  • Or (for SharePoint view pages)
    • Edit the view page in SharePoint Designer
    • Copy and paste the Javascript to just before the end tag for PlaceHolderMain (just before </asp:Content>)
  • If you want to hide the column headings of multiple web part modify the IF statement like this Three web parts

Web part summary name!

In SharePoint 2007, the summary name is usually just the list’s name: “Shared Documents”.

In SharePoint 2010, the summary name is usually the list’s name PLUS the list’s description. For example the default for Shared Documents is: “Shared Documents Share a document with the team by adding it to this document library.”  (including the period)

To find the correct name use your browser’s View Source option to display the HTML of the page and search for “summary=” and copy the text that follows.

    <table summary="Shared Documents Share a document with the team by adding it to this document library."

The JavaScript

 

Need to change multiple web parts?

Two web parts:
             if (x(i).summary=="Tasks" | x(i).summary=="Shared Documents"
Three web parts:
             if (x(i).summary=="Tasks" | x(i).summary=="Links" | x(i).summary=="Shared Documents"

The JavaScript

<script type="text/javascript"> // CEWP trick from techtrainingnotes.blogspot.com!

// techtrainingnotes.blogspot.com/2009/06/sharepoint-hide-list-and-library-column.html // Hide column headings in web parts //Find the list (change "Shared Documents" to your web part's name) var x = document.getElementsByTagName("TABLE"); // find all of the Tables var i; var y; for (i=0;i<x.length;i++) { if (x[i].summary=="Shared Documents") //find the table with this name { y = x[i].getElementsByTagName("TR"); y[0].style.display="none"; //hide the first row } } </script>

 

 

.

29 comments:

Naresh said...

Hi Mike,
I tried your code but I am not getting any luck in hiding the columns. I even coded an alert to display the value of x(i).summary but it always returns a blank:

alert("summary: " + x(i).summary);

is there anything missing from the code? Any help would be appreciated.

Mike Smith said...

Naresh,

Are you using Firefox? If so, change:
x(i) to x[i]
and
y(0) to y[0]

This will work in both IE and Firefox.

Mike

Rich said...

Thanks for the post Mike, it worked great. Two key points for any folks having problems with the code:

1) as stated, the CEWP with the code must be placed after the list/library CEWP
2) the code must contain the underlying table name not the CEWP name in the case where you rename your list/library CEWP as I did ;)

Cheers

Tripwire said...

You could also just add the following to your CSS override file.

/* Hide columns on doc lib */
#onetidDoclibViewTbl0 {display:none}

Similar ID secletors are available for all list types.

Mike Smith said...

Tripwire,

Thanks! That works too.

The style ID approach is not selective and removes the heading from all similar web parts using the same ID (i.e. all document, form and wiki web parts). The JavaScript approach can be targeted to a single web part.

Both have an advantage depending on what's needed. (the more tools in the tool box the better)

Mike

ameng said...

Hi,
I just cannot figure it out for the name of the CEWP or table. I want to hide the column title for ~/forms/allitems.aspx . Anybody can helps me..

Mike Smith said...

ameng,

This will work for both web parts and the actual edit page (allitems.aspx).

Go to your SharePoint page and use the browser's "view source" command. Do a search for "summary=" and look for your web part's name.

As an example the task list HTML would have:

summary="Tasks"

Also make sure the Content Editor Web Part is added below the web part you want to change.

Mike

Walter said...

This worked for me in 2007 but haven't had any luck with 2010.

Mike Smith said...

Walter,

I have updated the article to include notes for SP 2010. The most likely problem is how the web part is named. (summary="name")

Mike

Rudy said...

Thanks fo rthis post! Just thought you should know that this worked in SP 2003 for me.

Rudy

K said...

Hi, this is exactly what I need to do, but you say Modify the CEWP and use the Source Editor button - I can't find the Source Editor button. I've gone into the Edit the Web Part section but still can't find it. I'm sorry to be stupid but I'm just not as familiar with this as I'd like to be. Btw, I'm using SharePoint 2010.
Thanks
K

Mike Smith said...

K,

SP 2010 does not have that button. Follow the steps in the "Or (preferred for SP 2010 other than view pages)" bullet or the "Or (for SharePoint view pages)" bullet in the steps above.

Mike

Umar said...

This is Great , just one advise for the users who follow this , make sure you go to view source and get web part name from there , if you have a single space after the web part name it will show up there and code will not work if you will not add space in the code

Anonymous said...

I have found that this code works on my view (I am Site Collection Admin) but not on other's view (View Only access). The column headings appear on their page. Here is the code I am using per your post:

'open script'
// CEWP trick from techtrainingnotes.blogspot.com!// techtrainingnotes.blogspot.com/2009/06/sharepoint-hide-list-and-library-column.html
// Hide column headings in web parts

//Find the list (change "Shared Documents" to your web part's name)
var x = document.getElementsByTagName("TABLE"); // find all of the Tables
var i;
var y;
for (i=0;i<x.length;i++)
{
if (x(i).summary=="Resources Public resource links available for everyone in the firm" | x(i).summary=="Resources - RiskPro " | x(i).summary=="News Public news stories") //find the table with this name
{
y = x[i].getElementsByTagName("TR");
y[0].style.display="none"; //hide the first row
}
}
'close script'

Any suggestions on how fix that? FYI - I do not have access to SharePoint Designer. So I am only working with native SP2010 functionality.

Thanks,
LC

Mike Smith said...

LC,

Where did you put the JavaScript? Directly in the CEWP or in a linked file stored in a library? If in a linked file, do the view only users have view permissions to the library?

Is the page with the web part stored in a library ("/pages" etc)? If so, is the file checked out to your?

Mike

--Renate-- said...

Hello,
It didnt work for me. I have Norwegian language so when I search for table summary it says "Fellesdokumenter". I have tried to put it in the code but it will not work.
I have SP2010.

Mike Smith said...

Renate,

Take a look at "Web part summary name" above. Make sure that you include any extra spaces or periods in the Summary text.

Mike

Anonymous said...

Hi Mike,

Great article, just what I've been looking for. I'm using SP2010 and have uploaded a html file with the code. Problem is I can't find "Content Link" you are referring to where the URL should go in CQWP.

Would appreciate if you could clarify in what section in CQWP the url to the html file should go.

Thank you!
Henrik

Mike Smith said...

Henrik,

It's the CEWP (Content Editor) not the CQWP (Content Query).

Add the CEWP, click its dropdown menu and click Edit. In the properties panel at the far right of the page you will find the box for the link.

Mike

kathy said...

How can I find the web part summary name in SP2013?

Mike Smith said...

Kathy,

Some of the content in a 2013 page is delay loaded, so View Source may not find all of the HTML. If using Internet Explorer, press F12 to display Developers Tools, then use its search features to find "source=".

Mike

Marcelo Marques said...

It works very well in Sharepoint 2013, thanks!

Anonymous said...

For those who want a simple solution to hide only the column headers of document library web parts just put this somewhere in a content editor html code:

\
#onetidDoclibViewTbl0 {
DISPLAY: none
}\

other solutions presented didn't work as good as this solution

Neel said...

How should we do this in SharePoint 2013?

Rita said...

Thanks! Worked perfectly first try!

Anonymous said...

Doesn't work in SP2013 because:
http://paulryan.com.au/2014/script-editor-runs-javascript-edit-mode/

Anonymous said...

This was very helpful, and I was able to get this to work. Thank you!

Like others mentioned, make sure to account for any extra spaces in the Table Summary name.

However, I am running into problems with a grouped list on SP 2010 (expanded by default) where the first grouping collapses, while the others stay expanded. I want the whole list to be expanded. When I refresh the page, the list tries to expand, and then the first grouping collapses. Any suggestions? Thanks!

Mike Smith said...

For SharePoint 2013...

If you have problems with the script in a Content Editor Web Part, use the options listed above named "Or (preferred for SP 2010 other than view pages)" or "Or (for SharePoint view pages)"

Mike Smith said...

A 2013 version of this article is now available: http://techtrainingnotes.blogspot.com/2015/07/sharepoint-2013-hide-list-and-library.html

Mike

Note to spammers!

Spammers, don't waste your time... all posts are moderated. If your comment includes unrelated links, is advertising, or just pure spam, it will never be seen.