2014-02-11 51 views
0

我有一個表,並已實施了一些分頁。分頁工作正常!跨表搜索刪除尋呼

我還添加了一個文本字段,以便用戶可以搜索一列。這是用於

$("input#filter").keyup(function() { 
    var filtertext = $(this).val(); 
    $("#movie tbody tr").each(function(rowindex) { 
     $(this).children("td").eq(2).each(function(cellindex) { 
      if ($(this).text().indexOf(filtertext) < 0) { 
       $(this).parents("tr").hide(); 
      } else { 
       $(this).parents("tr").show(); 
      } 
     }); 
    }); 
}) 

但每當在文本框中的第一個字符,尋呼無二折騰的用戶類型和所有行是可見的再一次的邏輯。我該如何解決這個錯誤?

這裏的小提琴http://jsfiddle.net/Pja65/

PS:我沒有使用任何插件,因爲我有一個簡單的要求,不希望使用任何插件,它

回答

0

小提琴:http://jsfiddle.net/Pja65/1/
你有那裏有2-3個以上的錯誤。
1. $(this).children("td").eq(2)應該是$(this).children("td").eq(1)。它正在獲得第三列。
2.您需要通過調用paginate(firstRecord, pageSize);來檢查搜索項是否爲空,如果是,則顯示所有行。

$("input#filter").keyup(function() { 
var filtertext = $(this).val(); 
if(filtertext != '') 
    $("#movie tbody tr").each(function(rowindex) { 
     $(this).children("td").eq(1) 
      .each(function(cellindex) { 
       if ($(this).text().indexOf(filtertext) < 0) { 
        $(this).parents("tr").hide(); 
       } else { 
        $(this).parents("tr").show(); 
       } 
      }); 
    }); 
else 
    paginate(firstRecord, pageSize); 
}) 
+0

我觀察了幾件事。如果我輸入「1」,則顯示下一頁,而第一頁上顯示「1」。打字1968年不產生行,而4行應該出現 – darius