{"id":248,"date":"2020-09-25T02:14:23","date_gmt":"2020-09-25T02:14:23","guid":{"rendered":"http:\/\/basicwebsitesolutions.com\/blog\/?p=248"},"modified":"2020-09-25T02:14:23","modified_gmt":"2020-09-25T02:14:23","slug":"sb-admin-php-fixed-table-header-with-scrollable-body","status":"publish","type":"post","link":"https:\/\/basicwebsitesolutions.com\/blog\/2020\/09\/25\/sb-admin-php-fixed-table-header-with-scrollable-body\/","title":{"rendered":"SB Admin PHP &#8211; Fixed Table Header with Scrollable Body"},"content":{"rendered":"\n<p>Hi guys,<\/p>\n\n\n\n<p>This question was raised to me recently and it peeked my interest to solve and find out how to do this. After digging around i found 2 working codes for my case. <\/p>\n\n\n\n<p>To explain further my tables are generated dynamically so the column widths and gaps differ by each refresh of the table<\/p>\n\n\n\n<p>There are the 2 options that i found<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"549\" src=\"http:\/\/basicwebsitesolutions.com\/blog\/wp-content\/uploads\/2020\/09\/20200925-UBM-BORDER-DESIGN-1-1024x549.jpg\" alt=\"\" class=\"wp-image-249\" srcset=\"https:\/\/basicwebsitesolutions.com\/blog\/wp-content\/uploads\/2020\/09\/20200925-UBM-BORDER-DESIGN-1-1024x549.jpg 1024w, https:\/\/basicwebsitesolutions.com\/blog\/wp-content\/uploads\/2020\/09\/20200925-UBM-BORDER-DESIGN-1-300x161.jpg 300w, https:\/\/basicwebsitesolutions.com\/blog\/wp-content\/uploads\/2020\/09\/20200925-UBM-BORDER-DESIGN-1-768x412.jpg 768w, https:\/\/basicwebsitesolutions.com\/blog\/wp-content\/uploads\/2020\/09\/20200925-UBM-BORDER-DESIGN-1.jpg 1598w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><figcaption>\/\/\/\/\/\/\/\/\/\/\/\/\/\/ OPTION 1 \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/<br> table tbody { display:block; max-height:450px; overflow-y:scroll; }<br> table thead, table tbody tr { display:table; width:100%; table-layout:fixed; }<br> <br>table width=&#8221;100%&#8221; class=&#8221;table table-striped table-hover&#8221; id=&#8221;dataTables-example&#8221;<br><\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"549\" src=\"http:\/\/basicwebsitesolutions.com\/blog\/wp-content\/uploads\/2020\/09\/20200925-UBM-BORDER-DESIGN-2-1024x549.jpg\" alt=\"\" class=\"wp-image-250\" srcset=\"https:\/\/basicwebsitesolutions.com\/blog\/wp-content\/uploads\/2020\/09\/20200925-UBM-BORDER-DESIGN-2-1024x549.jpg 1024w, https:\/\/basicwebsitesolutions.com\/blog\/wp-content\/uploads\/2020\/09\/20200925-UBM-BORDER-DESIGN-2-300x161.jpg 300w, https:\/\/basicwebsitesolutions.com\/blog\/wp-content\/uploads\/2020\/09\/20200925-UBM-BORDER-DESIGN-2-768x412.jpg 768w, https:\/\/basicwebsitesolutions.com\/blog\/wp-content\/uploads\/2020\/09\/20200925-UBM-BORDER-DESIGN-2.jpg 1920w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><figcaption>\/\/\/\/\/\/\/\/\/\/\/\/\/\/ OPTION 2 \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/<br>table {<br>     overflow-y: auto;<br>     height: 10vh;    <br> }<br> thead th {<br>     position: sticky;<br>     top: 0;<br> }<br><br>table width=&#8221;100%&#8221; class=&#8221;table table-striped table-hover&#8221; id=&#8221;dataTables-example&#8221;<\/figcaption><\/figure>\n\n\n\n<p>Hope this code helps out somebody out there.  If  you have any questions, just drop me a line.<\/p>\n\n\n\n<p>Coffee Cup<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi guys, This question was raised to me recently and it peeked my interest to solve and find out how to do this. After digging around i found 2 working codes for my case. To explain further my tables are generated dynamically so the column widths and gaps differ by each refresh of the table &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/basicwebsitesolutions.com\/blog\/2020\/09\/25\/sb-admin-php-fixed-table-header-with-scrollable-body\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;SB Admin PHP &#8211; Fixed Table Header with Scrollable Body&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,11],"tags":[147,145,144,146],"class_list":["post-248","post","type-post","status-publish","format-standard","hentry","category-life-as-a-programmer","category-php-and-mysql","tag-css-code","tag-fixed-table-header","tag-sb-admin","tag-scrollable-body"],"_links":{"self":[{"href":"https:\/\/basicwebsitesolutions.com\/blog\/wp-json\/wp\/v2\/posts\/248","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/basicwebsitesolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/basicwebsitesolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/basicwebsitesolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/basicwebsitesolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=248"}],"version-history":[{"count":2,"href":"https:\/\/basicwebsitesolutions.com\/blog\/wp-json\/wp\/v2\/posts\/248\/revisions"}],"predecessor-version":[{"id":252,"href":"https:\/\/basicwebsitesolutions.com\/blog\/wp-json\/wp\/v2\/posts\/248\/revisions\/252"}],"wp:attachment":[{"href":"https:\/\/basicwebsitesolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/basicwebsitesolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/basicwebsitesolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}