Font Size:
Ask Joget AI

Add Search Filter to List Grid Element

Introduction

This article demonstrates how to add a search filter to a List Grid element in a form using jQuery. This approach is useful when you want users to dynamically search or filter through rows of data displayed in the List Grid without needing to reload the form or rely on external list definitions.

How does it work?

  1. In Form Builder, add a Custom HTML element to a form with the List Grid element.

  2. Add the following jQuery script to implement the search filter feature:
    <input type="text" id="searchInput" placeholder="Search..." style="width:30%" />
     
    <script>
    $("body").on("page_loaded", function () {
        var $table = $("div[name='data_list_grid'] table");
        var $rows = $table.find("tbody tr");
         
        var visibleRowCount = $rows.filter(".pg-tr-show").length;
        console.log("Visible rows on page load: " + visibleRowCount);
     
        $("#searchInput").on("keyup", function () {
            var searchTerm = $(this).val().trim().toLowerCase();
     
            if ($table.length === 0) return; // Exit if no table is found
     
            if (searchTerm === "") {
                // Remove all display:none styles and restore original pagination behavior
                $rows.removeClass("filtered-out").css("display", "");
                return;
            }
     
            // Perform filtering
            $rows.each(function () {
                var rowMatches = false;
     
                $(this).find(".grid-cell").each(function () {
                    if ($(this).text().toLowerCase().includes(searchTerm)) {
                        rowMatches = true;
                        return false; // Break loop if a match is found
                    }
                });
     
                if (rowMatches) {
                    $(this).removeClass("filtered-out");
                } else {
                    $(this).addClass("filtered-out");
                }
            });
     
            // Hide filtered rows but ensure pagination still works
            $rows.hide();
            $rows.filter(".pg-tr-show").not(".filtered-out").fadeIn(200);
        });
    });
    </script>

    Expected Outcome

    A search filter will be displayed for the list grid as demonstrated below.

    List Grid with the Search result:

    Download Sample App

Download the sample app for the Add Search Filter to List Grid Element:
Created by Debanraj Last modified by Debanraj Ravindran on Apr 24, 2026