Hi everyone,

I'm brand new to Prototype JS.
I just made use of it to create a basic function which can filter
table lines (show/hide) according to a column text search.

My first impression is that IE is dozens times slower than FF for this
thing.
As I'm new to Prototype, and that my code doesn't seem beautiful at
all (pretty basic thinking), I wonder if there would be a way to
"prototipize" it more, so that is would be more efficient and less
ugly.
Thanks for any advice that will make me learn Prototype and make my
code faster.

Here is the excerpt :

field_filter = function(nam, val) {
        var lines = $$("#annuaire_table > div > table > tbody > tr");
        // Gather cells that have our target column name as class :
they are cells of our current filtering column.
        // IS THERE ANY WAY TO GET THAT FROM "lines" DIRECTLY ?
instead of traversing DOM once again ?
        var ourcells = $$("#annuaire_table > div > table > tbody > tr
> ."+nam)
        // Removing previous search results : search results are made
of class changes.
        ourcells.each( function(i) {
          i.removeClassName("highlight");
          i.removeClassName("hide");
        } );
        // If our filter value is not empty...
        if( val.length > 0 )
        {
          // We partition our column's cells in 2 parts.
          var rtab = ourcells.partition( function(i) {
            i.cleanWhitespace();
            // Those which have a text content matching our search.
            if( i.empty() != true )
            {
              return ((i.textContent || i.innerText ||
"").toLowerCase().indexOf(val.toLowerCase()) >= 0);
            }
            // Those which don't.
            return false;
          } );
          var containstext = rtab[0];
          var notcontainstext = rtab[1];
          // We add "highlight" class to cells we care about (matching
search cells).
          containstext.each( function(j)
{ j.addClassName("highlight"); } );
          // We add "hide" class to others.
          notcontainstext.each( function(j)
{ j.addClassName("hide"); } );
        }
        // We hide every table line which has a cell with "hide"
class.
        lines.each( function(i) {
          var childcells = i.childElements();
          if( childcells.detect( function(j) { return
j.hasClassName("hide"); } ) )
          {
            i.hide();
          }
          else
          {
            i.show();
          }
        } );
       // THEN, IS THERE ANY WAY TO FIND TABLES WHERE ALL LINES ARE
HIDDEN ?
      };

Many thanks in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to