javascript - jQuery save sortable list -


i've used jquery example: http://jqueryui.com/sortable/#connect-lists-through-tabs

<script> $(document).ready(function() {     $(function() {     $( ".connectedsortable" ).sortable().disableselection();     var $tabs = $( "#tabs" ).tabs();      var $tab_items = $( "ul:first li", $tabs ).droppable({         accept: ".connectedsortable li",         hoverclass: "ui-state-hover",         drop: function( event, ui ) {             var $item = $( );             var $list = $( $item.find( "a" ).attr( "href" ) )             .find( ".connectedsortable" );              ui.draggable.hide( "slow", function() {                 $tabs.tabs( "option", "active", $tab_items.index( $item ) );             $( ).appendto( $list ).show( "slow" );             });         }     }); });   }); </script> 

the html:

<div id="tabs"> <ul>     <li><a href="#category1">category1</a></li>     <li><a href="#category2">category2</a></li> </ul>  <div id="category1">     <ul id="sortable-category1" class="connectedsortable ui-helper-reset">         <li class="ui-state-default">forum 1</li>         <li class="ui-state-default">forum 2</li>     </ul> </div> <div id="category2">     <ul id="sortable-category2" class="connectedsortable ui-helper-reset">         <li class="ui-state-default">forum 3</li>         <li class="ui-state-default">forum 4</li>     </ul> </div 

but i'd when change in list when reordered item. know how write changes database via ajax etc, method called when in list dragdropped + how implement in existing javascript above?

and there way can order of list in format '[id-of-the-li-item]-[number in list]' can use field in database named 'order' order of items specified?

what want achieve is: i've forum categories & forums. want use code above order forums / categories (order of forums in category , moving forums other categories)

        $( ".connectedsortable" ).sortable({             update: function (event, ui) {                 var newseq = [], p = ui.item.parent(), parentid = p.parent().prop('nodename') === "li" ? p.parent().attr('id') : 0;                 ui.item.parent().children().each(function () {                     newseq.push(this.id);                 });                 // here have newseq... update via ajax             }         }); 

this relies on element's id. there ids in newseq[]


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -