2011-05-14 16 views
9

Estoy usando una jQuery UI ordenable con una tabla (funciona bien). Me gustaría arreglar el encabezado y la última fila (no movible).jQuery UI ordenable con filas fijas

Los documentos jQuery UI indican que esto se puede hacer usando un selector para los elementos, pero no entiendo la sintaxis.

Este es el código correspondiente:

<script type="text/javascript"> 
    $(function() { 
    $("#response_options tbody.content").sortable(); 
    $("#response_options tbody.content").disableSelection(); 
}); 
</script> 

<table id="response_options" class="data-table"> 
    <tbody class="content"> 
     <tr> 
      <th>Links</th><th>Response</th> 
     </tr> 
     <tr class="sortable-row"> 
      <td>Edit</td> 
      <td>Item 1</td> 
     </tr> 
     <tr class="sortable-row"> 
      <td>Edit</td> 
      <td>Item 2</td> 
     </tr> 
     <tr class="sortable-row"> 
      <td>Edit</td> 
      <td>Item 3</td> 
     </tr> 
     <tr class="sortable-row"> 
      <td>Edit</td> 
      <td>Item 4</td> 
     </tr> 
     <tr class="sortable-row"> 
      <td>Edit</td> 
      <td>Item 5</td> 
     </tr> 
     <tr> 
      <td>Edit</td> 
      <td>Item 1</td> 
     </tr> 
    </tbody> 
</table> 

El selector va dentro .sortable (...):

$("#response_options tbody.content").sortable(); 

como

$("#response_options tbody.content").sortable(items: ???); 

y debe ser posible seleccionar solo elementos con class = "sortable-row"; pero de nuevo, estoy perdido por la sintaxis.

Respuesta

11

Esto debería funcionar:

$("#response_options tbody.content").sortable({items: 'tr.sortable-row'}); 
4

Por esta marcado:

<table id="tableid"> 
    <thead> 
     <tr>  
      <th>namr</th> 
      <th>id</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
      <td>jagadeesh</td> 
      <td>1</td> 
     </tr> 
     <tr> 
      <td>jagadeesh</td> 
      <td>2</td> 
     </tr> 
    </tbody> 
</table> 

Utilice esta jQuery:

$('#tableid tbody').sortable(); 

Se moverá solamente el contenido del cuerpo de la tabla no se puede mover parte de cabecera .

+0

me gusta este uno más! :) – Basti

8

Esto funcionó para mí:

 jQuery(".sortable tbody").sortable({ 
      items: 'tr:not(:first)' 
     }); 
Cuestiones relacionadas