title: Jquery filtering table cells
body: <p>I need to filter my table so it only uses the minimum amount of rows needed, for example the result of a filter with say 12 results should have 3 rows if the table dimension had a width of 5 columns. What i have now only filters out columns of rows leaving a table with too many rows. </p>
  
  <p>jQuery:</p>
  
  <pre><code>$("#filter").keyup(function(){
  
          // Retrieve the input field text and reset the count to zero
          var filter = $(this).val(), count = 0;
  
          // Loop through the comment list
          $("td").each(function(){
  
              // If the list item does not contain the text phrase fade it out
              if ($(this).text().search(new RegExp(filter, "i")) &lt; 0) {
                  $(this).hide();
  
              // Show the list item if the phrase matches and increase the count by 1
              } else {
                  $(this).show();
                  count++;
              }
          });
  
          // Update the count
          var numberItems = count;
          $("#filter-count").text("Number of Comments = "+count);
      });
  
  $i++;
  </code></pre>