2011-07-07 22 views

回答

1

如果您正在使用jQuery再考慮優秀的jQuery數據表插件,它的成效斐然,一個簡單的表元素:http://www.datatables.net/

3

我寫了下面的功能我自己,你只是把它要過濾的列索引,以及您要過濾的文本框的ID。

不要忘記到GridView /表名稱更改爲您的

function filter(columnIndex, id) { 
     var filterText = $("#" + id).val().toLowerCase(); 

     var cellText = ""; 
     var cellTextSampleToCompare = ""; 

     $("#<%=YOUR_GRIDVIEW_NAME.ClientID%> tr:has(td)").each(function() { 
      cellText = $(this).find("td:eq(" + columnIndex + ")").text().toLowerCase(); 
      cellText = $.trim(cellText); //removes the spaces in the starting of the string value if exist 
      cellTextSampleToCompare = cellText.substring(0, filterText.length); 

      if (filterText != cellTextSampleToCompare) { 
       $(this).css('display', 'none'); 
      } 
      else { 
       $(this).css('display', ''); 
      } 
     }); 
    } 
+0

作品非常感謝! – Eliseo

0

這可能不是回答你的問題,但它可能會幫助人們誰到這裏來。

$(document).ready(function() { 
      $("#txtID").keyup(function() { 
       _this = this; 
       $.each($("#grdEmployee tbody").find("tr:has(td)"), function() { 
        if ($(this).text().toLowerCase().indexOf($(_this).val().toLowerCase()) != -1) 
         $(this).show(); 
        else 
        $(this).hide(); 

       }); 
      }); 
     });