> Perhaps I didn't emphasize missed that this is within the 
> tablesorter plugin. The tablesorter plugin will reorder the 
> table, sorting by specific columns. The rows would no longer 
> be accurate after the reordering. The zebra widget for 
> tablesorter handles this by the following code:
>     $.tablesorter.addWidget({
>       id: "zebra2",
>       format: function(table) {
>         $("tr:visible",table.tBodies[0])
>           .filter(':even')
>             .removeClass(table.config.widgetZebra.css[1])
>             .addClass(table.config.widgetZebra.css[0])
>           .end()
>           .filter(':odd')
>             .removeClass(table.config.widgetZebra.css[0])
>             .addClass(table.config.widgetZebra.css[1]);
>       }
>     });
> 
> I'm wondering how I get this not to take action for certain 
> <tr> and/or <td> elements.

Well, that is a horse of a different color!

That zebra widget is working a little too hard. You don't need to set special 
classes on both the even and odd rows to do zebra
striping, you just pick either the even or odd rows and add a class to them.

Let's fix that and add your special nonzero TD handling at the same time. I'm 
also going to take the liberty of hard coding the
classnames instead of pulling them from table.config.widgetZebra.css[0|1], 
mostly because I'm not familiar with the rest of this
code.

I'll also assume that your special TD that has the zero/nonzero value has a 
classname of 'nonzeroCol'.

So you could code the format function like this (untested code, you debug it!):

  format: function(table) {
    var evenClass = 'even', nonzeroClass = 'nonzero';
    $("tr:visible",table.tBodies[0])
      .removeClass(evenClass+' '+nonzeroClass)
      .filter(':even')
        .addClass(evenClass)
      .end()
      .filter( function() {
        return $('.nonzeroCol',this).html() != '0';
      })
        .addClass(nonzeroClass);
  },

If your special TD doesn't have a classname, you can substitute any appropriate 
selector in the second .filter call, such as
$('td:eq(3)',this).

-Mike

Reply via email to