I have a table which is dynamically populated from FullCalendar
.
The problem is that FullCalendar
does not care about its original order.
The table looks like this:
<table id="caltbl">
<thead>
<tr> <th> </th> <th> Date </th> <th> hours </th> ... </tr>
</thead>
<tbody>
<tr> <td class="sortnr">1</td> <td></td> ... </tr>
<tr> <td class="sortnr">3</td> <td></td> ... </tr>
<tr> <td class="sortnr">2</td> <td></td> ... </tr>
<tr> <td class="sortnr">4</td> <td></td> ... </tr>
</tbody>
</table>
The first of each row contains the number on which the table should be sorted.
I had this code to sort it:
var rows = $('#caltbl > tbody').children('tr').detach();
for (var counter = 1; counter<=rows.length; counter++) {
$(rows).each(function(index) {
if ($(this).find(".sortnr").text()==counter){
$('#caltbl > tbody:last').append($(this));
}
});
}
This works fine in Firefox but causes me a major headache in Internet Explorer because there are more than 500 items and it hangs. I could add a setTimeout
but that would not fix the real problem. The sorting is slow. What is a faster way to sort this?
Instead of having to start from the <table>
html, as I said it gets populated dynamically so I have an Array
which contains the html. 1 item per <tr>
(unsorted)