I recently addressed the same need with the following code:

$(".listtable").tablesorter();
$(".listtable").bind("sortStart",function() {
    $("#busybar").fadeIn(400);
}).bind("sortEnd",function() {
    $(".listtable tr:odd").removeClass("alterow");
    $(".listtable tr:even").addClass("alterow");
    $("#busybar").fadeOut(400);
});
$(".listtable tr:even").addClass("alterow");
$(".listtable
tr").hover(function(){$(this).addClass("hoover")},function(){$(this).removeClass("hoover")});


The tr:even line near the bottom should be unnecessary if you define an
initial sort column/direction for the table, since that will entail a sort
taking place onload.  So I fade in the animgif 'busy' on sortStart (some of
my tables are several hundred rows of a dozen or two columns, taking several
seconds to sort sometimes) then on sortEnd I remove any 'alterow' class on
odd rows (clears ONLY from even rows that are now odd after sorting) then
applies 'alterow' class to even rows, in practice affecting only odd rows
that are now even, post-sort.  Originally I was clearing 'alterow' from all
then applying to all even rows, but the display update was often more
jarring that way.

Obviously the 'busybar' bit and the hover highlight are not pertinent to
your stated question, just part of the code chunk I've utilized, and
pasted.  (FWIW, 'hoover' is an in-joke - an ex employer of mine consistently
referred to onmouseover events as 'hoovering', and we all joked about it so
much it's sort of stuck ;)

I realize this can be condensed further, but haven't tried.  And I suspect
there's some way to chain the tr:odd and tr:even, but don't know if it would
be worth the effort, given that the odd vs even selection will still need to
take place.

j


> >> >> >> table starts out with alternating row colors.  but once i sort it
> >> by
> >> >> >> clicking on one for the columns. the row colors get all out of
> >> whack.
> >>
> >> >> >> can someone tell me how i can keep the alternating row colors in
> >> order
> >> >> >> after
> >> >> >> the sort?
>

Reply via email to