DeveloperBreeze

How to implement a jQuery search for a table

Step 1: Set Up HTML Structure with a Search Input and Sample Table

We’ll create a basic HTML page with a search input and a sample table containing random data, such as employee information.

jQuery Table Search Example

Employee Directory

Employee IDNameDepartmentPositionLocation
101Alice JohnsonFinanceAccountantNew York
102Bob SmithEngineeringSoftware DeveloperSan Francisco
103Carol WhiteHuman ResourcesHR ManagerChicago
104David BrownMarketingBrand StrategistLos Angeles
105Eve BlackSalesSales ManagerMiami

Explanation of the Code

  1. Search Input:
  • The input field with id="searchInput" is placed above the table, where users can type their search terms.
  • The jQuery function will listen to this input field and use its value to filter the table rows.
  1. Sample Table:
  • The table is filled with sample data, representing an employee directory.
  • Each row in the <tbody> contains random data, including Employee ID, Name, Department, Position, and Location.
  1. jQuery Search Script:
  • This script listens for the keyup event on the search input. As the user types, it captures the search term, converts it to lowercase, and checks if any table row contains the search term.
  • toggle(rowText.includes(searchTerm)): This line hides any rows that don’t include the search term and shows those that do.

How It Works

  • Type in the Search Box: When you type into the search box, the script checks each table row for the presence of the search term.
  • Filter Rows Dynamically: Rows that include the search term are shown, while rows that don’t are hidden. This filtering happens instantly without reloading the page.

Example Usage

  • Typing “Finance” will only show rows containing the “Finance” department.
  • Typing “Alice” will only display the row with the employee “Alice Johnson.”
  • Typing “Manager” will show any rows that include the term “Manager” in any column, such as HR Manager or Sales Manager.

This setup provides a simple, client-side search function for any table, allowing for quick and efficient data filtering with minimal setup.

Related Posts

More content you might like

Tutorial

How to Translate URLs in React (2025 Guide)

Create i18n.js:

import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import LanguageDetector from 'i18next-browser-languagedetector';

import en from './locales/en.json';
import fr from './locales/fr.json';

i18n
  .use(LanguageDetector)
  .use(initReactI18next)
  .init({
    resources: { en: { translation: en }, fr: { translation: fr } },
    fallbackLng: 'en',
    interpolation: {
      escapeValue: false,
    },
  });

export default i18n;

May 04, 2025
Read More
Tutorial

Globalization in React (2025 Trends & Best Practices)

In 2025, React globalization goes beyond just i18n (internationalization). It includes:

  • Text translation (i18n)
  • Locale-aware formatting (dates, numbers, currencies)
  • Cultural UX adaptations (e.g., RTL layouts, color symbolism)
  • Language switching + SEO compatibility
  • Region-based content rendering (e.g., laws, units, timezones)

May 04, 2025
Read More
Tutorial

Implementing Internationalization (i18n) in a Large React Application (2025 Guide)

import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import LanguageDetector from 'i18next-browser-languagedetector';

// Import translation files
import en from './locales/en.json';
import fr from './locales/fr.json';

i18n
  .use(LanguageDetector) // Detects user language
  .use(initReactI18next)
  .init({
    resources: {
      en: { translation: en },
      fr: { translation: fr },
    },
    fallbackLng: 'en',
    interpolation: {
      escapeValue: false, // React already escapes
    },
    detection: {
      order: ['localStorage', 'navigator', 'htmlTag'],
      caches: ['localStorage'],
    },
  });

export default i18n;

Create folder structure:

May 04, 2025
Read More
Tutorial

Building Micro-Frontends with Webpack Module Federation (2025 Guide)

By following this guide, you’ve created a flexible, scalable frontend system that combines React and Vue in real time — powered by the magic of Webpack 5.

  • Add a third micro-frontend (e.g., a user-profile module in Angular)
  • Deploy to cloud services (e.g., Vercel, Netlify, or AWS S3 + CloudFront)
  • Explore SSR with Next.js + Module Federation

May 04, 2025
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Be the first to share your thoughts!