2016-07-10 11 views
1

Ich versuche, eine .sortable Tabelle mit jQuery zu erstellen. Die Klasse fixWidthHelper behält die Tabellenspaltenbreiten bei. (Ich habe einen Teil der HTML entfernt)Wie sortierbare Tabellenzeilen mit jQuery erstellen

Tabelle HTML:

<table class = "table table-bordered" > 
      hr content here... 
    <tbody id = "field_wrapper"> 
      <tr> 
       <td id = "move">...</td> 
       <td id = "move">...</td>  
     </tbody> 
     </table> 

jQuery:

$(function (sort) { 
    sortable_tables.sorting_field_table(); 

}); 

var sortable_tables = 
{ 
    sorting_field_table: function(sort) 
    { 
     $('#field_wrapper').sortable({ 
     placeholder: "drop", 
     helper: sortable_tables.fixWidthHelper 
     }).disableSelection(); 
    } 
    fixWidthHelper: function(e, ui) { 
     ui.children().each(function(sort) { 
      $(this).width($(this).width()); 
     }); 
     return ui; 
    } 
}); 

CSS:

#move{ margin-left: 0px; padding-right:10px; cursor: move;} 
.drop { 
    outline: thin dashed #CCC !important; 
    background-color:#CCC; 
    width:100%; 
    } 
+0

'$ (function (Art) {...});' macht einfach 'sort' einen Alias ​​für' jQuery' innerhalb des Blocks. Die nächste 'function (sort)' erwartet einen Parameter, und die letzte 'function (sort)' macht 'sort' äquivalent zum Index jedes 'ui.children()'. Keine dieser Funktionen bezieht sich auf den Parameter 'sort'. Wir müssen mehr Code sehen. –

+0

Danke für schnelle Antwort. Ich habe meine Frage aktualisiert, um den Rest des Codes hinzuzufügen. – user3464091

Antwort

0

Ich habe es funktioniert!

jQuery:

$(function() { 
    $("#field_wrapper").sortable({ 
    placeholder: "drop" 
    }); 
    $("#field_wrapper").disableSelection(); 
}); 
+0

Hinweis: Sie benötigen beide folgenden jQuery-Links, damit sie funktioniert: '' – user3464091

1

Der erste Block Ihres Codes definiert nur eine Funktion auf document.ready, aber es wird nirgends aufgerufen.

Auch hier sehe ich nichts, das tatsächlich Sortierung durchführt.

+0

Dies ist nur die Funktion. Es ist innerhalb des document.ready-Aufrufs. Die Sortierung gilt für # field-wrapper.sortable – user3464091

+0

'$ (function (...)' ist eine Abkürzung für '$ (document) .ready()'. Siehe https://learn.jquery.com/using-jquery- core/document-ready/.Diese Antwort ist also etwas korrekt, obwohl eine Funktion nicht innerhalb des Blocks definiert wird. –

Verwandte Themen