A customer table with live search, sortable columns and pagination, built with Bootstrap 6 and plain JavaScript. It fits admin dashboards, CRM lists and any table that is too long for one screen. Search results highlight the matching text, and the footer always says which rows are visible.
How it works
The data lives in the CUSTOMERS array at the top of script.js. A small state object holds the search query, the sort key and direction, the current page and the page size. Every change calls render(), which filters, sorts, slices one page and rebuilds <tbody> and the pagination.
- Search: the
.tsp-queryinput sits in a Bootstrap 6.form-adornfield with a search icon. Typing is debounced by 150 ms. The query matches name, company, country and plan.highlight()wraps matches in<mark class="tsp-mark">with DOM nodes, neverinnerHTML, so data stays safe. - Sorting: each header contains a
.tsp-sortbutton with adata-tsp-key. Clicking setsaria-sorton the<th>and swaps the Bootstrap Icons arrow. A second click reverses the order. Text columns start A to Z, whileseatsandmrrstart high to low. - Pagination: a
pagination pagination-sm theme-primarylist with previous/next buttons and page numbers.pageList()adds ellipses once there are more than seven pages. After a page change, focus returns to the same button. - Page size: the
.tsp-size-selectselect switches between 6, 10, 15 and 25 rows and returns to page 1.
When nothing matches, a full-width .tsp-empty row explains why. .tsp-status reads, for example, "Showing 7–12 of 28 customers".
Customization
- Replace
CUSTOMERSwith data from your API, for exampleawait fetch('/api/customers').then((r) => r.json()), and callrender()afterwards. PLAN_THEMEinscript.js: maps each plan to atheme-*badge color.--tsp-greenand the--bs-primary-*overrides on.tsp-root: recolor the active page, sorted header and focus rings.--tsp-markon.tsp-root: changes the search highlight color.- The
<option>values in#tsp-size: change the page size choices. Theselectedoption is the default. - Add a column by adding a
<th>with a.tsp-sortbutton and itsdata-tsp-key, then one morecell()call inrenderRows().
Use cases
- CRM and customer lists: live search highlights matches as you type
- Admin dashboards: sortable columns let teams order records by name or other fields
- Large data sets: a rows-per-page select and smart pagination split long lists
- Accessible data tables: columns announce their sort state to screen readers
Accessibility
Sortable headers are real buttons inside <th scope="col">, and aria-sort tells screen readers the current order. The search field has an aria-label and aria-controls pointing to the table body. .tsp-status is a polite live region that announces result counts. Pagination buttons have aria-labels, and the current page has aria-current="page". Ellipses are hidden from assistive technology. The table has a visually hidden <caption>. On small screens .table-responsive scrolls sideways instead of breaking the layout.
Bootstrap 6 notes
The search box uses the new .form-adorn and .form-ghost classes instead of an input-group. The select uses form-control because form-select was removed. Pagination is colored with theme-primary, and badges use badge-subtle theme-*. Built on Bootstrap 6.0.0-alpha.1, so APIs can still change. Icons come from Bootstrap Icons.