Sort a table fast by its first column with Javascript or jQuery

后端 未结 5 1259
你的背包
你的背包 2020-12-01 08:18

I have a table which is dynamically populated from FullCalendar. The problem is that FullCalendar does not care about its original order.

T

5条回答
  •  孤独总比滥情好
    2020-12-01 08:37

    Try an approach like this: http://jsfiddle.net/qh6JE/

    var rows = $('#caltbl > tbody').children('tr').get(); // creates a JS array of DOM elements
    rows.sort(function(a, b) {  // use a custom sort function
        var anum = parseInt($(a).find(".sortnr").text(), 10);
        var bnum = parseInt($(b).find(".sortnr").text(), 10);
        return anum-bnum;
    });
    for (var i = 0; i < rows.length; i++) {  // .append() will move them for you
        $('#caltbl > tbody').append(rows[i]);
    }
    

提交回复
热议问题