JQuery sorted for partitioned sections

I have main categories and subcategories. I want to be able to sort subcategories when the display looks like this:

Main Cat1  
  sub cat11            [handle]
  sub cat12            [<>]
  sub cat13            [<>]
Main Cat2
  sub cat21            [<>]
  sub cat22            [<>]
  sub cat23            [<>]

It turned out in HTML

<ul id="order-list-1" class="c_order_list"> 
                    <li id="listItem-2" style=" margin-top:10px;">Sculpture<div style="float:right" align="right"><img src="images/add.png" style="vertical-align:middle; margin-bottom:2px;" onclick="showSubcategoryAddBox(2)"></div></li> 
                                        <li id="subcat-4" style="padding-left: 25px; width: 555px;">subcat1 Of maincat2<div style="float: right;" align="right"><img src="images/handle.png" alt="move" width="18" height="18" class="handle" /></div></li> 
                                        <li id="subcat-5" style="padding-left: 25px; width: 555px;">subcat2 Of maincat2<div style="float: right;" align="right"><img src="images/handle.png" alt="move" width="18" height="18" class="handle" /></div></li> 
</ul> 
<ul id="order-list-2" class="c_order_list"> 
                    <li id="listItem-1" style=" margin-top:10px;">Mantel Clocks<div style="float:right" align="right"><img src="images/add.png" style="vertical-align:middle; margin-bottom:2px;" onclick="showSubcategoryAddBox(1)"></div></li> 
                                        <li id="subcat-1" style="padding-left: 25px; width: 555px;">subcat1 Mantel Clocks<div style="float: right;" align="right"><img src="images/handle.png" alt="move" width="18" height="18" class="handle" /></div></li> 
                                        <li id="subcat-2" style="padding-left: 25px; width: 555px;">subcat2 Mantel Clocks<div style="float: right;" align="right"><img src="images/handle.png" alt="move" width="18" height="18" class="handle" /></div></li> 
                                        <li id="subcat-3" style="padding-left: 25px; width: 555px;">subcat3 Mantel Clocks<div style="float: right;" align="right"><img src="images/handle.png" alt="move" width="18" height="18" class="handle" /></div></li> 
</ul> 

I could only do one section, for example: sorting the main cats

$(document).ready(function() {
    var order = null;
    $("#order-list").load(location.href+" #order-list>*","");   
    $("#order-list").sortable({
      handle : '.handle',
      update : function (e, ui) {
             order = $(this).sortable('serialize');
         $("#info").load("process-sortable.php?"+order);
    }
    });

But I can’t understand how I can sort the subcategories in their section?

+3
source share
1 answer

There is a spot in your HTML that needs to be fixed, your subcategories need their tags

. Your HTML should follow something like this:
<ul id="main-cats">
 <li><span class="main-cat-handle">Main Cat 1</span>
  <ul id="main-cat-1">
   <li id="sub-cat-1"><span class="sub-cat-handle">Sub Cat 1</span></li>
   <li id="sub-cat-2"><span class="sub-cat-handle">Sub Cat 2</span></li>
   <li id="sub-cat-3"><span class="sub-cat-handle">Sub Cat 3</span></li>
  </ul&gt
 </li>
</ul>

#main-cats #main-cat-X , , .

+2

Source: https://habr.com/ru/post/1736988/


All Articles