webdevpuneet.com

Bootstrap Data Table with Row Selection — Free Snippet

Bootstrap Data Table with Row Selection · Tables · Plain HTML, CSS & JS · Live preview

CategoryTables

Copy & paste

Source Code

<div class="container py-5">
  <div class="d-flex justify-content-between align-items-center mb-2">
    <span class="small text-muted" id="bsselCount">0 selected</span>
    <button class="btn btn-sm btn-outline-danger d-none" id="bsselDelete">Delete selected</button>
  </div>
  <table class="table table-hover align-middle bssel-table">
    <thead>
      <tr>
        <th style="width:40px"><input type="checkbox" class="form-check-input" id="bsselAll"></th>
        <th>File</th><th>Size</th><th>Modified</th>
      </tr>
    </thead>
    <tbody id="bsselBody">
      <tr><td><input type="checkbox" class="form-check-input bssel-row"></td><td>proposal-final.pdf</td><td>2.1 MB</td><td>Sep 8</td></tr>
      <tr><td><input type="checkbox" class="form-check-input bssel-row"></td><td>brand-assets.zip</td><td>18.4 MB</td><td>Sep 5</td></tr>
      <tr><td><input type="checkbox" class="form-check-input bssel-row"></td><td>meeting-notes.docx</td><td>84 KB</td><td>Sep 2</td></tr>
      <tr><td><input type="checkbox" class="form-check-input bssel-row"></td><td>roadmap-2026.xlsx</td><td>412 KB</td><td>Aug 29</td></tr>
    </tbody>
  </table>
</div>

Extend with AI

Take This Snippet Further With AI

The AI prompt for this one is for Patreon supporters ($3 a month, 7 days free), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.

· Become a supporter

What's included

Features

Real Bootstrap 5.3 form-check checkboxes and table styling, loaded from the actual CDN
Header checkbox uses the real indeterminate state for a partial selection, not just checked/unchecked
Live selected-count summary recalculated from the actual DOM state on every change
Bulk delete action appears only when at least one row is selected
Selected rows get an immediate visual highlight, not just a checked checkbox
One shared updateSummary() function keeps count, header state, and delete visibility consistent

About this UI Snippet

Bootstrap Data Table with Row Selection — HTML, CSS & JavaScript

Screenshot of the Bootstrap Data Table with Row Selection snippet rendered live

The header checkbox in this table isn't just a "select all" toggle — it also uses the native indeterminate property, the real third visual state (a dash instead of a check or empty box) browsers support specifically for "some, but not all, of a group is selected." updateSummary() recalculates all three states together on every change: the live "N selected" count, whether the bulk "Delete selected" button should even be visible, and whether the header checkbox should read as checked, unchecked, or indeterminate — so those three things can never contradict each other.

Built on real Bootstrap 5.3 form-check checkboxes and table styling, with a highlighted row background (.bssel-selected) applied the instant a row's own checkbox changes, giving immediate visual confirmation beyond the small checkbox itself.

Step by step

How to Use

  1. 1
    Load the snippetClick the snippet in the sidebar Library tab. The preview loads a 4-row file table, "0 selected".
  2. 2
    Check one rowIt highlights, the count updates to "1 selected", and "Delete selected" appears. The header checkbox shows a dash (indeterminate).
  3. 3
    Check all remaining rowsThe header checkbox becomes fully checked once every row is selected.
  4. 4
    Click the header checkbox to uncheckEvery row deselects at once, the highlight clears, and the delete button hides again.
  5. 5
    Select a few rows and click "Delete selected"Those rows are removed from the table, and the summary updates to match what remains.

Real-world uses

Common Use Cases

File managers and bulk-action admin tables
The standard checkbox-select-and-bulk-act pattern for any table where visitors need to operate on multiple rows at once.
Learning the indeterminate checkbox state
A concrete, correct use of the often-overlooked native indeterminate property for "some but not all" selections.
Admin panels needing bulk delete/export/archive
Reuse this pattern for any bulk action — export selected, archive selected, tag selected — not just delete.
Email inboxes and record management UIs
The same select-all-with-indeterminate pattern used in most email clients and record management tools.

Got questions?

Frequently Asked Questions

It's the native indeterminate visual state, set via JavaScript (checkbox.indeterminate = true) whenever some but not all rows are checked — distinct from both the checked and unchecked states, and it can only be set programmatically, not by a user click.

It removes them from this front-end demo's table. Wire the delete handler to a real API call before removing the rows for actual persistence.

A single updateSummary() function re-queries how many row checkboxes are currently checked every time any checkbox changes, and derives the count, the delete button's visibility, and the header checkbox's state all from that one query — so none of them can drift out of sync.

The header checkbox becomes fully checked automatically once the count of checked rows equals the total row count — it doesn't require actually clicking the header checkbox itself to reach that state.

Yes — if you add filtering (like the Bootstrap Filter Sidebar Offcanvas snippet), scope selectAll's change handler to only affect currently-visible rows, and have updateSummary() count only visible rows' checked state as well.