Saturday, January 18, 2014

Search on table by Jquery / JavaScript


$(document).ready(function() {
    $('.TxT').keyup(function() {
        searchTable($(this).val());
    });
});

function searchTable(inputVal) {
    var table = $('#Table');
    var allRow = table.find('.Row').length;
    table.find('.Row').each(function(index, row) {
        var allCells = $(row).find('td');
        if (allCells.length > 0) {
            var found = false;
            allCells.each(function(index, td) {
                var regExp = new RegExp(inputVal, 'i');
                if (regExp.test($(td).text())) {
                    found = true;
                    return false;
                }
            });
            if (found == true) {
                $("#recordeNotFound").hide();
                $(row).show();
            }
            else {
                allRow -= 1;
                $(row).hide();
            }
        } else {

        }
        if (allRow == 0) {
            $("#recordeNotFound").show();
        }
    });

};

No comments:

Post a Comment