Allow content types to be grouped in views
Out of the box you’re not able to group your libraries by content type.
One way to achieve this is to activate the “Metadata Navigation and Filtering” feature under the site collection features.
Afterwards go to “document library settings”, beneath “General Settings” click “Metadata navigation settings” and add the “Content Type” to the “Selected Hierarchy Fields”.
If you return to your library, you’ll find an extra navigation panel which allows you to navigate through your library by the fields earlier selected.
But another way to achieve content type grouping is to change your field schema xml of the content type field in your site collection. The following code example shows how to achieve this. Within the code example we change the sortable property on the field, out of the box the property is set to false but if we change is we are able to sort and group our views by content type.
private void ModifyContentTypeField(SPWeb web) { SPFieldCollection fields = web.Fields; if (fields.Contains(SPBuiltInFieldId.ContentType)) { SPField contentTypeField = fields[SPBuiltInFieldId.ContentType]; if (contentTypeField != null) { string fieldSchemaXml = contentTypeField.SchemaXml; string replacedSchemaXml = Regex.Replace(fieldSchemaXml, "sortable=\"false\"", "Sortable=\"TRUE\"", RegexOptions.IgnoreCase); contentTypeField.SchemaXml = replacedSchemaXml; contentTypeField.Update(true); } } }
You can add this to a feature to enable content type field grouping. If you now go to your view modification screen, you can now select content type from the Group By drop down box.
After selecting the content type field as group by field your view will look something like this.





