Легкий, простой. Попробуйте это:)
$('#sortables').delegate('a', 'click', function() {
var by = $(this).attr('id').match(/^by_(.*)/i);
if (by)
{
mySort.sort(by[1]);
}
});
var mySort = {
sortables: {
'title': {
method: 'text',
type: 'alpha'
},
'author': {
method: 'attr',
val: 'data-author',
type: 'alpha'
},
'id': {
method: 'attr',
val: 'data-id',
type: 'numeric'
}
},
sort: function(sortBy)
{
if (!mySort.sortables[sortBy]) return;
var sortedElements = [];
var sortVal;
var sort = mySort.sortables[sortBy];
$('#my_list > div').each(function() {
sortVal = $(this)[sort.method](sort.val || null);
sortedElements.push([this, sortVal]);
});
// ">" sorts in ascending order, "<" will sort in descending order.
sortedElements.sort(function(a, b) {
var result;
return (sort.type == 'numeric') ?
a[1] - b[1] :
a[1] > b[1];
});
// Create a new div to replace the old one with
var $newDiv = $('<div id="my_list">');
$(sortedElements).each(function() {
$newDiv.append(this[0]);
});
$('#my_list').replaceWith($newDiv);
}
};
Рабочая скрипка здесь: http://jsfiddle.net/fHTmQ/3