How to sort product data by name and price in jquery

Hi i want how to how to sort product data by name and price in jquery please help me any one
Deepak Sharma
Asked 02-11-2019
69

Answer (1)
Use this code fully tested and workable.    <ul>                     <li>Name</li>                     <li>Price</li>                   </ul>   <ul class="products-grid"> <li data-position="potatoes" data-price="10" class="class item col-lg-4 col-md-3 col-sm-4 col-xs-6"></li> <li data-position="apple" data-price="20" class="class item col-lg-4 col-md-3 col-sm-4 col-xs-6"></li> </ul> 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;   } }  
Ankur Rajput
Asked 11-10-2018
45 Likes
Comments
Write comment

Submit your answer