带有jquery的简单表过滤器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了带有jquery的简单表过滤器相关的知识,希望对你有一定的参考价值。

have to change this snippet in order to hide filtered rows. Not tried out yet, but works fine in the jsfiddle
  1. Original example here: http://jsfiddle.net/hHJxP/
  2. $(document).ready(function() {
  3. $("input#search").keyup(function() {
  4. var self = $(this);
  5. $("tbody td").css("border", "0px").each(function(i, obj) {
  6. if($(obj).html().toLowerCase().indexOf(self.val().toLowerCase()) > -1 && self.val()) {
  7. $(obj).css("border", "1px solid blue");
  8. }
  9. });
  10. });
  11. });
  12.  
  13. ---------------------------------------------
  14. changed to this
  15.  
  16. var columnFilter = 2;
  17.  
  18. // to apply the filter on the second column in a table
  19. $('body').on('keyup', '#input', function(e){
  20. try{
  21. var self = $(this);
  22. var value = $.trim(self.val()).toLowerCase();
  23. // apply the filter only on the iLocation column
  24. var locationFilter = 'td:nth-child('+columnFilter+')';
  25. $(locationFilter).each(function(i, val) {
  26. var cellContent = $.trim($(this).text()).toLowerCase();
  27. if(cellContent.indexOf(value) == -1)
  28. $(val).parent('tr').hide();
  29. else $(val).parent('tr').show();
  30. });
  31. } catch(e){
  32. console.log('Error! - ' +e);
  33. }
  34. });

以上是关于带有jquery的简单表过滤器的主要内容,如果未能解决你的问题,请参考以下文章

使用jQuery数据表中的列过滤器下拉列表修复标头

处理屏幕旋转上的片段重复(带有示例代码)

使用带有条件过滤器的 Include() 连接两个表

当jquery过滤器没有返回结果时,在div中显示消息

将数据从底部工作表对话框片段传递到片段

使用 jquery 动态更新 DataTable 内容