Share via


Document library view: Group by a column with multiple values

Question

Thursday, February 3, 2011 10:04 AM | 1 vote

I have a document library which has a managed metadata column.
I would like to create a view which groups the documents by this managed metadata column.
The managed metadata column can have multiple values.

I know that this is not possible with SharePoint's group by, since it only accepts those columns which can have only one single value.
But is this possible to accomplish by some other means, e.g. Content query web part? Or is there perhaps a 3rd party solution to this?
Is it possible to change the group by settings somehow to allow Group by to function with columns with multiple values? <- this may be far fetched...

All replies (5)

Wednesday, February 16, 2011 4:54 PM âś…Answered | 1 vote

Hi Pekch,

In relation to your thread here: http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010general/thread/04b2413b-5aeb-4b19-b5d8-07cbca44064a/#f301c900-9915-4ccd-b30f-5dd5d7c5534b

I don't believe you can group by the seperated values in a multi value column such as Managed metadata, but here are a few suggestions.

1) It's possible to build a custom web part, which provides this level of grouping.  So if your familiar with programming then you can go this route or its possible a 3rd party solution is available, but I couldn't find one.

2) This is most likely not what you want (as it doesn't use the content query web part as discussed in the thread mentioned above), but instead of going the group by method to display documents, you can try a "filter" method. 

I'm unsure if this is available in Foundation, but under the Document Libraries settings > General Settings, there is a link called Metadata navigation settings. 

In this form, your allowed to "Configure Navigation Hierarchies" which configures the navigation tree just under the left nav menu (only shows if your in the Document Library page).  Move your managed metadata field to the "Selected hierachy fields".  If your field doesn't show up, it's probably because your using the "Enterprise Keywords" field, which doesn't appear to be allowed here, instead you have to create a managed metadata column to have it show up in the list.  Once this is configured and your in the Document Library page (not a web part page), you'll notice a navigation tree to the left which will display a hierarachy of seperated metadata values. You can try it out, but as mentioned it may not fit your needs.


Thursday, February 17, 2011 10:15 AM

Hi there Raymond and thanks for the reply.

I think we'll have to go with the 1) solution and customize the web part ourselves.

Would you have any tips on what SharePoint API's are used to access document libraries and audience targeting?


Tuesday, February 22, 2011 7:21 PM

Hi Pekch,

I'm assuming you have VS2010 to build the custom web part. From there you will need to figure out the following:

  1. Get a SPList object for the Document Library (See below for code example)
  2. Loop through all the documents in the SPList object 
  3. If you have audience targetting enabled, then you'll need to determine if the user has access to the document by checking the "Target_x0020_Audiences" column)
  4. As you also want to group by metadata, you'll need to populate 2 datatables (one table with a column containing unique metadata values and another table with a metadata column and other document related columns).  Link these two tables via a dataset relation.
  5. Set the dataset as the datasource for a repeater, add in some css and javascript for the group expand/collaspe and it should be close to what you need.

This will be a time consuming task if you don't know where to start or have problems figuring out how to perform a certain operation.  So you may want to determine if the functionality you want is required or just a "nice to have".  Good luck and if I have some spare time, I'll create a blog post outlining how to do all the above.

 

I got the below code from a sharepoint blog sometime in the past and you can use it to retrieve a list.

You can use it like this: GetListByUrl(http://servername/Shared%20Documents/Forms/AllItems.aspx)

using    Microsoft.SharePoint;

public SPList GetListByUrl(string listURL)
{
 SPList list = null;

 try
 {
 using (SPSite site = new SPSite(listURL))
 {
  if (site != null)
  {
  // Strip off the site url, leaving the rest
  // We'll use this to open the web
  string webUrl = listURL.Substring(site.Url.Length);

  // Strip off anything after /forms/
  int formsPos = webUrl.IndexOf("/forms/", 0, StringComparison.InvariantCultureIgnoreCase);
  if (formsPos >= 0)
  {
   webUrl = webUrl.Substring(0, webUrl.LastIndexOf('/', formsPos));
  }

  // Strip off anything after /lists/
  int listPos = webUrl.IndexOf("/lists/", 0, StringComparison.InvariantCultureIgnoreCase);
  if (listPos >= 0)
  {
   // Must be a custom list
   // Strip off anything after /lists/
   webUrl = webUrl.Substring(0, webUrl.LastIndexOf('/', listPos));
  }
  else
  {
   // No lists, must be a document library.
   // Strip off the document library name
   webUrl = webUrl.Substring(0, webUrl.LastIndexOf('/'));
  }

  // Get the web site
  using (SPWeb web = site.OpenWeb(webUrl))
  {
   if (web != null)
   {
   // Initialize the web (avoids COM exceptions)
   string title = web.Title;

   // Strip off the relative list Url
   // Form the full path to the list
   //string relativelistURL = listURL.Substring(web.Url.Length);
   //string url = SPUrlUtility.CombineUrl(web.Url, relativelistURL);

   // Get the list
   list = web.GetList(listURL);
   }
  }
  }
 }
 }
 catch { }

 return list;
}

Wednesday, February 6, 2013 3:13 PM

Wish this was possible. It makes it difficult to suggest to people that they use managed metadata (which does bring with it some real benefits) when I have to tell them that if they want to Group By whichever info they'd be capturing they also have to capture it in something like a Choice field.

It is not sufficient to tell Site Owners to use Hierarchies. As soon as they hear that their Site Visitors will need to look somewhere else and use the left column navigation in conjunction with whatever grouping, sorting, filtering etc. they are accomplishing through the View parameters, it's over.

I wish one could Group By metadata columns in these ways:

  1. Unique Values (If multiple values permitted and existing, then 1 group per unique set of metadata values, presumably sorted or with some accommodation made to account for terms having been entered in varying order.)

  2. Individual Values (1 group per each term present, meaning that items may well show up in multiple Grouped sections if multiple terms are permitted for the given column.)


Tuesday, February 18, 2014 5:11 PM

Hi Raymond,

Did you ever get to blog about this more in detail?

I am working with SharePoint 2013 and having the same issue now...

Please advise and thanks for your help!