Фильтровать уже отфильтрованную таблицу или работать с несколькими фильтрами одновременно

#javascript #jquery

#javascript #jquery

Вопрос:

У меня есть таблица с несколькими фильтрами, я хочу отфильтровать столбцы и скрыть те, которые не содержат искомое ключевое слово, которое работает просто отлично, но я хочу, чтобы все фильтры работали одновременно. Рабочая таблица находится здесь, на этой страницеhttp://beta.flexxonsolutions.com/products/sata-iii/2-5-ssd-sata-iii-new1 /

И код jQuery

 jQuery(".searchTableInput2").on("keyup", function() {
      let searchKey = jQuery(this).val().toLowerCase();
         
          jQuery('.searchTable2 tr td,.searchTable2 tr th').show();  
       
      if(searchKey == '') return;
      var colCount = jQuery(".searchTable2 tr th").length;
      for (i = 2; i <= colCount; i  ) {
        let keyExists = false;
        jQuery('.searchTable2 tr td:nth-child(' i ')').each( function(){
          if(jQuery(this).text().toLowerCase().includes(searchKey)) {
            keyExists = true;
            return;
          }      
        });
        if(!keyExists) {
          jQuery('.searchTable2 tr td:nth-child(' i '), .searchTable2 tr th:nth-child(' i ')').hide();
        }
      }
    });

  //this is for search by flash
  jQuery(".searchFlashInput").on("change", function() {
      let searchKey = jQuery(this).val().toLowerCase();
      jQuery('.searchTable2 tr td,.searchTable2 tr th').show();
      if(searchKey == '') return;
      var colCount = jQuery(".searchTable2 tr th").length;
      for (i = 2; i <= colCount; i  ) {
        let keyExists = false;
        jQuery('.searchTable2 tr td:nth-child(' i ')').each( function(){
          if(jQuery(this).text().toLowerCase().split(', ').includes(searchKey)) {
            keyExists = true;
            return;
          }      
        });
        if(!keyExists) {
          jQuery('.searchTable2 tr td:nth-child(' i '), .searchTable2 tr th:nth-child(' i ')').hide();
        }
      }
    });

  //this is for search by features
  jQuery(".searchGradeInput").on("change", function() {
      let searchKey = jQuery(this).val().toLowerCase();
      jQuery('.searchTable2 tr td,.searchTable2 tr th').show();

      var test = [];
      if(searchKey == '') return;
      var colCount = jQuery(".searchTable2 tr th").length;
      for (i = 2; i <= colCount; i  ) {
        let keyExists = false;
        jQuery('.searchTable2 tr td:nth-child(' i ')').each( function(){
          if(jQuery(this).text().toLowerCase().includes(searchKey)) {
            keyExists = true;
            return;
          }      
        });
        if(!keyExists) {
          jQuery('.searchTable2 tr td:nth-child(' i '), .searchTable2 tr th:nth-child(' i ')').hide();
        }
     }
  });

       //reset button function
       jQuery('.tble_reset_filters').click(function(){
         jQuery('.searchFlashInput')[0].selectedIndex = 0;
         jQuery('.searchGradeInput')[0].selectedIndex = 0;
         jQuery('.searchTableInput2').val('');
         jQuery('.searchTableInput2').keyup();
       });
 
  

Комментарии:

1. похоже, вы решили проблему, когда я перешел по ссылке, которую вы дали?

2. Да, спасибо за ваше время