Last year, I published a sample script that changes the layout of boxed views from two columns to a single column.
Several readers reported that it didn’t work for them. Larry Pfaff investigated the issue, and came up with the following update:
<script type="text/javascript"> var boxedview = document.getElementById("WebPartWPQ1").innerHTML; boxedview = boxedview.replace(/<td width="1.5%"> <\/td>/gi,"<\/tr><tr style='font-size:6px\;'><td> <\/td><\/tr><tr>"); boxedview = boxedview.replace(/<td width="1%"> <\/td>/gi,"<\/tr><tr style='font-size:6px\;'><td> <\/td><\/tr><tr>"); boxedview = boxedview.replace(/<td> <\/td>/gi,"<\/tr><tr style='font-size:6px\;'><td> <\/td><\/tr><tr>"); document.getElementById("WebPartWPQ1").innerHTML = boxedview; </script>
To include the script in your page, use a CEWP placed below the boxed view.
The above script is written for wss v3. It identifies the Web Part by its id “WebPartWPQ1”. If you use MOSS, or if the boxed view is on a page along with other Web Parts (typically on the site home page), you’ll need to change the id to “WebPartWPQ2” or “WebPartWPQn“. Or you can modify the code to scroll through all the Web Parts on the page and grab the boxed views.
Larry’s update works for all boxed styles, while my initial code only worked against the “Boxed, no labels” style.
Remember that the purpose of this sample script is simplicity (5 lines!). It relies on the innerHTML property.
I am going to publish a more complete (and of course heavier) solution that will allow you to choose the number of columns.
About Larry:
“Larry Pfaff, Sr, Systems Analyst working for Convergys Corp, a global company, based out of Jacksonville Florida delivering training and outsourcing for major corporations. I have been working with SharePoint for almost 7 years and manage many internal projects using SharePoint as the collaboration tool. I enjoy new challenges and automating existing process. I seek out cookie cutter solution and mold them to fit for “Non-Developers” working with SharePoint by developing and providing training for end user and sharing my knowledge with as many as I can.”
Larry is a long time reader of my blog and other power user blogs, like EndUserSharePoint.com and SharePoint JavaScripts. While we were collaborating on a case study, in the past few weeks, Larry decided to take the plunge and start his own blog, SharePoint Hacker.
Pingback: Boxed views: one column only « Path to SharePoint
Pingback: SharePoint Kaffeetasse 171 - Michael Greth [SharePoint MVP] - SharePointCommunity
Thanks Christophe and thanks Larry.
I was one of those for whom it did not work. I’m happy now-
Charlie Epes
Pingback: uberVU - social comments
Pingback: Links (3/21/2010) « Steve Pietrek-Everything SharePoint/Silverlight
This is a great site for SharePoint developers. I’ve shared your site with others, and have used some of the suggestions myself. I have learned so much from you and look forward to attending one of your workshops. Thanks.
This works great now. Thank you.
Is anyone aware of a way to have a single CEWP script apply to multiple web parts, or must there be a CEWP for each web part (for single column boxed display)?
Kevin, you can group all the scripts in a single CEWP, or even create a loop that scans all the Web Parts in the page (WebPartWPQi). Just remember that the script must be placed below all the Web Parts you want to modify.
Can you work out a solution for SharePoint 2010? It does not seem to work with SP2010….
In order to make my single column really look like a form, I was wondering what script could I use to number the columns?
A simple…
1.
2.
3.
I would think this would be easy, but I’m finding nothing.
You talked of how you can write something that will scroll through all the web parts on the page, id the boxed ones, and apply this code. I’m not a script writer. Would someone add that to the script given above so I can copy and paste it into the CEWP on my page? Thanks.
Also, I’d like to add bold and color to some of the text fields in displayed in it such as the title. How is that done via the CEWP?
I am having a awful time making this work with a Web Part Page. Any suggestions?
Great solution – just too slow for my homepage I’m afraid.
Also, this doesn’t work with being able to edit in datasheet view – when I try this it throws the ActiveX error. I took out the javascript and then the datasheet view works fine. Any thoughts on a workaround?
Worked great but I added one more line which I think is important
boxedview = boxedview.replace(width=”50%”, width=”100%”);
Otherwise the one column shown just uses 50% of the webpart and looks a little weird.
Thanks for the line to expand the width, but I couldn’t get it to work. Adding it makes the boxed view revert to 2 columns. Does anyone have any suggestions to make the boxed view 1 column at 100% width of the webpart?
This worked WONDERFULLY!!! Thank you so much. Been trying to attack if from so many different angles.
Quick question…does anyone know of a way to hide the actual box?
Thanks for the work 🙂
A better ways to do this is with a style sheet:
table.ms-listviewtable > tbody > tr > td {
border: 1px solid transparent;
border-width: 1px 0px;
float: right;
width: 100%;
}
A stylesheet that displays table cells vertically? That is so disturbing…
Thanks for sharing this! I love this kind of outside of the box thinking 🙂
This is great, thank you! I was wondering if I could use it in a page layout, and instead of the web part ID use a div ID or the web part zone ID. I’ve tried just replacing it but that doesn’t seem to work – have you got any ideas?
Sorry, the code is specific to boxed views, and won’t help in another context.
Thanks Christophe. I’ve applied the CSS Mike B posted to a zone on my page layout, so now any boxed view added there will display in one column.
I wondered if anyone has tried moving the cells around within the table. I would like my user photos floated left and all text columns floated right, but I’m not having any luck!
Is it possible to do the same trick with the “document detailed view” of a document library?
Sebastian, what do you mean by “document detailed view”?
Hi Christophe,
I mean the “Document Details” View Style for the SharePoint 2010 Document Library.
(http://www.bfcnetworks.com/wp-content/uploads/2011/02/image18.png)
There are some different Styles then in the Lists.
Thanks for your help!
Well, something similar should work with the Document Details view, but I haven’t tried. This post was written for SP 2007, and with SP 2010 and 2013 Microsoft is offering other (and sometimes contradictory) options to tweak views.
Reblogged this on Nishant Rana's Weblog and commented:
Worked like a charm.