Update: boxed view with one column only

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%">&nbsp;<\/td>/gi,"<\/tr><tr style='font-size:6px\;'><td>&nbsp;<\/td><\/tr><tr>");
boxedview = boxedview.replace(/<td width="1%">&nbsp;<\/td>/gi,"<\/tr><tr style='font-size:6px\;'><td>&nbsp;<\/td><\/tr><tr>");
boxedview = boxedview.replace(/<td>&nbsp;<\/td>/gi,"<\/tr><tr style='font-size:6px\;'><td>&nbsp;<\/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.

27 thoughts on “Update: boxed view with one column only

  1. Pingback: Boxed views: one column only « Path to SharePoint

  2. Pingback: SharePoint Kaffeetasse 171 - Michael Greth [SharePoint MVP] - SharePointCommunity

  3. Thanks Christophe and thanks Larry.
    I was one of those for whom it did not work. I’m happy now-

    Charlie Epes

  4. Pingback: uberVU - social comments

  5. Pingback: Links (3/21/2010) « Steve Pietrek-Everything SharePoint/Silverlight

  6. 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)?

  7. 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.

  8. 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.

  9. 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?

  10. 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?

  11. 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?

  12. 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 stylesheet that displays table cells vertically? That is so disturbing…

      Thanks for sharing this! I love this kind of outside of the box thinking 🙂

  13. 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?

      • 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!

  14. Is it possible to do the same trick with the “document detailed view” of a document library?

Comments are closed.