Adding a Tabbed View to A Web Part Page Using jQueryUI

Sometimes I work on something and blindly stumble into a neat trick. The other day I was trying to figure out how to reliably add a tabbed view to a SharePoint Web Part Page. I was working in SharePoint Designer, so I had total freedom to try whatever I wanted.

The idea was to show a set of tabs, each of which could contain at least a Content Editor Web Part (CEWP) initially. We wanted it to look something like this:

Tabs Mock UpAside: Wireframes drive me a little batty because they turn into the goal rather than just a useful development tool. Mock ups like this using something like Balsamiq make far more sense to me. The Comic Sans makes it very clear to everyone that this is the basic idea, and we’re not talking about pixel placement.

My first thought was of course to use Christophe Humbert’s most excellent Easy Tabs, but for some reason that wasn’t working in the page. Since we’re already using jQueryUI for some other things – this is a highly customized environment – I figured that it would be a good alternative and would probably give me more control of the display.

If you look at the jQueryUI documentation, you’ll see that there is some specific markup required to get the .tabs() widget to function:

<div id="tabs">
   <ul>
      <li><a href="#tabs-1">Nunc tincidunt</a></li>
      <li><a href="#tabs-2">Proin dolor</a></li>
      <li><a href="#tabs-3">Aenean lacinia</a></li>
   </ul>
   <div id="tabs-1">
      <p>Tab 1 content</p>
   </div>
   <div id="tabs-2">
      <p>Tab 2 content</p>
   </div>
   <div id="tabs-3">
      <p>Tab 3 content</p>
   </div>
</div>

Once you have that basic markup in place, you can make this simple call to activate the tabs:

$("#tabs").tabs();

There are multiple options, of course, but that gets you the basics.

I tried a number of things, but the main difficulty I had was that Web Part Zones cannot contain markup; they can only contain Web Parts. SharePoint Designer strips out any markup that you add manually inside a Web Part Zone.

Somehow I thought of trying to wrap the Web Part Zone with the markup I needed to make the tabs work instead. Even better, each tab could have its own Web Part Zone so that we could edit existing Web Parts and add new Web Parts to the tabs at will. That markup ended up like this:

<div id="team-tabs">
  <ul>
    <li><a href="#tabs-how-we-help">How we can help</a></li>
    <li><a href="#tabs-case-studies">Case studies</a></li>
    <li><a href="#tabs-projects">Current projects</a></li>
    <li><a href="#tabs-applications">Applications we support</a></li>
  </ul>
  <div id="tabs-how-we-help">
    <WebPartPages:WebPartZone runat="server" Title="loc:HowWeHelp" ID="HowWeHelp" FrameType="TitleBarOnly"><ZoneTemplate>
    </ZoneTemplate></WebPartPages:WebPartZone>
  </div>
  <div id="tabs-case-studies">
    <WebPartPages:WebPartZone runat="server" Title="loc:CaseStudies" ID="CaseStudies" FrameType="TitleBarOnly"><ZoneTemplate>
    </ZoneTemplate></WebPartPages:WebPartZone>
  </div>
  <div id="tabs-projects">
    <WebPartPages:WebPartZone runat="server" Title="loc:Projects" ID="Projects" FrameType="TitleBarOnly"><ZoneTemplate>
    </ZoneTemplate></WebPartPages:WebPartZone>
  </div>
  <div id="tabs-applications">
    <WebPartPages:WebPartZone runat="server" Title="loc:Applications" ID="Applications" FrameType="TitleBarOnly"><ZoneTemplate>
    </ZoneTemplate></WebPartPages:WebPartZone>
  </div>
</div>

This markup gives us this nice UI. I’ve blurred out the specific content in the CEWP, but you should get the idea.jQueryUI Tabs Example

The really nifty thing about all of this is that editing the content of each Web Part Zone seems to work just fine in the context of each tab. In other words, not only do we get the user experience (UX) goodness from the tabs for the end user, we also get it for the few people who will be editing the tab content.

Editing Web Part Zone Content

88 Comments

  1. I love jQueryUI and this is a reallly elegant application. I hadn’t thought to use tabs to contain web parts or web part zones, but it’s really nice to know that it can be done.

    Reply
  2. Hey Marc,
    Do you think it would be possible to use jquery UI to ‘Tabify’ a DVWP. I’m thinking if I had a dataview that was grouped by a collumn –lets say category– to have the categories appear as tabs in the dataview.

    Any ideas?
    Russell

    Reply
  3. Hi, I used the jQuery UI last week to do just that for a project. Have you tried inserting a Calendar view web part? It seems to break my setup, but I haven’t quite figured out why.

    cheers,

    Reply
      • There’s actually an issue with calendar views in SharePoint (not sure if this is what Ingeborg is referring to). Calendar views are made of two layers – the dates and the events – and these two layers don’t stay together when you resize the views, or toggle the display.

        Reply
  4. Marc, I just came across your post. The link to the Easy Tabs is an old one (pre-SP 2010), and that’s certainly the reason why it was not working for you.

    Setting tabs at the Web Part zone level is something I’ve also done in the past, and it works seamlessly. You can even take it one step further and create a two level tabbed interface – one tab per zone, then one tab per Web Part!

    Reply
    • Christophe:

      Great to hear from you after such a long time! Sorry about the old link to EasyTabs. I looked all over for the right version and that’s what I found. You might want to add some cross links to whatever other locations you have so that simpletons like me don’t end up with the wrong version.

      M.

      Reply
  5. Hello Christophe,

    Would you please elaborate on two level tabbed interface with one tab per zone then one tab per web part. As of now I use EasyTab v5 for one level only. Thank you very much.

    Regards,

    HN

    Reply
  6. Hi Marc,

    this is a very nice blog and i have been reading your blogs continuously.

    my query is not related to this blog , my query is related about data view webpart, actually one of my clients wants paging in data view web part similar to spgridview. so is this feasible that we can have paging in data
    view web part similar to spgridview and if it is possible then how?

    Thanks,

    Gaurav

    Reply
    • Gaurav:

      DVWPs are XSL-driven, so you can build pretty much anything you want. There are multiple ways to do paging, depending on the expected number of items, etc.

      In the future, rather than posting a question to a random post, consider using one of the excellent SharePoint-based forums out there.

      M.

      Reply
  7. I am creating a aspx page from sharepoint designer 2010.I am keeping the js and css reference from a doc lib .But i am not seeing any tab niether the webpart zone.Plz tell if my approach is correct

    Reply

Have a thought or opinion?