Live search through table rows

前端 未结 15 1859
失恋的感觉
失恋的感觉 2020-11-29 00:52

I want to do a live search through the table rows, using jQuery, the \"live\" word is the key, because I want to type the keywords in the text input, on the same site and I\

15条回答
  •  佛祖请我去吃肉
    2020-11-29 01:21

    Below JS function you can use to filter the row based on some specified columns see searchColumn array. It is taken from w3 school and little bit customised to search and filter on the given list of column.

    HTML Structure

    
    
         

      function myFunction() {
        var input, filter, table, tr, td, i;
        input = document.getElementById("myInput");
        filter = input.value.toUpperCase();
        table = document.getElementById("myTable");
        tr = table.getElementsByTagName("tr");
    
         var searchColumn=[0,1,3,4]
    
        for (i = 0; i < tr.length; i++) {
    
          if($(tr[i]).parent().attr('class')=='head')
            {
                continue;
             }
    
        var found = false;
          for(var k=0;k -1 ) {
                found=true;    
              } 
            }
        }
        if(found==true)  {
            tr[i].style.display = "";
        } 
        else{
            tr[i].style.display = "none";
        }
    }
    }
    

    提交回复
    热议问题
    COL 1 CoL 2 COL 3 COL 4 COL 5 COL 6