woensdag 5 december 2012

SharePoint list view group by content type

By default it’s not possible to group your list items by contenttype. After some research on internet I founded a solution on codeplex:

SharePoint 2010 ViewEdit Group By Content Type

Actually it’s nothing more than adding some javascript with a script link to each page.

Add the following js code to a separate file (I called it ListViewEdit.js)

Code Snippet
  1. _spBodyOnLoadFunctionNames.push("jbCTFix");
  2.  
  3. function jbCTFix() {
  4.     jbCTKludge('idGroupField1');
  5.     jbCTKludge('idGroupField2');
  6. }
  7. function jbCTKludge(selName) {
  8.     var sel = document.getElementById(selName);
  9.     if (sel) {
  10.         if (sel.selectedIndex >= 0) {
  11.  
  12.             var o = document.createElement('option');
  13.             o.text = 'Inhoudstype';
  14.             o.value = 'tp_ContentType';
  15.  
  16.             var prev = sel.options[sel.selectedIndex];
  17.             try {
  18.                 sel.add(o, prev);
  19.             }
  20.             catch (ex) {
  21.                 sel.add(o, sel.selectedIndex);
  22.             }
  23.         }
  24.     }
  25. }

Add a custom action to add the scriptlink on each page in SharePoint


Code Snippet



  1. <?xml version="1.0" encoding="utf-8"?>

  2. <Elements xmlns="http://schemas.microsoft.com/sharepoint/">

  3.   <CustomAction Id="Ribbon.Library.Actions.Scripts"

  4.               Location ="ScriptLink"

  5.               ScriptSrc="~site/_layouts/VMW_Intranet/js/ListViewEdit.js" />

  6. </Elements>




Deploy the solution and enjoy the group by content type!

Geen opmerkingen:

Een reactie posten