2011-05-26 89 views
0

我需要过滤我的表格,因此它只使用所需的最小行数,例如,如果表格维度的宽度为5列,那么具有say 12结果的过滤器的结果应该有3行。我现在所拥有的只是过滤掉一排行,并留下行数太多的表格。Jquery过滤表格单元格

的jQuery:

$("#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")) < 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++; 

回答

0

这是行不通的。而不是td,你最好使用具有固定宽度和高度的div,并应用float:left。然后答案将始终显示为完整行,除了可能的最后一行。

你可以使用td,但这很难。你必须得到td,然后用tr重建整个表,然后把td放回去。

+0

我期待的答案:]:[ – 2011-05-26 11:14:37