{"id":605,"date":"2019-03-19T13:01:00","date_gmt":"2019-03-19T18:01:00","guid":{"rendered":"https:\/\/blog.felineflock.com\/?p=605"},"modified":"2024-01-01T13:19:42","modified_gmt":"2024-01-01T19:19:42","slug":"an-easier-way-to-make-visualforce-tables-mobile-friendly","status":"publish","type":"post","link":"https:\/\/blog.felineflock.com\/index.php\/2019\/03\/19\/an-easier-way-to-make-visualforce-tables-mobile-friendly\/","title":{"rendered":"An easier way to make VisualForce tables mobile friendly"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"297\" src=\"https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/vf1-1024x297.png\" alt=\"\" class=\"wp-image-606\" srcset=\"https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/vf1-1024x297.png 1024w, https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/vf1-300x87.png 300w, https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/vf1-768x223.png 768w, https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/vf1.png 1085w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image alignright size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"320\" height=\"414\" src=\"https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/vf2.png\" alt=\"\" class=\"wp-image-607\" srcset=\"https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/vf2.png 320w, https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/vf2-232x300.png 232w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/><\/figure>\n\n\n\n<p>The default behavior of VisualForce tables (apex:pageBlockTable and apex:dataTable) is static &#8211; they don&#8217;t rearrange the data to better fit tablets and smartphones.<\/p>\n\n\n\n<p>This example shows how tiny the table data can appear on an IPhone.<\/p>\n\n\n\n<p>Sometimes the table will not decrease in size and will require the user to scroll sideways to see all data in it.<\/p>\n\n\n\n<p>I&#8217;ve implemented a CSS solution based on principles described on&nbsp;<a href=\"https:\/\/css-tricks.com\/responsive-data-tables\/\" target=\"_blank\" rel=\"noreferrer noopener\">this<\/a>&nbsp;<a href=\"https:\/\/css-tricks.com\/responsive-data-tables\/\" target=\"_blank\" rel=\"noreferrer noopener\">article<\/a>&nbsp;at CSS-tricks.com and have added several adjustments to make it work requiring minimal changes to the VisualForce code.<\/p>\n\n\n\n<p>This solution below (<a href=\"https:\/\/github.com\/fmendes\/MobileResponsiveVisualForceTable\/tree\/master\" target=\"_blank\" rel=\"noreferrer noopener\">my GitHub<\/a>) resizes and rearranges the table data according to the screen size and can be implemented in 3 steps.<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/fmendes\/MobileResponsiveVisualForceTable\/tree\/master\">https:\/\/github.com\/fmendes\/MobileResponsiveVisualForceTable\/tree\/master<\/a><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>use the &#8220;<a href=\"https:\/\/github.com\/fmendes\/MobileResponsiveVisualForceTable\/blob\/master\/mobileFriendly.css\" target=\"_blank\" rel=\"noreferrer noopener\">mobileFriendly.css<\/a>&#8221; file linked above &#8211; it contains the CSS directives to make a browser respond to the screen size<\/li>\n\n\n\n<li>add to your apex:pageBlockTable or apex:dataTable the attribute below:<\/li>\n<\/ol>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>styleClass=&#8221;mobileFriendly&#8221;<\/p>\n<\/blockquote>\n\n\n\n<ol class=\"wp-block-list\">\n<li>for each column in your table, add the attribute below containing the column header to display<\/li>\n<\/ol>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>html-data-header=&#8221;your column header text ending with a space&#8221;<\/p>\n<\/blockquote>\n\n\n\n<p>You can edit the CSS file to adjust how the elements appear, increase font-size or weight, etc.<\/p>\n\n\n\n<p>This was tested mostly with&nbsp;<strong>lightningStylesheets=&#8221;true&#8221;<\/strong>&nbsp;but it works in Classic too.<\/p>\n\n\n\n<p>The result is below (animated GIF showing the table responding to screen resizing):<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"808\" height=\"429\" src=\"https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/vf3.gif\" alt=\"\" class=\"wp-image-608\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>The default behavior of VisualForce tables (apex:pageBlockTable and apex:dataTable) is static &#8211; they don&#8217;t rearrange the data to better fit tablets and smartphones. This example shows how tiny the table data can appear on an IPhone. Sometimes the table will not decrease in size and will require the user to scroll sideways to see all [&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,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-605","post","type-post","status-publish","format-standard","hentry","category-blog"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/posts\/605","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/comments?post=605"}],"version-history":[{"count":1,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/posts\/605\/revisions"}],"predecessor-version":[{"id":609,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/posts\/605\/revisions\/609"}],"wp:attachment":[{"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/media?parent=605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/categories?post=605"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/tags?post=605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}