i'm trying to inital sort a table by it's row-numbers from an array/variable like
$list: row0=id2;row1=id0;row2=id1...
<table>
<tr id="0">...</tr>
<tr id="1">...</tr>
<tr id="2">...</tr>
</table>
How can i handle with tablesorter that the rows will be sorted like in $list?
thanks for any tipp or workaround :)
This is a possible duplicate of: How to sort DOM elements while selecting in jQuery?
$('#myt tr').sort(function(a, b) {
if (parseInt(a.id) > parseInt(b.id)) return 1;
else return -1;
}).each(function() {
$('#myt').append($(this));
});
td {
border: 1px solid grey;
padding: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table id='myt'>
<tr id="8">
<td>8</td>
</tr>
<tr id="1">
<td>1</td>
</tr>
<tr id="21">
<td>21</td>
</tr>
<tr id="5">
<td>5</td>
</tr>
</table>
</div>
maybe not what was originally intended but it's a workaround :)
var sortTable = [1,5,2,3,4];
$.each(sortTable, function(){
$("table#productList").append($("#" + this));
})
thanks for the responses and help!!