Skip to content

tofsjonas/searchable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

16 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

searchable

- a tiny, vanilla/plain JavaScript table search

Makes any table with class="searchable" searchable. Click the search button to filter table rows in real-time as you type.

Just include the JavaScript+CSS and it works automatically. No function calls needed.

Related Projects

sortable - makes tables sortable with similar simplicity.

Demo

https://tofsjonas.github.io/searchable/

Table of Contents

Features

  • 1.41K minified (786 bytes gzipped)
  • Real-time search - filter as you type (case-insensitive)
  • Works with dynamic tables - JavaScript generated content supported
  • Lightning fast - handles large tables smoothly
  • Zero dependencies - vanilla JavaScript only
  • Auto-initialization - just add the class
  • Multi-language support - 29 languages available
  • Customizable - button position, icons, styling
  • Modern browsers - requires CSS :has() support (Chrome 105+, Firefox 121+, Safari 15.4+)

Installation

CDN (jsDelivr)

Default (English):

<link href="https://cdn.jsdelivr.net/gh/tofsjonas/searchable@latest/dist/searchable.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/gh/tofsjonas/searchable@latest/dist/searchable.min.js"></script>

Or use a specific language (e.g., Swedish):

<link href="https://cdn.jsdelivr.net/gh/tofsjonas/searchable@latest/dist/sv/searchable.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/gh/tofsjonas/searchable@latest/dist/sv/searchable.min.js"></script>

Local files

Copy files from dist/ (or dist/[language]/ for specific languages) and link locally:

<link href="/assets/searchable.css" rel="stylesheet" />
<script src="/assets/searchable.min.js"></script>

Languages

searchable comes with built-in support for 29 languages. Each language version includes localized text for the search placeholder, empty state message, and search icon.

Supported Languages

  • ar - Arabic (ุงู„ุนุฑุจูŠุฉ)
  • cs - Czech (ฤŒeลกtina)
  • da - Danish (Dansk)
  • de - German (Deutsch)
  • el - Greek (ฮ•ฮปฮปฮทฮฝฮนฮบฮฌ)
  • en - English (default)
  • es - Spanish (Espaรฑol)
  • fi - Finnish (Suomi)
  • fr - French (Franรงais)
  • he - Hebrew (ืขื‘ืจื™ืช)
  • hi - Hindi (เคนเคฟเคจเฅเคฆเฅ€)
  • hu - Hungarian (Magyar)
  • id - Indonesian (Bahasa Indonesia)
  • it - Italian (Italiano)
  • ja - Japanese (ๆ—ฅๆœฌ่ชž)
  • ko - Korean (ํ•œ๊ตญ์–ด)
  • nl - Dutch (Nederlands)
  • no - Norwegian (Norsk)
  • pl - Polish (Polski)
  • pt - Portuguese (Portuguรชs)
  • ro - Romanian (Romรขnฤƒ)
  • ru - Russian (ะ ัƒััะบะธะน)
  • sv - Swedish (Svenska)
  • th - Thai (เน„เธ—เธข)
  • tr - Turkish (Tรผrkรงe)
  • uk - Ukrainian (ะฃะบั€ะฐั—ะฝััŒะบะฐ)
  • vi - Vietnamese (Tiแบฟng Viแป‡t)
  • zh - Chinese (ไธญๆ–‡)

Using a Specific Language

To use a specific language, include the language-specific files from the dist/[language]/ folder:

<!-- German example -->
<link href="https://cdn.jsdelivr.net/gh/tofsjonas/searchable@latest/dist/de/searchable.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/gh/tofsjonas/searchable@latest/dist/de/searchable.min.js"></script>

The default files in the root dist/ folder use English. You can still override any text using the data attributes described in the Configuration section.

Usage

Add class="searchable" to any table with <thead> and <tbody>:

<table class="searchable">
  <thead>
    <tr>
      <th>Product</th>
      <th>Price</th>
      <th>Category</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Laptop</td>
      <td>$999</td>
      <td>Electronics</td>
    </tr>
    <tr>
      <td>Coffee Mug</td>
      <td>$12</td>
      <td>Kitchen</td>
    </tr>
  </tbody>
</table>

A search button appears automatically. Click it to show/hide the search input.

Configuration

Button Position

Left vs Right Per table

<table class="searchable sb-left"></table>
<!-- left -->
<table class="searchable"></table>
<!-- right (default) -->

Globally using CSS

.searchable::before {
  top: 9px;
  left: 80px;
}

Custom Button Icon

Per table

<table class="searchable" data-sb-icon="๐Ÿ”"></table>
<table class="searchable" data-sb-icon="Search"></table>

Globally

.searchable::before {
  content: 'anything you want' !important;
}

Input Styling

Per table

<table class="searchable" data-sb-input-class="form-control"></table>

Globally

Using HTML

<script
  data-sb-input-class="form-control bg-warning etc"
  src="https://cdn.jsdelivr.net/gh/tofsjonas/searchable@latest/dist/searchable.min.js"
></script>

Using CSS

.searchable thead input {
  background: purple;
  font-family: 'Comic Sans MS', 'Comic Sans', cursive;
}

Placeholder

Per table

<table class="searchable" data-sb-placeholder="Search..."></table>

Globally

<script
  data-sb-placeholder="Placeholder for all searchable inputs"
  src="https://cdn.jsdelivr.net/gh/tofsjonas/searchable@latest/dist/searchable.min.js"
></script>

Empty State Message

Per table

<table class="searchable" data-sb-empty="No matches found"></table>

Globally

.searchable thead::after {
  content: 'Nothing here, move along' !important;
}

Table Background

Set a background so the empty-state pseudo-element is not visible through transparent table areas.

.searchable,
.searchable td {
  background: white;
  color: black;
}

@media (prefers-color-scheme: dark) {
  .searchable,
  .searchable td {
    background: #333;
    color: #fff;
  }
}

How It Works

Uses event delegation and CSS :has() pseudo-class. The search input is created dynamically and filters rows by hiding non-matching content in real-time.