EndUserSharePoint 2010 » Brandon Anderson http://www.endusersharepoint.com/EUSP2010 Just another WordPress weblog Tue, 26 Jun 2012 13:21:30 +0000 http://wordpress.org/?v=2.9.2 en hourly 1 How to Expand/Collapse Web Parts in SharePoint Using jQuery http://www.endusersharepoint.com/EUSP2010/2010/03/24/how-to-expandcollapse-web-parts-in-sharepoint-using-jquery/ http://www.endusersharepoint.com/EUSP2010/2010/03/24/how-to-expandcollapse-web-parts-in-sharepoint-using-jquery/#comments Wed, 24 Mar 2010 14:07:29 +0000 Brandon Anderson http://www.endusersharepoint.com/EUSP2010/?p=71 This entry is part of a series, Using jQuery and Web Parts»

Guest Author: Brandon Anderson

I was recently challenged with creating a web part zone in a page layout in which for every web part added to it, that web part took on expand/collapse functionality. The idea is that on the home page for this particular SharePoint site, users can add RSS feeds. Each of the RSS feeds is a web part, and each has many individual feed items. With the number of feeds and feed items open for modification, the information architect thought it best to collapse each feed web part by default and allow the user to expand and collapse the feed web parts as they desire.

To do this I needed to understand the HTML structure of web parts in SharePoint 2010 and write jQuery and CSS that would add the functionality and look-and-feel we were looking for. Here is the result:


Below is the jQuery script I wrote for the web part expand/collapse (or accordion) functionality.

function expandCollapseWebPartsInZone() {
$(".expandCollapseWebPartsInZone td.ms-WPHeaderTd").addClass("expandCollapseHead");
$(".expandCollapseHead").parent().parent().parent().parent().parent().parent().parent()
.addClass("expandCollapse");
$("table.expandCollapse .ms-WPBody").parent().parent().addClass("expandCollapseBody");
$(".expandCollapseWebPartsInZone .expandCollapseHead").click(function() {
var headParentRow = $(this).parent().parent().parent().parent().parent();
if($(headParentRow).next("tr.expandCollapseBody").hasClass("expanded")) {
$(this).removeClass("expanded");
$(headParentRow).next("tr.expandCollapseBody").removeClass("expanded");
}
else {
$(this).addClass("expanded");
$(headParentRow).next("tr.expandCollapseBody").addClass("expanded");
}
return false;
});
}

This article was originally published on the Ironworks Consulting blog Fit & Finish.

Guest Author: Brandon Anderson

Brandon Anderson is a SharePoint user interface and look-and-feel specialist.  He brings over 10 years experience with front-end web development to SharePoint implementations requiring customized branding. For the past 3 years, Brandon has worked extensively with the UI customization of SharePoint properties, both public and restricted-access, for clients of various sizes and industries.  Brandon is the lead Microsoft SharePoint front-end developer for Ironworks Consulting (www.ironworks.com) and hosts the blog SharePoint Putty (sharepointputty.com), where he writes about the user interface customization of SharePoint.

Entries in this series:
  1. How to Expand/Collapse Web Parts in SharePoint Using jQuery
Powered by Hackadelic Sliding Notes 1.6.4
]]>
http://www.endusersharepoint.com/EUSP2010/2010/03/24/how-to-expandcollapse-web-parts-in-sharepoint-using-jquery/feed/ 3