{"id":1822,"date":"2018-11-01T12:30:11","date_gmt":"2018-11-01T16:30:11","guid":{"rendered":"https:\/\/toddbaginski.com\/blog\/?p=1822"},"modified":"2018-11-01T12:30:11","modified_gmt":"2018-11-01T16:30:11","slug":"how-to-create-custom-responsive-sharepoint-list-views-with-view-formatters","status":"publish","type":"post","link":"https:\/\/toddbaginski.com\/blog\/how-to-create-custom-responsive-sharepoint-list-views-with-view-formatters\/","title":{"rendered":"HOW TO: Create custom responsive SharePoint list views with View Formatters"},"content":{"rendered":"<p>Did you see <a href=\"https:\/\/techcommunity.microsoft.com\/t5\/Microsoft-SharePoint-Blog\/New-SharePoint-view-formatting-samples-now-available\/ba-p\/278185\" target=\"_blank\" rel=\"noopener\">the blog post on the Microsoft SharePoint Blog about the new SharePoint list View Formatter samples<\/a>?\u00a0 We had fun building the samples in the weeks leading up to the Microsoft Ignite conference and I&#8217;d like to share what we learned.<\/p>\n<p>In this article I&#8217;m going to dive into the sample code and show you how to implement responsive layouts with SharePoint View Formatters.<\/p>\n<p>In this article, I&#8217;ll use the <a href=\"https:\/\/github.com\/SharePoint\/sp-dev-list-formatting\/tree\/master\/view-samples\/resource-catalog\" target=\"_blank\" rel=\"noopener\">Resource Catalog sample<\/a> as an example.\u00a0 The Resource Catalog sample looks like this in a desktop web browser.\u00a0 You can see it fills the screen from left to right.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1823\" src=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-desktop.png\" alt=\"\" width=\"1024\" height=\"545\" srcset=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-desktop.png 1024w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-desktop-300x160.png 300w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-desktop-768x409.png 768w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-desktop-260x138.png 260w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-desktop-50x27.png 50w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-desktop-132x70.png 132w\" sizes=\"auto, (max-width:767px) 480px, (max-width:1024px) 100vw, 1024px\" \/><\/p>\n<p>In a tablet device it looks like this.\u00a0 The same layout is implemented and the content fits in the more narrow view port.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1825\" src=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-tablet.png\" alt=\"\" width=\"576\" height=\"392\" srcset=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-tablet.png 576w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-tablet-300x204.png 300w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-tablet-215x146.png 215w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-tablet-50x34.png 50w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-tablet-103x70.png 103w\" sizes=\"auto, (max-width:767px) 480px, 576px\" \/><\/p>\n<p>In mobile devices it looks like this.\u00a0 Here the layout changes and the content is displayed in a stacked layout.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1824\" src=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-mobile.png\" alt=\"\" width=\"375\" height=\"667\" srcset=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-mobile.png 375w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-mobile-169x300.png 169w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-mobile-82x146.png 82w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-mobile-28x50.png 28w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-mobile-39x70.png 39w\" sizes=\"auto, (max-width:767px) 375px, 375px\" \/><\/p>\n<p>Finally, what about when you add a web part to a SharePoint page to display the list?\u00a0 Here&#8217;s an example of what that looks like in a Modern Site.\u00a0 Notice the content fits nicely into the web part.\u00a0 In this example, the layout is the same as the tablet device example.<\/p>\n<p><strong>Note:<\/strong><em>It&#8217;s imperative<\/em><em> that you think about the web part use case when making View Formatters<\/em>.\u00a0 You never know when someone will add a web part to a page to display the lists you apply View Formatters to.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1826\" src=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-web-part.png\" alt=\"\" width=\"1200\" height=\"828\" srcset=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-web-part.png 1200w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-web-part-300x207.png 300w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-web-part-768x530.png 768w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-web-part-1024x707.png 1024w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-web-part-212x146.png 212w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-web-part-50x35.png 50w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-web-part-101x70.png 101w\" sizes=\"auto, (max-width:767px) 480px, (max-width:1200px) 100vw, 1200px\" \/><\/p>\n<p>To implement the responsive design, use CSS and HTML in the View Formatter JSON.\u00a0 <em><strong>This is the same pattern used to create responsive web sites.<\/strong><\/em><\/p>\n<p>Looking closer at the code, you can see the top level HTML element used to define the outer container for each row (the DIV shown in the JSON View Formatter code in the green box shown below)\u00a0uses a variety of CSS styles (shown the the gold box) to implement the responsive design.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1830\" src=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-row-styles.png\" alt=\"\" width=\"507\" height=\"411\" srcset=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-row-styles.png 507w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-row-styles-300x243.png 300w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-row-styles-180x146.png 180w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-row-styles-50x40.png 50w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-row-styles-86x70.png 86w\" sizes=\"auto, (max-width:767px) 480px, 507px\" \/><\/p>\n<p>Now, let&#8217;s connect the dots&#8230;\u00a0 In the image below you can see how the HTML and CSS Styles actually appear when they are rendered in the web page.\u00a0 Notice the green markup on the image that shows the HTML element (the DIV) in the code and in the web browser.\u00a0 Also, notice the gold markup on the image that shows the CSS classes that are applied to the DIV.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1833\" src=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-styles-web-debugger.png\" alt=\"\" width=\"1918\" height=\"517\" srcset=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-styles-web-debugger.png 1918w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-styles-web-debugger-300x81.png 300w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-styles-web-debugger-768x207.png 768w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-styles-web-debugger-1024x276.png 1024w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-styles-web-debugger-260x70.png 260w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-styles-web-debugger-50x13.png 50w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-styles-web-debugger-200x54.png 200w\" sizes=\"auto, (max-width:767px) 480px, (max-width:1918px) 100vw, 1918px\" \/><\/p>\n<p>Now, taking it to the next level, you can see the <strong>children<\/strong> element in the View Formatter JSON (green box in image below).\u00a0 It also defines a DIV.\u00a0 This DIV is used to display the content for the top portion of each row.\u00a0 You will also see another children collection and additional elements below it.\u00a0 This screenshot is only a partial view of all the HTML elements in the sample, there are many children elements used to implement the user interface.\u00a0 Again, CSS styles (in the gold box) are used to implement the responsive behavior.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1831\" src=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-row-styles-2.png\" alt=\"\" width=\"475\" height=\"853\" srcset=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-row-styles-2.png 475w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-row-styles-2-167x300.png 167w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-row-styles-2-81x146.png 81w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-row-styles-2-28x50.png 28w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-row-styles-2-39x70.png 39w\" sizes=\"auto, (max-width:767px) 475px, 475px\" \/><\/p>\n<p>Just like I demonstrated earlier, here you can see what it looks like in the web browser and how the styles correlate to the HTML and CSS used to render the view.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1836\" src=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-styles-web-debugger-2.png\" alt=\"\" width=\"1918\" height=\"547\" srcset=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-styles-web-debugger-2.png 1918w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-styles-web-debugger-2-300x86.png 300w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-styles-web-debugger-2-768x219.png 768w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-styles-web-debugger-2-1024x292.png 1024w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-styles-web-debugger-2-260x74.png 260w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-styles-web-debugger-2-50x14.png 50w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-styles-web-debugger-2-200x57.png 200w\" sizes=\"auto, (max-width:767px) 480px, (max-width:1918px) 100vw, 1918px\" \/><\/p>\n<p>To sum it all up, to create responsive SharePoint View Formatters simply use HTML and CSS just like you would to create a responsive web site.<\/p>\n<p><strong>Expert Tip:\u00a0<\/strong>Use <a href=\"https:\/\/developer.microsoft.com\/en-us\/fabric\" target=\"_blank\" rel=\"noopener\">Office UI Fabric Styles<\/a> to style the content whenever possible.\u00a0 This helps you match your user interface to Office 365.\u00a0 You will see in the samples where we used the Office UI Fabric Styles wherever we could. For example, we set the background color for the top level DIV with an Office UI Fabric Style, like this.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1837\" src=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-row-styles-3.png\" alt=\"\" width=\"507\" height=\"140\" srcset=\"https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-row-styles-3.png 507w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-row-styles-3-300x83.png 300w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-row-styles-3-260x72.png 260w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-row-styles-3-50x14.png 50w, https:\/\/toddbaginski.com\/blog\/wp-content\/uploads\/2018\/10\/vf-row-styles-3-200x55.png 200w\" sizes=\"auto, (max-width:767px) 480px, 507px\" \/><\/p>\n<p>Keep in mind, depending on your design, you may have to use styles that are not part of the Office UI Fabric Styles, just like you see in this sample.<\/p>\n<p>Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Did you see the blog post on the Microsoft SharePoint Blog about the new SharePoint list View Formatter samples?\u00a0 We had fun building the samples in<span class=\"excerpt-hellip\"> [\u2026]<\/span><\/p>\n","protected":false},"author":1,"featured_media":1839,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[96,104,97],"tags":[6,54,45,7],"class_list":["post-1822","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mobile","category-office-365","category-sharepoint","tag-how-to-sharepoint","tag-mobile","tag-o365","tag-sharepoint"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/posts\/1822","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/comments?post=1822"}],"version-history":[{"count":8,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/posts\/1822\/revisions"}],"predecessor-version":[{"id":1843,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/posts\/1822\/revisions\/1843"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/media\/1839"}],"wp:attachment":[{"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/media?parent=1822"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/categories?post=1822"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/toddbaginski.com\/blog\/wp-json\/wp\/v2\/tags?post=1822"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}