Saving the elements beforehand (if they're not gonna change), rolling
your own loop and doing only what is necessary inside it should
increase performance already. I'm sure there are faster ways, knowing
how the HTML is structured you could speed up the element look-ups
too.

$(document).ready(function () {
  var searchbox = $('.member_search_input'),
  mRows = $('#members_data_table_wrap > table > tbody > tr')
  mPhones = member_rows.find('yui-dt1-col-PhoneNumber div a'),
  mNames = member_rows.find('.yui-dt1-col-Name div');
  searchbox
   .click(function() {
      $(this).val('');
   })
   .bind('change keyup', function(){
      var i = rows.length,
      search_val = searchbox.val(),
      while(i--){
        text = $(mPhones[i]).text() + $(mNames[i]).text();
        $(mRows[i])[ (text.indexOf(search_val) > -1) ? 'show' :
'hide' ]();
      };
   });

});

- ricardo
On Feb 15, 4:46 am, Bob O <sngndn...@gmail.com> wrote:
> hello,
> Im trying to figure out a better way to do this. it works but its very
> sluggish, so i think theyre might be a better way to iterate?
>
> i have an input field = .searchbox
>
> and then i have a YUI datatable that contains about 65 rows.
> when i start to type in the search field, it iterates over all the
> tr's looks at 2 cell text values and then uses the indexOf method to
> determine whether or not to display the <tr>
>
> is there a way that i can iterate once and put those values into cache
> or something?
>
> here is my code.
>
> $(document).ready(function () {
>   var searchbox = $('.member_search_input');
>   var member_row = $('#members_data_table_wrap table tbody tr');
>   searchbox.click(function() {
>     $(this).val('');
>   });
>    searchbox.bind('change keyup', function() {
>       member_row.each(function() {
>         var number = $(this).find('.yui-dt1-col-PhoneNumber div
> a').text();
>         var name = $(this).find('.yui-dt1-col-Name div').text();
>         var search_check_value = (name + number);
>         var search_value = searchbox.val();
>          if (search_check_value.indexOf(search_value) > -1) {
>            $(this).show();
>           } else {
>           $(this).hide();
>         }
>       });
>     });
>
> });

Reply via email to