Hi i want how to how to sort product data by name and price in jquery
please help me any one
Answer (1)
Use this code fully tested and workable.
function sorbyname() {
$(".products-grid .class").sort(sort_li).appendTo('.products-grid');
function sort_li(a, b) {
return ($(b).data('position')) < ($(a).data('position')) ? 1 : -1;
}
}
function sorbyprice() {
$(".products-grid .class").sort(sort_li).appendTo('.products-grid');
function sort_li(a, b) {
return ($(b).data('price')) < ($(a).data('price')) ? 1 : -1;
}
}