โœฆ StealThis .dev

Data Table

Feature-rich data table with column sorting, row selection via checkboxes, search filter, column visibility toggle, and pagination.

Open in Lab
css vanilla-js
Targets: JS HTML

Code

Data Table

A feature-rich data table built entirely with vanilla JS and CSS. Handles 15+ rows with sorting, filtering, selection, column visibility, and pagination.

Features

  • Sort โ€” click any column header to cycle asc โ†’ desc โ†’ none; sort indicator arrow updates
  • Search โ€” real-time filter across Name and Email columns; resets to page 1
  • Row selection โ€” individual checkboxes + select-all header checkbox; indeterminate state when partial
  • Bulk actions โ€” bar appears above table when rows are selected, shows count with Delete and Export buttons
  • Column visibility โ€” dropdown lets you hide/show any column; persists across re-renders
  • Pagination โ€” 10 rows per page; prev/next buttons + numbered page buttons; ellipsis for long page lists

How it works

  1. A DATA array holds all 15 user objects; filteredData is recomputed on search or sort
  2. render() slices filteredData for the current page and rebuilds the <tbody> rows
  3. Column sort state is stored as { col, dir } โ€” dir cycles through asc โ†’ desc โ†’ null
  4. Selected row IDs are stored in a Set; the select-all checkbox reads the intersection with the current page
  5. Column visibility is a plain object keyed by column id; hidden columns are display: none for both <th> and all corresponding <td>

Status badges

  • Active โ€” green
  • Inactive โ€” gray
  • Pending โ€” amber