{"id":153,"date":"2010-07-27T18:32:53","date_gmt":"2010-07-27T17:32:53","guid":{"rendered":"http:\/\/www.sharepointroot.net\/?p=29"},"modified":"2016-01-25T07:24:13","modified_gmt":"2016-01-25T06:24:13","slug":"allow-content-types-to-be-grouped-in-views","status":"publish","type":"post","link":"https:\/\/commonware.nl\/?p=153","title":{"rendered":"Allow content types to be grouped in views"},"content":{"rendered":"<p>Out of the box you&#8217;re not able to group your libraries by content type.<br \/>\nOne way to achieve this is to activate the &#8220;Metadata Navigation and Filtering&#8221; feature under the site collection features.<\/p>\n<div id=\"attachment_180\" style=\"width: 310px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/commonware.nl\/wp-content\/uploads\/2010\/07\/Metadata_navigation_and_filtering.png\" rel=\"attachment wp-att-180\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-180\" class=\"size-medium wp-image-180\" src=\"https:\/\/commonware.nl\/wp-content\/uploads\/2010\/07\/Metadata_navigation_and_filtering-300x40.png\" alt=\"Metadata navigation and filtering feature\" width=\"300\" height=\"40\" srcset=\"https:\/\/commonware.nl\/wp-content\/uploads\/2010\/07\/Metadata_navigation_and_filtering-300x40.png 300w, https:\/\/commonware.nl\/wp-content\/uploads\/2010\/07\/Metadata_navigation_and_filtering.png 575w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-180\" class=\"wp-caption-text\">Metadata navigation and filtering feature<\/p><\/div>\n<p>Afterwards go to &#8220;document library settings&#8221;, beneath &#8220;General Settings&#8221; click &#8220;Metadata navigation settings&#8221; and add the &#8220;Content Type&#8221; to the &#8220;Selected Hierarchy Fields&#8221;.<\/p>\n<div id=\"attachment_184\" style=\"width: 310px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/commonware.nl\/wp-content\/uploads\/2010\/07\/configure_navigation_hierchies.png\" rel=\"attachment wp-att-184\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-184\" class=\"size-medium wp-image-184\" src=\"https:\/\/commonware.nl\/wp-content\/uploads\/2010\/07\/configure_navigation_hierchies-300x133.png\" alt=\"Configure Navigation Hierarchies\" width=\"300\" height=\"133\" srcset=\"https:\/\/commonware.nl\/wp-content\/uploads\/2010\/07\/configure_navigation_hierchies-300x133.png 300w, https:\/\/commonware.nl\/wp-content\/uploads\/2010\/07\/configure_navigation_hierchies-768x341.png 768w, https:\/\/commonware.nl\/wp-content\/uploads\/2010\/07\/configure_navigation_hierchies.png 837w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-184\" class=\"wp-caption-text\">Configure Navigation Hierarchies<\/p><\/div>\n<p>If you return to your library, you&#8217;ll find an extra navigation panel which allows you to navigate through your library by the fields earlier selected.<\/p>\n<div id=\"attachment_183\" style=\"width: 164px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/commonware.nl\/wp-content\/uploads\/2010\/07\/navigation.png\" rel=\"attachment wp-att-183\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-183\" class=\"size-full wp-image-183\" src=\"https:\/\/commonware.nl\/wp-content\/uploads\/2010\/07\/navigation.png\" alt=\"Metadata navigation\" width=\"154\" height=\"248\" \/><\/a><p id=\"caption-attachment-183\" class=\"wp-caption-text\">Metadata navigation<\/p><\/div>\n<p>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.<\/p>\n<pre lang=\"csharp\">private void ModifyContentTypeField(SPWeb web)\r\n{\r\n\tSPFieldCollection fields = web.Fields;\r\n\r\n\tif (fields.Contains(SPBuiltInFieldId.ContentType))\r\n\t{\r\n\t\tSPField contentTypeField = fields[SPBuiltInFieldId.ContentType];\r\n\r\n\t\tif (contentTypeField != null)\r\n\t\t{\r\n\t\t\tstring fieldSchemaXml = contentTypeField.SchemaXml;\r\n\r\n\t\t\tstring replacedSchemaXml = Regex.Replace(fieldSchemaXml,\r\n\t\t\t\t\"sortable=\"false\"\", \"Sortable=\"TRUE\"\", RegexOptions.IgnoreCase);\r\n\r\n\t\t\tcontentTypeField.SchemaXml = replacedSchemaXml;\r\n\t\t\tcontentTypeField.Update(true);\r\n\t\t}\r\n\t}\r\n}<\/pre>\n<p>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.<\/p>\n<div id=\"attachment_182\" style=\"width: 310px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/commonware.nl\/wp-content\/uploads\/2010\/07\/group_by_contenttype.png\" rel=\"attachment wp-att-182\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-182\" class=\"size-medium wp-image-182\" src=\"https:\/\/commonware.nl\/wp-content\/uploads\/2010\/07\/group_by_contenttype-300x211.png\" alt=\"Group by content type\" width=\"300\" height=\"211\" srcset=\"https:\/\/commonware.nl\/wp-content\/uploads\/2010\/07\/group_by_contenttype-300x211.png 300w, https:\/\/commonware.nl\/wp-content\/uploads\/2010\/07\/group_by_contenttype.png 472w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-182\" class=\"wp-caption-text\">Group by content type<\/p><\/div>\n<p>After selecting the content type field as group by field your view will look something like this.<\/p>\n<div id=\"attachment_181\" style=\"width: 310px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/commonware.nl\/wp-content\/uploads\/2010\/07\/grouped_contenttypes_view.png\" rel=\"attachment wp-att-181\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-181\" class=\"size-medium wp-image-181\" src=\"https:\/\/commonware.nl\/wp-content\/uploads\/2010\/07\/grouped_contenttypes_view-300x127.png\" alt=\"View grouped content types\" width=\"300\" height=\"127\" srcset=\"https:\/\/commonware.nl\/wp-content\/uploads\/2010\/07\/grouped_contenttypes_view-300x127.png 300w, https:\/\/commonware.nl\/wp-content\/uploads\/2010\/07\/grouped_contenttypes_view.png 653w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-181\" class=\"wp-caption-text\">View grouped content types<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Out of the box you&#8217;re not able to group your libraries by content type. One way to achieve this is to activate the &#8220;Metadata Navigation and Filtering&#8221; feature under the site collection features. Afterwards go to &#8220;document library settings&#8221;, beneath &#8220;General Settings&#8221; click &#8220;Metadata navigation settings&#8221; and add the &#8220;Content Type&#8221; to the &#8220;Selected Hierarchy [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[8,15],"tags":[12,13,14,16],"class_list":["post-153","post","type-post","status-publish","format-standard","hentry","category-development","category-sharepoint-2010","tag-content-type","tag-customization","tag-sharepoint","tag-views"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/commonware.nl\/index.php?rest_route=\/wp\/v2\/posts\/153"}],"collection":[{"href":"https:\/\/commonware.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/commonware.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/commonware.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/commonware.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=153"}],"version-history":[{"count":2,"href":"https:\/\/commonware.nl\/index.php?rest_route=\/wp\/v2\/posts\/153\/revisions"}],"predecessor-version":[{"id":186,"href":"https:\/\/commonware.nl\/index.php?rest_route=\/wp\/v2\/posts\/153\/revisions\/186"}],"wp:attachment":[{"href":"https:\/\/commonware.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/commonware.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/commonware.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}