Skip to content Skip to sidebar Skip to footer

Remove Extra Cell Spaces

I have a script below: I use this script for searching text with an HTML table. It have more than 500 cells like 100 rows and 5 columns etc. This script works well for finding tex

Solution 1:

Try this! =)

<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><inputtype="text"class="input"/><divclass="print"></div><script>var data = ['food', 'bar', 'google']; // your datavar fx = function(text) {
    var print = function(list,s) {
        var table = $('<table/>').css('width','100%');
        var x = 0;
        while (list[x]) {
            var tr = $('<tr/>');
            while (list[x] && x < 5) {
            	var td = $('<td/>').text(list[x])
            	if(s == list[x]){
            		 td.css('background','red');
            	}
                tr.append(td);
                x++;
            }
            table.append(tr);
        }
        $('.print').html(table);
    }

    if (typeof text === "undefined") {
        print(data, '');
    } else {
        var find = [];

        for (var i = 0; data[i]; i++) {
            if (data[i].toLowerCase().indexOf(text.toLowerCase()) == 0) find[find.length] = data[i];
        }

        print(find,text);
    }
}

$(function() {
    $('.input').keyup(function() {
        fx($(this).val());
    });
    fx();
});
</script>

Post a Comment for "Remove Extra Cell Spaces"