Turn summary link web part into an accordion
In SharePoint the summary link web part is a great tool to create overviews made of internal and external links. The challenge with this web part is to enhance the presentation when a lot of links will be added to this web part. In this post I will present how to turn this basic web part to an accordion which gives the user a much better experience.
Styling the summary link web part
First of all I created a simple summary link web part and added grouping of those links. As you see the amount of links are not that much but enough that specific links are hard to read and find the belonging groups as well.
To enhance the default style I simply added a content editor web part to the page that contains my new style definition. To improve the group header I simply added a style definition for the CSS class “groupheader”. I also added some styling for the links as well.
.groupheader{
background-color: #0072C6;
color: white;
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
font-size: 140%;
padding: 0.5em;
padding-left: 0.75em;
margin-right: 0.5em;
margin-bottom: 1px;
}
.groupmarker:hover .groupheader{
cursor: pointer;
background-color: #0597FF;
}
.dfwp-list{
background-color: #0072C6;
margin-bottom: 0.5em;
margin-right: 0.75em;
}
.dfwp-list .item:hover{
background-color: #0597FF;
}
.dfwp-list .link-item a{
margin-left: 2em;
color: white;
}
The style definitions transform the web part now into a metro styled web part. For the user experience I also added a hover effect using CSS. This allows to highlight the currently selected link.
Add accordion script
The turn this web part now into a fully functional accordion all that needs to be done is to add a simple Jquery script the performs the following tasks.
- Hide all hyperlinks in the groups
- When a user clicks a group header
- Hide all sections that is not the current header
- Expand current selected link section
This can be accomplished with the following code.
$(document).ready(function(){
/* Slide up all link items and hide them */
$(".dfwp-list").slideUp("fast");
/* Binding a click event handler to the links: */
$('.groupheader').click(function(e){
/* Finding the drop down list that corresponds to the current section: */
var dropDown = $(this).next(".dfwp-list");
/* Closing all other drop down sections, except the current one */
$('.dfwp-list').not(dropDown).slideUp('slow');
dropDown.slideToggle('slow');
/* Preventing the default event (which would be to navigate the browser to the link's address) */
e.preventDefault();
})
})
Now the web part has turned into an accordion with expandable sections, but there is one last step to do. The accordion is currently not editable but this can be fixed with a simple modification of the script.
Make accordion editable again
SharePoint has something called display mode. This display mode indicates how a user has opened a page and can have the following values:
- Browse – indicates that the user views the page
- Design – indicates that the user tries to edit the page
Normally this form context or display mode is use is web part development but it could be used and detected using Jquery. SharePoint renders a hidden input field with the id ”MSOSPWebPartManager_DisplayModeName” that will be set to the appropriate value.
For example the field can look like this if the page is opened in browse mode.
<input type="hidden" name="MSOSPWebPartManager_DisplayModeName" id="MSOSPWebPartManager_DisplayModeName" value="Browse" />
To restore the edit function all that needs to be done is to wrap the script and let it only get executed in browse mode.
$(document).ready(function(){
// Detect if user view or edit the page
if($("#MSOSPWebPartManager_DisplayModeName").val() == "Browse"){
// Register accordion
accordion();
}
})
var accordion = function(){
/* Do fancy easing */
$.easing.def = "easeOutBounce";
/* Slide up all link items and hide them */
$(".dfwp-list").slideUp("fast");
/* Binding a click event handler to the links: */
$('.groupheader').click(function(e){
/* Finding the drop down list that corresponds to the current section: */
var dropDown = $(this).next(".dfwp-list");
/* Closing all other drop down sections, except the current one */
$('.dfwp-list').not(dropDown).slideUp('slow');
dropDown.slideToggle('slow');
})
}
The last thing I want to show is the accordion live in action.
Download Accordion Content Editor Web Part - SharePoint 2007 / SharePoint 2010


Sheral commented at 24. January 2013 at 15:44
This worked great. I changed the color easily by just editing the color code to match our branding colors.
Is there a setting that would allow for the Expand All/Collapse All function? I’m new to jQuery and would love to add that functionality to the Accordion for our page.
Thanks,
Sheral
Stefan Bauer commented at 24. January 2013 at 16:31
Actually there is no setting right now for that. What you might can do is to add a separate html form editor web part above that triggers the expand/collaps all. I can provide you the code for that later today.
Sheral commented at 24. January 2013 at 16:37
If you could post code for the separate web part to trigger the expand/collapse that woudl be great. Your code has saved me a ton of time and provides the visual bells and whistles which allowed me to concentrate on the functionality
Chris commented at 29. January 2013 at 06:41
Thank you for sharing this. It works great.
Steve Connelly commented at 29. January 2013 at 23:03
I am having trouble stringing the pieces together. Plus the code in the video does not look quite like the code in your examples abobe.
Can you string all the pieces together as they should look?
Thanks much,
Steve
Stefan Bauer commented at 30. January 2013 at 01:37
Hi Steve,
have you downloaded the web part below the videos?
Kind regards
Stefan
Steve Connelly commented at 30. January 2013 at 15:27
Good morning sir, thanks for the swift reply.
No, I had not downloaded your web-part; I had been trying to work with your code in a regular Content Editor web-part.
Please forgive my ignorance; I am still fairly new at this. Please tell me; now that I have downloaded your web part, what do I need to do with it? Do I need to have my SharePoint Admins upload it for me or is this something I can work with from within my Team Site?
Almost forgot, does it matter if I am working in MOSS 2007?
Best regards,
Steve
Stefan Bauer commented at 31. January 2013 at 10:07
Hi Steve,
you are not able to use it in SharePoint 2007 because the content editor part i used have been exported from SharePoint 2010. I updated the download link above to support both versions. SharePoint 2010 and SharePoint 2007.
If you download again you will now get both versions. I hope the 2007 work for you because i haven’t had a chance to test it.
To import the web part you need to follow the instruction on this page: http://community.bamboosolutions.com/blogs/sharepoint_blank/archive/2009/01/08/how-to-export-amp-import-web-parts-in-sharepoint.aspx
Kind regards
Stefan
Richard Ndagijimana commented at 31. January 2013 at 10:56
Hi Stefan, Thanks so much, it really worked for me
Steve Connelly commented at 31. January 2013 at 14:38
Thanks a ton Stefan,
I will let you know how it works out.
Steve
Steve Connelly commented at 31. January 2013 at 15:03
Good morning again Stefan,
So, I proceeded as instructed; this all seemed very straight-forward and un-complicated.
The results however are exactly the same as I have gotten with every other try. I get the style changes to the headers and links, but none of the accordion affect. So my links list is prettier, but no change in function.
Examining the code in the web-part, it is identical to the code I pieced together from your article and applied in my own content-editor web-part. That does answer one question at least; it appears that I was assembling the pieces correctly.
So the question now is, is SP 2007 the problem.
Thoughts?
Steve
Stefan Bauer commented at 31. January 2013 at 15:28
Hi Steve
yes it is possible that it’s a SharePoint 2007 problem or you are not allowed to access the jquery library. What you can try to do is to open the browser and try to access the following links:
http://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js
http://code.jquery.com/jquery-1.7.2.min.js
I can try the SharePoint 2007 web part later on one of my old SharePoint 2007 VM to find what the problem is.
Greetings
Stefan
Steve Connelly commented at 31. January 2013 at 15:36
Yes, I can access/download these scripts. I can do the same for the original locations in the web-part too. We use jquery scripts for a number of SP tools.
I have even tried downloading the scripts to a library in the same site collection and referencing them that way in the script.
Still no-go.
Still
Stefan Bauer commented at 31. January 2013 at 15:48
OK let me check this on one of my SharePoint 2007 Servers in a couple of hours.
Sham commented at 28. March 2013 at 13:19
Hi Steve,
This worked great for me! Thanks a lot! A quick question to ask. By using accordion script is there any ways to display the links in a summary link webpart in a Horizontal Manner?
Stefan Bauer commented at 29. March 2013 at 00:50
Do you like to have the groups horizontal or how you like to the the summary link web part horizontal?