user1835840 user1835840 - 2 years ago 116
Javascript Question

Javascript table with {{#each}}, filtering not working

I have a table in which I want to make filtering functionality.

The table displays the records from meteor's collection through handlebars


The code looks like this:

keyup #filterbox': function(event){

var table = document.getElementById('example');

var len = table.rows.length;

for(var i=1; i< table.rows.length; i++){

var cellText = table.rows[i].cells[1].innerHTML.toLowerCase();


table.rows[i].style.display = "none";
table.rows[i].style.display = "block";

The this code works when I type matching letters with predefined cell.

But when I clear the input box, the whole table gets collapsed. Only after I refresh the page it displays properly.

What I am doing wrong here?

Answer Source

Try with

table.rows[i].style.display = "table-row";

instead of

table.rows[i].style.display = "block";

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download