0

I am trying to filter an html table on column values (vertically like MS Excel filter). I thought following code would work. It is failing, can someone help me understand why it is failing?

Error:

$("tr").each.find is not a function [Break On This Error]

$('tr').each.find('td').eq(coli)(function() {

the header row of the table has diff class applied to it, and body has diff class applied, if it matters...

        rowi = this.rowIndex;
        var coli = e.target.cellIndex;
        cellval = $('tr').eq(rowi).find('td').eq(coli).text();

    $("#filterbutton").click(function() {
        var row = new Array();
        $('tr').each.find('td').eq(coli)(function() {
                if ($(this).text() == cellval) {  //  you can add aditional filter criteria... || $(this).text() == 50) {
                    row.push($(this).index());
                }
            });
        $('th,td').each(function() {
            if (($.inArray($(this).index(), row)==-1) && ($(this).index() != '0')){$(this).hide();}
        });
    });

3 Answers 3

1

$('tr').each expects a function to call on each tr:

$('tr').each(function() {
    var $cell = $(this).find('td').eq(coli);

    if ($cell.text() == cellval) {
        row.push(this.rowIndex);
    }
});
Sign up to request clarification or add additional context in comments.

Comments

0

$('tr').each.find('td').eq(coli)(function() {

should be:

$('tr td:eq(' + coli +')').each(function() { ...

Comments

0

You are using the wrong syntax here.. Instead of

$('tr').each.find('td').eq(coli)(function() {
           if ($(this).text() == cellval) { 
              row.push($(this).index());
           }
   });

// Try this

$('tr').each.find('td').eq(coli)(function() {
      var $curr = $(this).find('td:eq('+ coli + ')') ; (OR) $(this).find('td').eq(coli) ; 

      if ($curr.text() == cellval) { 
          row.push($(this).index());
      }
   });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.