2011-05-26 105 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