Toggle Table Columns
Checkboxes that show or hide individual table columns.
Requires Bootstrap 5. Add the CDN tags below to your page (styles in
<head>, scripts before </body>). The downloaded file already includes them.<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"><script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script><div class="card border-0 shadow-sm" style="max-width:420px"><div class="card-body">
<div class="d-flex gap-3 mb-2 small" id="ctToggles"><label><input type="checkbox" data-col="1" checked> Email</label><label><input type="checkbox" data-col="2" checked> Role</label></div>
<table class="table table-sm small mb-0" id="ctTable"><thead><tr><th>Name</th><th data-c="1">Email</th><th data-c="2">Role</th></tr></thead><tbody>
<tr><td>Ava</td><td data-c="1">ava@x.com</td><td data-c="2">Admin</td></tr><tr><td>Ben</td><td data-c="1">ben@x.com</td><td data-c="2">Editor</td></tr>
</tbody></table>
</div></div>document.querySelectorAll('#ctToggles input').forEach(function(cb){cb.onchange=function(){document.querySelectorAll('#ctTable [data-c="'+cb.dataset.col+'"]').forEach(function(c){c.style.display=cb.checked?'':'none'})}});Free to use.This component uses Bootstrap 5 (linked above). Copy any file, or download a ready-to-open .html page with the CDN links already included.