EGN
EGN

Reputation: 2572

Filter Table by column in jQuery

I have a jQuery script that filters a table if the entire row contains a keyword. However I want to limit it to one column only and have multiple text boxes, one for each column. I can't figure this one out. Any ideas?

here is the script http://jsfiddle.net/ukW2C/

$("#searchInput").keyup(function () {
    console.log("value=%o", this.value);
    //split the current value of searchInput
    var data = this.value.split(" ");
    //create a jquery object of the rows
    var jo = $("#fbody").find("tr")
    //hide all the rows
    .hide();

    //Recusively filter the jquery object to get results.
    jo.filter(function (i, v) {
        var $t = $(this);
        for (var d = 0; d < data.length; ++d) {
            if ($t.is(":contains('" + data[d] + "')")) {
                console.log(data[d]);
                return true;
            }
        }
        return false;
    })
    //show the rows that match.
    .show();
}).focus(function () {
    this.value = "";
    $(this).css({
        "color": "black"
    });
    $(this).unbind('focus');
}).css({
    "color": "#C0C0C0"
});

Upvotes: 1

Views: 7681

Answers (1)

Paulo Lima
Paulo Lima

Reputation: 1238

Just look only in the column that you want

http://jsfiddle.net/ukW2C/352/

 var $t = $(this).children(":eq("+indexColumn+")");

Upvotes: 4

Related Questions