javascript - How to create a pagination and sorting using jquery? -
i need create pagination using jquery displays 5 results per page. must allow user sort results price.
i created pagination , works fine. bug in sorting function. when user sorts results sorts results available in specific page , not total results. here demo below function sort price.
var ascending = false; $('.sortc').on('click', '.sortp', function (e) { e.preventdefault(); var sorted = $('ul .price_indiv').sort(function (a, b) { return (ascending == (converttonumber($(a).find('.final_price').html()) < converttonumber($(b).find('.final_price').html()))) ? 1 : -1; }); ascending = ascending ? false : true; $('.price').html(sorted); }); var converttonumber = function (value) { return parsefloat(value.replace('$', '')); }
can me fix bug? note: without plugin
i think have misunderstood how pager works.you may need re-evaluate how script works. displays proper items , hides rest of list items using display:none;
before sort
!
after sort
!
so darkhorse said sorting working perfectly. need may reapply sorting function work
Comments
Post a Comment