StealThis .dev

Data Table

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

Otwórz w Lab
css vanilla-js
Targety: JS HTML

Kod

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