Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4627064
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:30:46+00:00 2026-05-22T03:30:46+00:00

I want to filter a table using jQuery hide/show based on what the user

  • 0

I want to filter a table using jQuery hide/show based on what the user selects from multiple select elements.

I want the user to be able to select multiple values from 1, 2 or 3 of the select elements. So maybe they’ll select 2 trainers, 1 recruit and 1 status, or maybe just 1 trainer. Planning on creating a function that will run when the user clicks any of the options.

The way I see it, each select element will have an array of values that the user has selected. So I’ll need to loop through each array and compare it to the text in that specific column. Would be easy enough if the options were from only 1 select element. But since it could be 1, 2 or all 3, I’m having trouble getting my head around it.

Any help would be GREATLY appreciated.

Table:

<table id="reportsTable">
  <thead>
    <th>Report Number</th>
    <th>Date</th>
    <th>Name</th>
    <th>Trainer</th>
    <th>Status</th>
  </thead>
  <tbody>
    <tr>
      <td>12345-1</td>
      <td>05/01/2011</td>
      <td>First Recruit</td>
      <td>First Trainer</td>
      <td>Complete</td>
    </tr>
    <tr>
      <td>12345-2</td>
      <td>05/02/2011</td>
      <td>First Recruit</td>
      <td>Second Trainer</td>
      <td>In Progress</td>
    </tr>
    <tr>
      <td>54321-1</td>
      <td>05/03/2011</td>
      <td>Second Recruit</td>
      <td>First Trainer</td>
      <td>Created</td>
    </tr>
  </tbody>
</table>

Selects:

<select multiple="multiple" name="trainerFilter">
  <option value="firsttrainer">First Trainer</option>
  <option value="secondtrainer">Second Trainer</option>
</select>
<select multiple="multiple" name="recruitFilter">
  <option value="firstrecruit">First Recruit</option>
  <option value="secondrecruit">Second Recruit</option>
</select>
<select multiple="multiple" name="statusFilter">
  <option value="created">Created</option>
  <option value="inprogress">In Progress</option>
  <option value="complete">Complete</option>
</select>

Looks like I can’t post an answer to my question for 8 hours but this is what I came up with thanks to @Spencer Ruport. It ended up being a lot more convoluted than I expected thanks to having to account for all possible entries. The user could select something from the first select element, nothing from the second, and maybe 2 from the third. Or maybe the user doesn’t select anything from the first and 2 from the second. For any given input, there may be 6+ filters than need to be applied.

I’m sure there’s a better way than this, and it looks like @Alison may have linked to one, but it works.

    function filterReports() {
        $('.report').hide(); //Set all rows to hidden.
        trainerVals = $('#trainerFilter').val();
        recruitVals = $('#recruitFilter').val();
        statusVals = $('#statusFilter').val();
        if (trainerVals) { //Check if any trainers are selected.
            $.each(trainerVals, function(index, trainer) {
                filtered = false; 
                classString = '';
                classString += '.' + trainer;
                if (recruitVals) { //Check if trainers and recruits are selected.
                    $.each(recruitVals, function(index, recruit) {
                        filtered = false;
                        secondString = ''; 
                        secondString = classString + '.' + recruit; //Concat to a new string so we keep the old one intact.
                        if (statusVals) { //Check if trainers, recruits and statuses are selected.
                            $.each(statusVals, function(index, status) {
                                filtered = false;
                                finalString = '';
                                finalString += secondString + '.' + status; //Again concat to a new string.
                                $(finalString).show();
                                filtered = true; //By setting filtered to true, we only run the show once.
                            });
                        }
                        if (!filtered) { //If trainers and recruits are selected, but not a status, we need to apply that filter.
                            $(secondString).show();
                            filtered = true;
                        }
                    });
                }
                if (!filtered && statusVals) { //If only trainers and statuses are selected, go through those.
                    $.each(statusVals, function(index, status) {
                        filtered = false;
                        finalString = '';
                        finalString += classString + '.' + status;
                        $(finalString).show();
                        filtered = true;
                    });
                }
                if (!filtered) { //If only trainers are selected, apply that filter.
                    $(classString).show();
                    filtered = true;
                }
            });
        }
        if (!filtered && recruitVals) { //If trainers are not selected, by recruits are, run through the recruits.
            $.each(recruitVals, function(index, recruit) {
                classString = '';
                classString += '.' + recruit;
                if (statusVals) { //Check if recruits and statuses are selected
                    $.each(statusVals, function(index, status) {
                        finalString = '';
                        finalString += classString + '.' + status;
                        $(finalString).show();
                        filtered = true;
                    });
                }
                if (!filtered) { //If only recruits are selected, apply that filter.
                    $(classString).show();
                    filtered = true;
                }
            });
        }
        if (!filtered && statusVals) { //If both trainers and recruits are not selected, but statuses are, run through those.
            $.each(statusVals, function(index, status) {
                classString = '';
                classString += '.' + status;
                $(classString).show();
                filtered = true;
            });
        }
        if (!filtered) {
            //No filters selected.
        }
        $("tr").removeClass("even"); //Remove current zebra striping.
        $("tr:visible:even").addClass("even"); //Add zebra striping only for rows that are visible.
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:30:46+00:00Added an answer on May 22, 2026 at 3:30 am

    This is pretty simple to do using multiple classes (I usually call them markers when they’re not being used for styles.)

    <table>
      <thead>
        <th>Report Number</th>
        <th>Date</th>
        <th>Name</th>
        <th>Trainer</th>
        <th>Status</th>
      </thead>
      <tbody>
        <tr class="obj_first_recruit obj_first_trainer obj_complete obj_row_item">
          <td>12345-1</td>
          <td>05/01/2011</td>
          <td>First Recruit</td>
          <td>First Trainer</td>
          <td>Complete</td>
        </tr>
        <tr class="obj_first_recruit obj_second_trainer obj_in_progress obj_row_item">
          <td>12345-2</td>
          <td>05/02/2011</td>
          <td>First Recruit</td>
          <td>Second Trainer</td>
          <td>In Progress</td>
        </tr>
        <tr class="obj_second_recruit obj_first_trainer obj_created obj_row_item">
          <td>54321-1</td>
          <td>05/03/2011</td>
          <td>Second Recruit</td>
          <td>First Trainer</td>
          <td>Created</td>
        </tr>
      </tbody>
    </table>
    

    Then anytime you want to filter just concatenate all the corresponding markers with periods for example:

    $(".obj_row_item").hide();
    $(".obj_first_recruit.obj_second_trainer.obj_in_progress").show();
    

    For simplicity’s sake you can make the values of the dropdowns correspond to the marker names making your statement look something like:

    $("." + $("#dropdown1").val() + "." + $("#dropdown2").val() + "." + $("#dropdown3").val()).show();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm displaying a table with multiple rows and columns. I'm using a JQUERY plugin
I want to implement an ISAPI filter like feature using HttpModule in IIS7 running
I am using Ruby on Rails. I want to create a filter field on
I want to make a page so I can select filters in a jquery
So basically I have a main table, and I want to filter that data
I want to filter the selectable dates on a datepicker. I basically need to
I'm reading all the files in a single directory and I want to filter
I have a MultipleChoiceField on a form holding car makes. I want to filter
I want to intercept a request in a filter/servlet and add a few parameters
Why would I want to use PHP's filter library? Why wouldn't I? It seems

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.