views:

353

answers:

1
    $(document).ready(function() {

   $("#test-list").sortable({ 
        items: "> li", 
        handle : '.handle', 
        axis: 'y', 
        opacity: 0.6, 
        update : function () { 
            var order = $('#test-list').sortable('serialize'); 
            $("#info").load("process-sortable.asp?"+order+"&id=catid&order=orderid&table=tblCats"); 
        } 
    }); 
    $("#test-sub").sortable({ 
        containment: "ul", 
        items: "li", 
        handle : '.handle2', 
        axis: 'y', 
        opacity: 0.6, 
        update : function () { 
            var order = $('ul').sortable('serialize'); 
            $("#info").load("process-sortable.asp?"+order+"&id=catid&order=orderid&table=tblCats"); 
        } 
    }); 

});

<ul id="test-list">
  <li id="listItem_10">first<img align="middle" src="Themes/arrow.png" class="handle" /></li>
  <li id="listItem_8">second<img align="middle" src="Themes/arrow.png" class="handle" />
    <ul id="test-sub">
      <li id="listItem_4"><img align="middle" src="Themes/arrow.png" class="handle2" /></li>
      <li id="listItem_3"><img align="middle" src="Themes/arrow.png" class="handle2" /></li>
        <ul id="test-sub">
          <li id="listItem_9"><img align="middle" src="Themes/arrow.png" class="handle2" /></li>
        </ul>
      </li>
    </ul>
  </li>
</ul>

the problems i have:

  1. sorting the main ul is working but not all the time - i will try to fix that my own but if there is a problem with the code here and not the one in proccess-sortable - tell me.
  2. moving li in the main ul is ok but the sub or the sub of the sub is having problem - i can drag something from one sub to it's sub or the other way too - i don't want that to happend.
  3. i want to be able to drag li and by selecting that one that only this ul group will send to proccess-sortable to be updated - how can i catch the specific ul of li i am draging?
A: 

the first thing I see is that your giving the same id to multiple UL's and you really only need to set sortable to the the mother uL you can use one of the sortable events such as change to get the ul of the li you moved to handle the load process

Edit: adding more info

ok so I went back and looked at what I did for my nested sortable and what I had done was used behind's nested sortable it requires ui.core but does what we want to do. I then used serialize_list to serialize the data back to my server. Not claim it to be the best but thats how I ended up doing it.

Edit Again here is what I found in your code I didn't change anything just commented it

  $(document).ready(function() {
    $("#test-list").sortable({
      items: "> li", // this is wrong should be "li"
      handle : '.handle',
      axis: 'y',
      opacity: 0.6,
      update : function () {
        var order = $('#test-list').sortable('serialize');
        $("#info").load("process-sortable.asp?"+order+"&id=catid&order=orderid&table=tblCats");
      }
    });


    $("#test-sub").sortable({ // this should be a class so that you can target multiple items
      containment: "ul",
      items: "li",
      handle : '.handle2',
      axis: 'y',
      opacity: 0.6,
      update : function () {
        var order = $('ul').sortable('serialize'); // this say get all ul items it should probably target $(this).closest('ul);
        $("#info").load("process-sortable.asp?"+order+"&id=catid&order=orderid&table=tblCats");
        }
    });
  });

then you need to go through your html make sure you have no duplicate ids and your nesting is off in addition to that your missing a quote on listitem_4

take the time to look at your html before you post it is often a problem you should use w3's validator

mcgrailm
can you please help me with that answer of yours?
Y.G.J
how do i do it only to the mother ul and still make it to work so every li can be sorted with his siblings and not moving to other ul even on the same level?and how do i get the ul of the sorted li?
Y.G.J
fyi I edited my answer as you can see above
mcgrailm
you see my changes now ?
mcgrailm
only now i see the changes... the first link you gave me is not good because it allow the li to be drag to parent or siblings uls about the rest - i will try later.missing quote is only here when i copy the code and delete some of the inside of the li
Y.G.J
having any luck ?
mcgrailm
first the ">" char was recommended me by an answer here in stackoverflow for another problem i hadi changed the id to class but still can drug li between defrent level - most probebly because i have 2 ul with the same class so i can drug li from one to another - how can i disallow it?
Y.G.J