1

I am trying to filter a table based on data attribute, instead on value inside the td tag.

The problem is, that I can't get it to work, because I always get this error:

Uncaught TypeError: Cannot call method 'match' of undefined

$(document).ready(function(){
    var elemens = $("td")
    searchInput = $("#search")
    searchInput.on('keyup',function(){

        elemens.each(function(){

            var re = new RegExp(searchInput.val(), 'gi');
            if( $(this).data('gui').match(re) === null )
            {
                $(this).parent('tr').hide();
            }else{
                $(this).parent('tr').show();
            }

        });                
    });
});​

My Fiddle: http://jsfiddle.net/T57ba/3/

1 Answer 1

3

The data attributes are on the tr not the td, also .data() will convert the applicable types, in this case numbers. Instead use .attr()

$(document).ready(function(){
    var elemens = $("tr")
    searchInput = $("#search")
    searchInput.on('keyup',function(){            
        elemens.each(function(){                
            var re = new RegExp(searchInput.val(), 'gi');
            if( $(this).attr('data-gui').match(re) === null ){
                $(this).hide();
            }
            else{
                $(this).show();
            }

        });                
    });
});​

DEMO

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, i see the mistake i made with td and tr, but what do you mean that .data() will convert types?

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.