Hello Friends, Today i am going to share jqueryui sortable examples. JqueryUI sortable method enables a group of DOM elements to become sortable, so that we can drag an element to a new spot within the list. Actually, recently I have used this method in a project in which I was developing a menu builder just like WordPress and a product image upload section to sort uploaded image. So I am sharing both examples with some modifications.
Example 1:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Sortable Example 1</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css"> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <style> .menu-item { margin-bottom: 5px; cursor: grab; } </style> </head> <body> <div class="container" style="padding: 25px;"> <ul class="nav menu sortable" id="menu-to-edit"> <li id="menu-item-1"> <div class="panel panel-default menu-item"> <div class="panel-heading"> <h3 class="panel-title"> <a data-toggle="collapse" href="#collapse1">Java</a> </h3> </div> <div id="collapse1" class="panel-collapse collapse"> <div class="panel-body"> <div class="form-group"> <i>Navigation Label</i> <input type="text" value="Java" class="form-control"> </div> <div class="form-group"> <i>Title Attribute</i> <input type="text" value="" class="form-control"> </div> </div> </div> </div> </li> <li id="menu-item-2"> <div class="panel panel-default menu-item"> <div class="panel-heading"> <h3 class="panel-title"> <a data-toggle="collapse" href="#collapse2">PHP</a> </h3> </div> <div id="collapse2" class="panel-collapse collapse"> <div class="panel-body"> <div class="form-group"> <i>Navigation Label</i> <input type="text" value="PHP" class="form-control"> </div> <div class="form-group"> <i>Title Attribute</i> <input type="text" value="" class="form-control"> </div> </div> </div> </div> </li> <li id="menu-item-3"> <div class="panel panel-default menu-item"> <div class="panel-heading"> <h3 class="panel-title"> <a data-toggle="collapse" href="#collapse3">JavaScript</a> </h3> </div> <div id="collapse3" class="panel-collapse collapse"> <div class="panel-body"> <div class="form-group"> <i>Navigation Label</i> <input type="text" value="JavaScript" class="form-control"> </div> <div class="form-group"> <i>Title Attribute</i> <input type="text" value="" class="form-control"> </div> </div> </div> </div> </li> </ul> <div id="status"> </div> </div><!-- ./wrapper --> <!-- REQUIRED JS SCRIPTS --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <script type="text/javascript"> $(".sortable").sortable({ update: function (event, ui) { $("#status").html("status: menu reordered"); } }); </script> </body> </html> |
Output:
Example 2:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Sortable Example 2</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css"> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <style> #thumbnails { float: none; margin-top: 10px; min-height: 250px; border: solid thick aliceblue; } #thumbnails .product-img-thumb { max-height: 250px; margin: 10px; border: dashed thin #ccd0d4; cursor: grab; } </style> </head> <body> <div class="container" style="padding: 25px;"> <ul class="nav navbar-nav sortable" id="thumbnails"> <li> <img src="http://via.placeholder.com/200x400?text=Product-1" class="img-responsive product-img-thumb"/> </li> <li> <img src="http://via.placeholder.com/200x400?text=Product-2" class="img-responsive product-img-thumb"/> </li> <li> <img src="http://via.placeholder.com/200x400?text=Product-3" class="img-responsive product-img-thumb"/> </li> </ul> <div id="status"> </div> </div><!-- ./wrapper --> <!-- REQUIRED JS SCRIPTS --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <script type="text/javascript"> $(".sortable").sortable({ update: function (event, ui) { $("#status").html("status: product reordered"); } }); </script> </body> </html> |
Output:
Example 1 Demo: https://zatackcoder.com/demo/sortable-example-1.html
Example 2 Demo: https://zatackcoder.com/demo/sortable-example-2.html
Thank for visiting
Please don’t forget to share if you like it
Comments