jquery - JavaScript Sort to clear a sort that has already been made -


i trying create own sort function table, i'm not allowed use plugin part of university coursework.

now i've got javascript mark here sort table nicely:

var newdirection = 1; if ($(this).is('.sorted-asc')) {     newdirection = -1; }  var rows = $table.find('tbody > tr').get(); $.each(rows, function(index, row) {     row.sortkey =         findsortkey($(row).children('td').eq(column)); });  rows.sort(function(a, b) {     if (a.sortkey < b.sortkey) return -newdirection;     if (a.sortkey > b.sortkey) return newdirection;     return 0; }); 

the sortkey variables whether sorted alpha or numeric.

here change rows in table in correct order:

$.each(rows, function (index, row) {     $table.children('tbody').append(row);     row.sortkey = null; }); 

now love work out, there way in can reverse sort? don't mean .reverse() reverse order of table rows clear sort , put values way were.

i'd make table order default comes back.

edit: attempt @ it: declared previous variable after declared rows variable:

var previous = $table.find('tbody > tr').get(); 

and tried reorder in similar way how set it:

$table.siblings('a.reset').click(function () {     $.each(previous, function (index, row) {         $table.children('tbody').append(row);     }); }); 


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -