Membuat Tabel pada Bootstrap

Cara Menggunakan Bootstrap
Bootstrap

Membuat Tabel pada Bootstrap

Membuat Tabel pada Bootstrap. – Pada artikel sebelumnya, kita telah membahas Aturan Penulisan pada Bootstrap. Kali ini kita masih pada Tema Bootstrap, yaitu Membuat Tabel pada Bootstrap. Seperti biasa, yang kita pakai adalah class pada Bootstrap yang akan kita gunakan untuk membuat table.

Baca juga: Aturan Penulisan pada Bootstrap.

Membuat Tabel pada Bootstrap

Membuat tabel pada Bootstrap sangat mudah, hanya dengan menaggil class bawaan dari Bootstrap. Lalu kita bisa meng-kustom nya sendiri. Seperti memberi warna header gelap, bahkan membuat tabel responsive. Adapun class yang kita gunakan adalah,

  • .table > Class ini adalah class basic yang digunakan dalam Bootstrap.
  • .table-striped > Kita bisa membuat table yang tiap barisnya berbeda warna menggunakan class table-striped.
  • .table-bordered > Class ini memudahkan kita untuk memberi border pada table yang kita buat.
  • .table-hover > Memberikan efek hover (gray background) pada table kita.
  • .thead-dark > Class ini menjadikan warna header table menjadi gelap.
  • .thead-light > Ini adalah kebalikan dari thead-dark, yaitu memberi background grey pada header table.

Cara Membuat Table pada Bootstrap

Sekarang kita coba membuat table menggunakan Bootstrap. Yang pertama buat file index.html berisi kode berikut,

[html]



codelatte.id/title><br /> <meta charset="utf-8"><br /> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><br /> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script><br /> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script><br /> </head><br /> <body></p> <div class="container"> <h2>Contoh Penggunaan <code>.thead-dark</code> pada Bootstrap | codelatte.id</h2> <table class="table"> <thead class="thead-dark"> <tr> <th>Nama</th> <th>Tempat Tinggal</th> <th>Email</th> </tr> </thead> <tbody> <tr> <td>Andi</td> <td>Jakarta</td> <td>andi@example.com</td> </tr> <tr> <td>Susi</td> <td>Surabaya</td> <td>susi@example.com</td> </tr> <tr> <td>Gilang</td> <td>Medan</td> <td>gilang@example.com</td> </tr> </tbody> </table> </div> <p></body><br /> </html><br /> [/html]<br /> Hasilnya akan menjadi seperti ini,</p> <div id="attachment_449" style="width: 1263px" class="wp-caption aligncenter"><img decoding="async" aria-describedby="caption-attachment-449" class="size-full wp-image-449" src="https://codelatte.id/wp-content/uploads/2018/07/Screen-Shot-2018-07-20-at-4.46.30-AM.png" alt="Contoh Tabel pada Bootstrap" width="1253" height="396" srcset="https://i0.wp.com/codelatte.org/wp-content/uploads/2018/07/Screen-Shot-2018-07-20-at-4.46.30-AM.png?w=1253&ssl=1 1253w, https://i0.wp.com/codelatte.org/wp-content/uploads/2018/07/Screen-Shot-2018-07-20-at-4.46.30-AM.png?resize=300%2C95&ssl=1 300w, https://i0.wp.com/codelatte.org/wp-content/uploads/2018/07/Screen-Shot-2018-07-20-at-4.46.30-AM.png?resize=768%2C243&ssl=1 768w, https://i0.wp.com/codelatte.org/wp-content/uploads/2018/07/Screen-Shot-2018-07-20-at-4.46.30-AM.png?resize=1024%2C324&ssl=1 1024w" sizes="(max-width: 740px) 100vw, 740px" /><p id="caption-attachment-449" class="wp-caption-text">Contoh Tabel pada Bootstrap</p></div> <p> </p> <p>Sebenarnya banyak sekali <code>class</code> untuk table pada Bootstrap. Kita bisa membuat tabel tanpa border, tabel kontekstual, bahkan sampai membuat tabel responsive. Kalian bisa lihat dibawah tentang <code>class</code> yang saya maksud diatas.</p> <ul> <li><code>.table-dark</code></li> <li>Kombinasi <code>.table-dark</code> dan <code>.table-striped</code></li> <li><code>.table-borderless</code></li> <li><code>.table-primary</code></li> <li><code>.table-success</code></li> <li><code>.table-danger</code></li> <li><code>.table-info</code></li> <li><code>.table-warning</code></li> <li><code>.table-active</code></li> <li><code>.table-secondary</code></li> <li><code>.table-sm</code> > Tabel berukuran lebih kecil dari default.</li> <li><code>.table-responsive</code></li> </ul> <p>Sekian artikel kali ini, semoga bermanfaat dan sampai jumpa pada artikel berikutnya!</p> <div class="sharedaddy sd-sharing-enabled"><div class="robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing"><h3 class="sd-title">Bagikan ini:</h3><div class="sd-content"><ul><li class="share-facebook"><a rel="nofollow noopener noreferrer" data-shared="sharing-facebook-448" class="share-facebook sd-button share-icon" href="https://codelatte.org/membuat-tabel-pada-bootstrap/?share=facebook" target="_blank" title="Click to share on Facebook" ><span>Facebook</span></a></li><li class="share-x"><a rel="nofollow noopener noreferrer" data-shared="sharing-x-448" class="share-x sd-button share-icon" href="https://codelatte.org/membuat-tabel-pada-bootstrap/?share=x" target="_blank" title="Click to share on X" ><span>X</span></a></li><li class="share-end"></li></ul></div></div></div> <div class="clear"></div> </div><!--/.entry--> </div> <div class="entry-footer group"> <p class="post-tags"><span>Tags:</span> <a href="https://codelatte.org/tag/bootstrap/" rel="tag">Bootstrap</a></p> <div class="clear"></div> <div class="author-bio"> <div class="bio-avatar"><img alt='' src='https://codelatte.org/wp-content/uploads/2024/12/avatar_user_1_1733460378-128x128.png' srcset='https://codelatte.org/wp-content/uploads/2024/12/avatar_user_1_1733460378-256x256.png 2x' class='avatar avatar-128 photo' height='128' width='128' loading='lazy' decoding='async'/></div> <p class="bio-name">Abay</p> <p class="bio-desc">Cheers, I am Abay and I make things for fun. I love turning exciting ideas into horrible code.</p> <div class="clear"></div> </div> <ul class="post-nav group"> <li class="next"><a href="https://codelatte.org/contoh-dan-cara-penggunaan-gambar-pada-bootstrap/" rel="next"><i class="fas fa-chevron-right"></i><strong>Next</strong> <span>Contoh dan Cara Penggunaan Gambar pada Bootstrap</span></a></li> <li class="previous"><a href="https://codelatte.org/aturan-penulisan-pada-bootstrap/" rel="prev"><i class="fas fa-chevron-left"></i><strong>Previous</strong> <span>Aturan Penulisan pada Bootstrap</span></a></li> </ul> <div id="comments" class="themeform"> <!-- comments open, no comments --> <div id="respond" class="comment-respond"> <h3 id="reply-title" class="comment-reply-title">Leave a Reply<small><a rel="nofollow" id="cancel-comment-reply-link" href="/membuat-tabel-pada-bootstrap/#respond" style="display:none;">Cancel reply</a></small></h3> <form id="commentform" class="comment-form"> <iframe title="Comment Form" src="https://jetpack.wordpress.com/jetpack-comment/?blogid=175539205&postid=448&comment_registration=0&require_name_email=1&stc_enabled=0&stb_enabled=0&show_avatars=1&avatar_default=retro&greeting=Leave+a+Reply&jetpack_comments_nonce=f36464f834&greeting_reply=Leave+a+Reply+to+%25s&color_scheme=light&lang=en_US&jetpack_version=14.1&iframe_unique_id=1&show_cookie_consent=10&has_cookie_consent=0&is_current_user_subscribed=0&token_key=%3Bnormal%3B&sig=2b227dc1689eb743d1e445a9937ced78226362da#parent=https%3A%2F%2Fcodelatte.org%2Fmembuat-tabel-pada-bootstrap%2F" name="jetpack_remote_comment" style="width:100%; height: 430px; border:0;" class="jetpack_remote_comment" id="jetpack_remote_comment" sandbox="allow-same-origin allow-top-navigation allow-scripts allow-forms allow-popups" > </iframe> <!--[if !IE]><!--> <script> document.addEventListener('DOMContentLoaded', function () { var commentForms = document.getElementsByClassName('jetpack_remote_comment'); for (var i = 0; i < commentForms.length; i++) { commentForms[i].allowTransparency = false; commentForms[i].scrolling = 'no'; } }); </script> <!--<![endif]--> </form> </div> <input type="hidden" name="comment_parent" id="comment_parent" value="" /> </div><!--/#comments--> </div> </div> </article><!--/.post--> <div class="masonry"> <article id="post-1372" class="masonry-item group post-1372 post type-post status-publish format-standard has-post-thumbnail hentry category-laravel category-server tag-configuration tag-htaccess tag-laravel tag-system-administrator"> <div class="masonry-inner"> <div class="entry-top"> <a class="entry-thumbnail" href="https://codelatte.org/setting-http-authentication-pada-laravel/"> <img width="520" height="340" src="https://i0.wp.com/codelatte.org/wp-content/uploads/2020/03/Screenshot_2020-03-02_22-34-28.png?resize=520%2C340&ssl=1" class="attachment-gridzone-medium size-gridzone-medium wp-post-image" alt="Setting HTTP Authentication pada Laravel" decoding="async" loading="lazy" /> </a> <div class="entry-category"><a href="https://codelatte.org/category/laravel/" rel="category tag">Laravel</a> <a href="https://codelatte.org/category/server/" rel="category tag">Server</a></div> </div> <h2 class="entry-title"> <a href="https://codelatte.org/setting-http-authentication-pada-laravel/" rel="bookmark">Setting HTTP Authentication pada Laravel</a> </h2><!--/.entry-title--> <ul class="entry-meta group"> <li class="entry-date"><i class="far fa-calendar"></i> 2 March 2020</li> </ul> </div> </article><!--/.post--> <article id="post-531" class="masonry-item group post-531 post type-post status-publish format-standard has-post-thumbnail hentry category-referensi tag-text-editor"> <div class="masonry-inner"> <div class="entry-top"> <a class="entry-thumbnail" href="https://codelatte.org/10-text-editor-terbaik-2018/"> <img width="520" height="347" src="https://i0.wp.com/codelatte.org/wp-content/uploads/2018/07/code-editor.jpg?resize=520%2C347&ssl=1" class="attachment-gridzone-medium size-gridzone-medium wp-post-image" alt="Text Editor" decoding="async" loading="lazy" /> </a> <div class="entry-category"><a href="https://codelatte.org/category/referensi/" rel="category tag">Referensi</a></div> </div> <h2 class="entry-title"> <a href="https://codelatte.org/10-text-editor-terbaik-2018/" rel="bookmark">10 Text Editor Terbaik Yang Bikin Kamu Semangat Ngoding!</a> </h2><!--/.entry-title--> <ul class="entry-meta group"> <li class="entry-date"><i class="far fa-calendar"></i> 28 July 2018</li> </ul> </div> </article><!--/.post--> <article id="post-1271" class="masonry-item group post-1271 post type-post status-publish format-standard has-post-thumbnail hentry category-laravel tag-composer tag-laravel"> <div class="masonry-inner"> <div class="entry-top"> <a class="entry-thumbnail" href="https://codelatte.org/install-laravel-6/"> <img width="520" height="347" src="https://i0.wp.com/codelatte.org/wp-content/uploads/2019/11/laravel-thumbnail.jpg?resize=520%2C347&ssl=1" class="attachment-gridzone-medium size-gridzone-medium wp-post-image" alt="Controller Laravel" decoding="async" loading="lazy" /> </a> <div class="entry-category"><a href="https://codelatte.org/category/laravel/" rel="category tag">Laravel</a></div> </div> <h2 class="entry-title"> <a href="https://codelatte.org/install-laravel-6/" rel="bookmark">Install Laravel 6</a> </h2><!--/.entry-title--> <ul class="entry-meta group"> <li class="entry-date"><i class="far fa-calendar"></i> 12 December 2019</li> </ul> </div> </article><!--/.post--> </div> </div><!--/.content--> <div class="sidebar s1"> <div class="sidebar-content"> </div><!--/.sidebar-content--> </div><!--/.sidebar--> </div><!--/.main-inner--> </div><!--/.main--> </div><!--/.container-inner--> </div><!--/.container--> <div class="clear"></div> <footer id="footer"> <div id="footer-bottom"> <a id="back-to-top" href="#" aria-label="Back to Top"><i class="fas fa-angle-up"></i></a> <div class="pad group"> <div class="grid one-full"> <div id="copyright"> <p>Codelatte © 2024. All Rights Reserved.</p> </div><!--/#copyright--> <div id="credit"> <p>Powered by <a href="http://wordpress.org" rel="nofollow">WordPress</a>. Theme by <a href="http://alx.media" rel="nofollow">Alx</a>.</p> </div><!--/#credit--> </div> </div><!--/.pad--> </div><!--/#footer-bottom--> </footer><!--/#footer--> </div><!--/#wrapper--> <script type="text/javascript"> window.WPCOM_sharing_counts = {"https:\/\/codelatte.org\/membuat-tabel-pada-bootstrap\/":448}; </script> <script type="text/javascript" id="superpwa-register-sw-js-extra"> /* <![CDATA[ */ var superpwa_sw = {"url":"\/superpwa-sw.js?1733541514","disable_addtohome":"0","enableOnDesktop":"","offline_form_addon_active":"","ajax_url":"https:\/\/codelatte.org\/wp-admin\/admin-ajax.php","offline_message":"1","offline_message_txt":"You are currently offline."}; /* ]]> */ </script> <script type="text/javascript" src="https://codelatte.org/wp-content/plugins/super-progressive-web-apps/public/js/register-sw.js?ver=2.2.32" id="superpwa-register-sw-js"></script> <script type="text/javascript" src="https://codelatte.org/wp-content/themes/gridzone/js/jquery.fitvids.js?ver=6.7.1" id="gridzone-fitvids-js"></script> <script type="text/javascript" src="https://codelatte.org/wp-content/themes/gridzone/js/jq-sticky-anything.min.js?ver=6.7.1" id="gridzone-jq-sticky-anything-js"></script> <script type="text/javascript" src="https://codelatte.org/wp-content/themes/gridzone/js/imagesloaded.pkgd.min.js?ver=6.7.1" id="gridzone-imagesloaded-js"></script> <script type="text/javascript" src="https://codelatte.org/wp-content/themes/gridzone/js/masonry.pkgd.min.js?ver=6.7.1" id="gridzone-masonry-js"></script> <script type="text/javascript" src="https://codelatte.org/wp-content/themes/gridzone/js/scripts.js?ver=6.7.1" id="gridzone-scripts-js"></script> <script type="text/javascript" src="https://c0.wp.com/c/6.7.1/wp-includes/js/comment-reply.min.js" id="comment-reply-js" async="async" data-wp-strategy="async"></script> <script type="text/javascript" src="https://codelatte.org/wp-content/plugins/enlighter/cache/enlighterjs.min.js?ver=OXpO+0+NQhcfSun" id="enlighterjs-js"></script> <script type="text/javascript" src="https://stats.wp.com/e-202449.js" id="jetpack-stats-js" data-wp-strategy="defer"></script> <script type="text/javascript" id="jetpack-stats-js-after"> /* <![CDATA[ */ _stq = window._stq || []; _stq.push([ "view", JSON.parse("{\"v\":\"ext\",\"blog\":\"175539205\",\"post\":\"448\",\"tz\":\"7\",\"srv\":\"codelatte.org\",\"j\":\"1:14.1\"}") ]); _stq.push([ "clickTrackerInit", "175539205", "448" ]); /* ]]> */ </script> <script type="text/javascript" id="sharing-js-js-extra"> /* <![CDATA[ */ var sharing_js_options = {"lang":"en","counts":"1","is_stats_active":"1"}; /* ]]> */ </script> <script type="text/javascript" src="https://c0.wp.com/p/jetpack/14.1/_inc/build/sharedaddy/sharing.min.js" id="sharing-js-js"></script> <script type="text/javascript" id="sharing-js-js-after"> /* <![CDATA[ */ var windowOpen; ( function () { function matches( el, sel ) { return !! ( el.matches && el.matches( sel ) || el.msMatchesSelector && el.msMatchesSelector( sel ) ); } document.body.addEventListener( 'click', function ( event ) { if ( ! event.target ) { return; } var el; if ( matches( event.target, 'a.share-facebook' ) ) { el = event.target; } else if ( event.target.parentNode && matches( event.target.parentNode, 'a.share-facebook' ) ) { el = event.target.parentNode; } if ( el ) { event.preventDefault(); // If there's another sharing window open, close it. if ( typeof windowOpen !== 'undefined' ) { windowOpen.close(); } windowOpen = window.open( el.getAttribute( 'href' ), 'wpcomfacebook', 'menubar=1,resizable=1,width=600,height=400' ); return false; } } ); } )(); var windowOpen; ( function () { function matches( el, sel ) { return !! ( el.matches && el.matches( sel ) || el.msMatchesSelector && el.msMatchesSelector( sel ) ); } document.body.addEventListener( 'click', function ( event ) { if ( ! event.target ) { return; } var el; if ( matches( event.target, 'a.share-x' ) ) { el = event.target; } else if ( event.target.parentNode && matches( event.target.parentNode, 'a.share-x' ) ) { el = event.target.parentNode; } if ( el ) { event.preventDefault(); // If there's another sharing window open, close it. if ( typeof windowOpen !== 'undefined' ) { windowOpen.close(); } windowOpen = window.open( el.getAttribute( 'href' ), 'wpcomx', 'menubar=1,resizable=1,width=600,height=350' ); return false; } } ); } )(); /* ]]> */ </script> <script> /(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",function(){var t,e=location.hash.substring(1);/^[A-z0-9_-]+$/.test(e)&&(t=document.getElementById(e))&&(/^(?:a|select|input|button|textarea)$/i.test(t.tagName)||(t.tabIndex=-1),t.focus())},!1); </script> <script type="text/javascript"> (function () { const iframe = document.getElementById( 'jetpack_remote_comment' ); const watchReply = function() { // Check addComment._Jetpack_moveForm to make sure we don't monkey-patch twice. if ( 'undefined' !== typeof addComment && ! addComment._Jetpack_moveForm ) { // Cache the Core function. addComment._Jetpack_moveForm = addComment.moveForm; const commentParent = document.getElementById( 'comment_parent' ); const cancel = document.getElementById( 'cancel-comment-reply-link' ); function tellFrameNewParent ( commentParentValue ) { const url = new URL( iframe.src ); if ( commentParentValue ) { url.searchParams.set( 'replytocom', commentParentValue ) } else { url.searchParams.delete( 'replytocom' ); } if( iframe.src !== url.href ) { iframe.src = url.href; } }; cancel.addEventListener( 'click', function () { tellFrameNewParent( false ); } ); addComment.moveForm = function ( _, parentId ) { tellFrameNewParent( parentId ); return addComment._Jetpack_moveForm.apply( null, arguments ); }; } } document.addEventListener( 'DOMContentLoaded', watchReply ); // In WP 6.4+, the script is loaded asynchronously, so we need to wait for it to load before we monkey-patch the functions it introduces. document.querySelector('#comment-reply-js')?.addEventListener( 'load', watchReply ); const commentIframes = document.getElementsByClassName('jetpack_remote_comment'); window.addEventListener('message', function(event) { if (event.origin !== 'https://jetpack.wordpress.com') { return; } if (!event?.data?.iframeUniqueId && !event?.data?.height) { return; } const eventDataUniqueId = event.data.iframeUniqueId; // Change height for the matching comment iframe for (let i = 0; i < commentIframes.length; i++) { const iframe = commentIframes[i]; const url = new URL(iframe.src); const iframeUniqueIdParam = url.searchParams.get('iframe_unique_id'); if (iframeUniqueIdParam == event.data.iframeUniqueId) { iframe.style.height = event.data.height + 'px'; return; } } }); })(); </script> </body> </html>