Сортировка таблицы по атрибуту (jQuery)

Sanu0074
На сайте с 31.08.2012
Offline
110
1416

Есть таблица

<table>

<tbody>
<tr>
<th>cell 1</th>
<th>cell 2</th>
</tr>
<tr data-sort="8">
<th>cell 1</th>
<th>cell 2</th>
</tr>
<tr data-sort="12">
<th>cell 1</th>
<th>cell 2</th>
</tr>
<tr data-sort="2">
<th>cell 1</th>
<th>cell 2</th>
</tr>
<tr data-sort="7">
<th>cell 1</th>
<th>cell 2</th>
</tr>
<tr data-sort="0">
<th>cell 1</th>
<th>cell 2</th>
</tr>
<tr data-sort="0">
<th>cell 1</th>
<th>cell 2</th>
</tr>
</tbody>
</table>

Нужно ее строки отсортировать по параметру data-sort, по убыванию, чтоб было так:

<table>

<tbody>
<tr data-sort="12">
<th>cell 1</th>
<th>cell 2</th>
</tr>
<tr data-sort="8">
<th>cell 1</th>
<th>cell 2</th>
</tr>
<tr data-sort="7">
<th>cell 1</th>
<th>cell 2</th>
</tr>
<tr data-sort="2">
<th>cell 1</th>
<th>cell 2</th>
</tr>
<tr data-sort="0">
<th>cell 1</th>
<th>cell 2</th>
</tr>
<tr data-sort="0">
<th>cell 1</th>
<th>cell 2</th>
</tr>
<tr>
<th>cell 1</th>
<th>cell 2</th>
</tr>
</tbody>
</table>

Как это сделать наиболее лучшим или простым способом?

IL
На сайте с 20.04.2007
Offline
435
#1
... :) Облачные серверы от RegRu - промокод 3F85-3D10-806D-7224 ( http://levik.info/regru )
Sanu0074
На сайте с 31.08.2012
Offline
110
#2

ivan-lev, вот так сортирует

$wrapper.find('tr').sort(function (a, b) {
return +a.getAttribute('data-sort') - +b.getAttribute('data-sort');
})
.appendTo( $wrapper );

а как сделать сортировку в обратном порядке? по убыванию...

p.s.

все понял, b - a)))

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий