javascript - jQuery limit sortable to parent table row -


so have table has several categories, several items underneath in each category.

something like:

 <tr>    <td>category1</td>    </tr>    <tr>      <td>item1<td>    </tr>    <tr>      <td>item2</td>    </tr>    <tr>      <td>item3</td>    </tr>    <tr>      <td>category2</td>    </tr>    <tr>      <td>item1</td>    </tr> 

i want able sort each "item" within category only. "item1" inside "category2" should not able dragged "category1". not sure how accomplish this.

you can implement jquery ui's sortable interaction achieve requirement. following working example:

<style type="text/css">     .issortable { list-style-type: none; margin: 10px; padding: 5px; width: 60%; }     .issortable li { margin: 0 5px 5px 5px; padding: 5px; font-size: 1.2em; height: 1.5em; }     html>body .issortable li { height: 1.5em; line-height: 1.2em; }  </style>  <ul id="category1" class="issortable" style="border:1px solid blue;">     <li class="ui-state-default">item1</li>     <li class="ui-state-default">item2</li>     <li class="ui-state-default">item3</li> </ul>  <ul id="category2" class="issortable" style="border:1px solid red;">     <li class="ui-state-default">item1</li>     <li class="ui-state-default">item2</li>     <li class="ui-state-default">item3</li> </ul>  <script type="text/javascript">      $('ul.issortable').each(function(){         $(this).sortable({             connectwith : $(this).attr('id')         })     });  </script> 

edit:

following code should implement requirement:

<style type="text/css">     .issortable { list-style-type: none; margin: 10px; padding: 5px; width: 60%; }     .issortable li { margin: 0 5px 5px 5px; padding: 5px; font-size: 1.2em; height: 1.5em; }     html>body .issortable li { height: 1.5em; line-height: 1.2em; }  </style>  <ul class="issortableblock">        <li>         <span>category</span>         <ul id="category1" class="issortable" style="border:1px solid blue;">         <li class="ui-state-default">item1</li>         <li class="ui-state-default">item2</li>         <li class="ui-state-default">item3</li>         </ul>     </li>     <li>         <span>category 2</span>         <ul id="category2" class="issortable" style="border:1px solid blue;">         <li class="ui-state-default">item1</li>         <li class="ui-state-default">item2</li>         <li class="ui-state-default">item3</li>         </ul>     </li> </ul>  <script type="text/javascript">      $('ul.issortableblock').sortable();      $('ul.issortable').each(function(){     $(this).sortable({     connectwith : $(this).attr('id')     })     });  </script> 

i'd updated same in link http://jsfiddle.net/sknlr/8/


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -