Add text box which filters row based on the values in the 1st column only

Add text box which filters row based on the values in the 1st column only

sarthaks21sarthaks21 Posts: 41Questions: 8Answers: 0

If the table is :

Name Age City

Harry 33 XYZ
Ron 31 YUI
Bill 2 HAR

I want a text box outside the table to only use the 1st column for filtering purpose and then show all the columns of the filtered row.

This uses all the columns for filtering. So if I type HAR in the texbox, I will get 2 rows, Harry and Bill as both contain HAR.

The else part contains the search code:

$("#gfg").on("keyup", function() {
    $('.extable').hide();
    var value = $(this).val().toLowerCase();

    if(value == ''){
        $('.s_table').hide();
        $('.extable').show();
    }
    else{
      var x = $("#secondID tr")
      $("#secondID tr").filter(function() {
          $(this).toggle($(this).text()
          .toLowerCase().indexOf(value) > -1)
          $('.s_table').show();
      });

    }

  });

If I add td to the filter variable, eg:

$("#secondID tr td").filter(function() {
          $(this).toggle($(this).text()
          .toLowerCase().indexOf(value) > -1)
          $('.s_table').show();
      });

This does the same thing but only shows the columns where the searched key appears.

Thanks in advance!

Answers

This discussion has been closed.