Skip to main content

HTML Table Pure JS LIVE search for all columns

HTML Table Pure JS LIVE search for all columns

Hello, Today we learn how to add live search for html without jQuery . 


Why we are using PURE JS ?

jQuery syntax is easy and simple compare to javascript but sometimes  jQuery have conflict issues with other libraries and also it takes more time compare to javascript.

So here is the full code and js function to add search in html table


HTML CODE


 
<input id="dls_search_input" onkeyup="search_table()" type="text" />
 
 <table class="dls-table dls-table-element" id="dlsTableAirline">
 <thead>
 <tr>
   <th>First Name</th>
   <th>Last Name</th>
   <th>Email</th>
  </tr>
 </thead>
       <tbody>
        <tr>
         <td>Jackson</td>
         <td>Doe</td> 
         <td>john@gmail.com</td>
        </tr>
        <tr>
  <td>Micheal</td>
  <td>Doe</td> 
  <td>mdoe@gmail.com</td>
        </tr>
        <tr>
  <td>Code</td>
  <td>rain</td> 
  <td>thecoderain@gmail.com</td>
        </tr> 
        </tbody>
</table> 


        

JS CODE

function search_table(){
  // Declare variables 
  var input, filter, table, tr, td, i;
  input = document.getElementById("dls_search_flight_input");
  filter = input.value.toUpperCase();
  table = document.getElementById("dlsTableAirline");
  tr = table.getElementsByTagName("tr");

  // Loop through all table rows, and hide those who don't match the search query
  for (i = 0; i < tr.length; i++) {
    td = tr[i].getElementsByTagName("td") ; 
    for(j=0 ; j-1) {
          tr[i].style.display = "";
          break ; 
        } else {
          tr[i].style.display = "none";
        }
      } 
    }
  }
}
 

Explaination
First we have created an input field where user can type anything to search in table.
After that we have created one HTML table that will contain all user data
After that we have added one js function to add search in html table. In the javascript function we get input field value and then get all rows of table and match all columns value one by one and if any row that contains the input field value then it will show otherwise it will hide. So its easy process to add search in html table using pure javascript function.
Thank you.

Recent links
How to search value in all columns of a table
Table search with js
JS function to add search based on input field
Javascript function for searching
HTML table add search
HTML JS searching functionality
Input on keyup search in html table
Simple js script to add searching in html table


Comments

  1. Woah what an article you've written! Great work.
    Adairs Coupon Code

    ReplyDelete
  2. Look at the way my friend Wesley Virgin's biography starts in this shocking and controversial video.

    As a matter of fact, Wesley was in the army-and shortly after leaving-he unveiled hidden, "SELF MIND CONTROL" tactics that the government and others used to get everything they want.

    As it turns out, these are the same secrets many famous people (especially those who "come out of nowhere") and top business people used to become rich and famous.

    You've heard that you use less than 10% of your brain.

    Mostly, that's because most of your brainpower is UNCONSCIOUS.

    Maybe that conversation has even taken place IN YOUR very own brain... as it did in my good friend Wesley Virgin's brain around seven years ago, while driving an unregistered, trash bucket of a car without a license and $3.20 on his debit card.

    "I'm very frustrated with living check to check! When will I get my big break?"

    You've been a part of those those questions, am I right?

    Your very own success story is going to be written. All you have to do is in YOURSELF.

    Take Action Now!

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. this code not working

    for(j=0 ; j-1) {
    tr[i].style.display = "";
    break ;
    } else {
    tr[i].style.display = "none";
    }
    }
    }
    }
    }

    ReplyDelete
    Replies
    1. You have wrong syntax of for loop , please use like this
      for(i=0 ;i < 10; i++) {
      tr[i].style.display = "";
      break ;
      } else {
      tr[i].style.display = "none";
      }
      }
      }
      }
      }

      Delete

Post a Comment

Popular posts from this blog

Run and compile sass scss file to css using node

  Today we learn how to use scss and generate css using node  or Run and compile sass scss file to css using node   So please follow simple  steps :-   Today we will create a project that can read scss file and generates css with it  Note: Make sure you have installed node in your system. If you want to help to install node js based on your system then check our other tutorial or check node js official website. Now create a blank folder and open  terminal(linux) or cmd(windows) and navigate to your current project folder by using cd command Now run below command npm init after enter it will ask you some package info that you can fill according to you or just keep enter until it finished. The above command will generate package.json file Now  we will install npm module that will convert our scss to css Run below command: npm install node-sass So we have installed node-sass package . Now open package.json file in your editor and add below code into it into

How to retrieve Facebook Likes, share , comment Counts

function facebook_count($url){     // Query in FQL     $fql  = "SELECT share_count, like_count, comment_count ";     $fql .= " FROM link_stat WHERE url = '$url'";     $fqlURL = "https://api.facebook.com/method/fql.query?format=json&query=" . urlencode($fql);     // Facebook Response is in JSON     $response = file_get_contents($fqlURL);     return json_decode($response); } $fb = facebook_count('https://www.facebook.com/BahutHoGyiPadhai'); // facebook share count echo $fb[0]->share_count;  echo "like"; // facebook like count echo $fb[0]->like_count ; echo "comment"; // facebook comment count echo $fb[0]->comment_count;  ?>

jQuery Datatable add date range filter

jQuery Datatable add date range filter Datatable is most useful jQuery plugin that helps to make our html tables more powerful and give powers to user to filter , search, sort, pagination etc, But Data table provides a common filter only and yes we can customize and add filter for each column, but still sometimes we need an advance filter like show results only between a date range, So today we will learn how to create a minimum and maximum date range fields and show date picker on it, and user can fill dates by selecting dates and data table will auto filter records based on it. Keep follow below steps :- I am using Bootstrap if you want to use any other framework then you can use. Create a new index.php file  and paste below code in it, i have used all required CDN like bootstrap, datatable, datepicker etc. <!DOCTYPE html> <html> <head>     <title>Datatable Date Range Filter Example</title>     <link rel="stylesheet" href="https://maxcd