-2

I want do searching follow by this link but i have multiple row to search in td value, so how i can add to search with data from all td ? Thanks!

$("#search").on("keyup", function() {
    var value = $(this).val();

    $("table tr").each(function(index) {
        if (index !== 0) {

            $row = $(this);

            var id = $row.find("td:first").text();

            if (id.indexOf(value) !== 0) {
                $row.hide();
            }
            else {
                $row.show();
            }
        }
    });
});
Govind Singh
  • 15,282
  • 14
  • 72
  • 106
koe
  • 736
  • 1
  • 12
  • 33

3 Answers3

0

here is the link

the new jquery :

$("#search").on("keyup", function() {
    var value = $(this).val();

    $("table tr").each(function(index) {
        if (index !== 0) {

            $row = $(this);

           $row.find("td").each(function(){
               var id =$(this).text();

            if (id.indexOf(value) !== 0) {
                $row.hide();
            }
            else {
                $row.show();
            }
           });
        }
    });
});
Youness
  • 1,468
  • 1
  • 9
  • 19
  • my code is can work already for data from the one column to search but what i asked above is i want search with data from multi column result to search – koe Jul 25 '14 at 10:48
  • yes and that code i put there is for searching in multi column test it and you will see – Youness Jul 25 '14 at 10:56
  • 1
    but your code, i test not work :( – koe Jul 25 '14 at 11:09
  • soo sorry to hear that but can you explain to me what do you want to do exactly i dont quit understand you sorry :( – Youness Jul 25 '14 at 11:27
  • by link i give above i can test with search data a column already but i want search with data from more column – koe Jul 27 '14 at 10:27
0

You can use filter() to find td elements within the current row which match the text. Try this:

var $row = $(this);
var tdMatches = $('td', $row).filter(function() {
    return $(this).text().indexOf(value) != -1;
}).length;
tdMatches == 0 ? $row.hide() : $row.show()

Updated fiddle

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
0

try

$("#search").on("keyup", function () {
    var value = this.value.trim();
    if (value) {
        var data = $("table tr td").filter(function () {
            return value == $(this).text();
        }).parent();
        $("table tr:gt(0)").hide();
        data.show();
    } else {
        $("table tr").show();  // all data show if the value is 0 If you want do or remove that
    }
});

DEMO

Balachandran
  • 9,567
  • 1
  • 16
  • 26
  • @Time check this link http://jsfiddle.net/rFGWZ/1081/ – Balachandran Jul 25 '14 at 10:42
  • Your demo is not work,Any my code is can work already for data from the first column to search but what i asked above is i want search with data from multi column result to search – koe Jul 25 '14 at 10:47