On Mar 31, 12:36 pm, Bob O <sngndn...@gmail.com> wrote: > I have a YUI datatable that im live filtering from a text field. The > problem im having is when i get a lot of records, its really slow..
When you are trying to enhance performance, the best way to accomplish it is to start moving away from the generalized jQuery way of doing things are start coding POJS (plain old javascript) that manipulates objects at the lowest possible level. > Any help refactoring this to make it run smoother would be great. I'll give you a few tips, but depending on your specific situation it may not be enough to actually improve performance enough to matter. > $(document).ready(function () { > searchbox.bind('change keyup', function() { > member_row.each(function() { > var number = $(this).find('.yui-dt0-col-PhoneNumber div').text(); > var name = $(this).find('.yui-dt0-col-Name div').text(); Avoid repeated calls to $() on the same object. Create a variable reference instead. If the phone number field has a match, there is no need to check the name, so you can potentially avoid that lookup. > var search_check_value = (name + number); > var search_value = searchbox.val(); No need to do this with every loop iteration. Doing it once at the top would be enough. > if (search_check_value.indexOf(search_value) > -1) { > $(this).show(); > } else { > $(this).hide(); Again, use a cached reference to $(this). Using show() and hide() will be slower than working at a lower level. I haven't tested this, and I don't normally use "contains()" so I hope I got the syntax right, but take a look: searchbox.bind('change keyup', function() { var search_value = searchbox.val(); member_row.each(function() { var $tr = $(this); if ($tr.find('.yui-dt0-col-PhoneNumber div').contains (search_value).length>0 || $tr.find('.yui-dt0-col-Name div').contains (search_value).length>0) { $tr[0].style.display='none'; else { $tr[0].style.display=''; } }); }); Personally, I would also avoid using each(), and avoid the find() calls by using native DOM methods if this doesn't offer any speed-up. Matt Kruse