SharePoint 2007 had a commonly used feature that enabled users to create views on lists that grouped by Content Type.
For some reason, this feature was removed from the user interface in SharePoint 2010.
Solution 1: The Easy Method
If you wish to do this today, you can do this using SharePoint Designer to create a view and then change the Xsl to specify a different field name to group by (e.g. “ContentType”).
Solution 2: The Better Method
Alternative, we could try and get our options added to the ViewEdit.aspx page. Options aren’t great for this as it’s a _layouts (application) page, and therefore we can’t just edit it in the browser or SharePoint Designer.
You could add a piece of JavaScript to do this though. Plan a) would be to add this to the bottom of you v4.master, and customise this for the whole site/site collection.
Plan b) would be to create something like a sandbox solution that deploys a “scriptlink” element, placing the script on every page that gets rendered.
I’ve create a CodePlex project for plan b). Here’s some of the code. Firstly, here’s the JavaScript I’d like to run on every page. It simply creates a new <option> tag in HTML and adds it to the drop down list if it exists on the page. Let’s call it “ListViewEdit.js”.
_spBodyOnLoadFunctionNames.push("jbCTFix"); function jbCTFix() { jbCTKludge('idGroupField1'); jbCTKludge('idGroupField2'); } function jbCTKludge(selName) { var sel = document.getElementById(selName); if (sel) { if (sel.selectedIndex >= 0) { var o = document.createElement('option'); o.text = 'Content Type'; o.value = 'tp_ContentType'; var prev = sel.options[sel.selectedIndex]; try { sel.add(o, prev); } catch (ex) { sel.add(o, sel.selectedIndex); } } } }
Next, here’s the element manifest to apply this on each page in the site collection.
<?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <CustomAction Id="Ribbon.Library.Actions.Scripts" Location ="ScriptLink" ScriptSrc="~site/ListViewEdit/ListViewEdit.js" /> <Module Name="ListViewEdit"> <File Path="ListViewEdit\ListViewEdit.js" Url="ListViewEdit/ListViewEdit.js" /> </Module> </Elements>
You can download the full project and source code for the SharePoint 2010 ViewEdit Group by Content Type project from the CodePlex project here: sp10ctgrouping.codeplex.com