Petty_Crim
Petty_Crim

Reputation: 441

JQuery Multiple Group Sort

I need to sort a table of users alphabetically based upon a value in a td element. I can do basic sort fine but I have 3 tbodies per user and I need them all to stick together rather then just a single one of those tbodies being sorted.

This is an example of my table:

<tbody1>
<tr><td>The Value To Base Sort On(username)</td></tr>
<tr></tr>
</tbody>
<tbody2>
<tr><td>some other stuff</td></tr>
<tr></tr>
</tbody>
<tbody1>
<tr><td>other stuff</td></tr>
<tr></tr>
</tbody>

I need these 3 tbodies to remain linked next to each other when the table is sorted, however all 3 should be sorted based upon a value in the first tbody if that makes sense.

Upvotes: 0

Views: 570

Answers (1)

David Laberge
David Laberge

Reputation: 16061

Here is the jQuery plugin you are looking for:

http://james.padolsey.com/javascript/sorting-elements-with-jquery/

$('#someId>li').sortElements( function(a, b){ return $(a).text() > $(b).text() ? 1 : -1; } );

Upvotes: 1

Related Questions