can we sort the jquery sortable at runtime using the id or idx as taken by me in each li. I want it to sort in the run time
here is fiddle . I want it to auto sort f
Check this out
http://jsfiddle.net/wmaqb/2/
Using the standard jQuery library and the .sort()
method you can specify a function to use for sorting your array of objects.
$('#sort').click(function() {
var mylist = $('#sortable');
var listitems = mylist.children('li').get();
listitems.sort(function(a, b) {
var compA = parseFloat($(a).attr('id'));
var compB = parseFloat($(b).attr('id'));
return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
});
$.each(listitems, function(idx, itm) {
mylist.append(itm);
});
});
Once you got this array sorted, you can simply order them with a .each()
cycle