Snippets Layout

Bootstrap 5 Editable Data Table with Add and Delete Rows

A clean employee table where you can add a new row, edit any row inline and delete entries, with validation and an empty state.

Bootstrap 5 No jQuery Sep 2020 2.2K views

<section class="wdw-stage">
  <div class="container" style="max-width: 960px">
    <div class="wdw-card p-3 p-md-4" id="dt">
      <div class="d-flex flex-wrap align-items-center justify-content-between gap-3 mb-3 px-1">
        <div>
          <span class="wdw-eyebrow">Directory</span>
          <h1 class="wdw-heading h4 mb-0">Employee details</h1>
        </div>
        <button type="button" class="btn btn-primary rounded-pill px-4" id="dtAdd"><i class="bi bi-plus-lg"></i> Add employee</button>
      </div>
      <div class="d-flex flex-wrap align-items-center gap-3 mb-2 px-1">
        <div class="flex-grow-1 position-relative" style="min-width: 220px">
          <label class="visually-hidden" for="dtSearch">Search employees</label>
          <i class="bi bi-search dt-search-icon"></i>
          <input id="dtSearch" type="search" class="form-control ps-5" placeholder="Search employees">
        </div>
        <span class="small text-body-secondary" id="dtCount" aria-live="polite">3 employees</span>
      </div>
      <div class="table-responsive">
        <table class="table align-middle mb-0 dt-table">
          <thead>
            <tr><th scope="col">Employee</th><th scope="col">Department</th><th scope="col">Phone</th><th scope="col" class="text-end">Actions</th></tr>
          </thead>
          <tbody id="dtBody"></tbody>
        </table>
      </div>
      <p class="text-center text-body-secondary py-4 mb-0" id="dtEmpty" hidden>No employees found.</p>
    </div>
  </div>
  <div class="toast-container position-fixed bottom-0 start-50 translate-middle-x p-3">
    <div class="toast align-items-center text-bg-dark border-0" id="dtToast" role="status" aria-live="polite" aria-atomic="true" data-bs-autohide="true" data-bs-delay="6000">
      <div class="d-flex align-items-center">
        <div class="toast-body" id="dtToastMsg">Employee deleted.</div>
        <button type="button" class="btn btn-sm btn-outline-light me-2" id="dtUndo">Undo</button>
        <button type="button" class="btn-close btn-close-white me-2" data-bs-dismiss="toast" aria-label="Close"></button>
      </div>
    </div>
  </div>
</section>

Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.

Free to use in personal and commercial projects under the MIT license.