1
我有一個表結構如下。現在我需要分別對這些嵌套表格進行排序。例如:排序章節的行只會更新單獨表格中的章節順序。而排序項目將更新他們在另一個表中的順序。用多個tbody對錶格排序?
我設法設置了代碼和排序。但是,當我拖動第4章中的項目時,它會傳遞第1章中的項目的順序,因爲它們在第4章之前?
有人可以幫我排序只有相關的項目??
注意:此列表是動態來自數據庫。所以我對覆蓋所有排序位的一個jquery代碼感興趣。
<table id=subsortsortable>
<tbody class=content>
<tr id="chapter_1"><td>Chapter one</td></tr>
<tr id="chapter_2"><td>Chapter two</td></tr>
<tr id="chapter_3">
<td>
<table>
<tbody class=subcontent>
<tr id="item_31"><td>three.one</td></tr>
<tr id="item_32"><td>three.two</td></tr>
</tbody>
</table>
</td>
</tr>
<tr id="chapter_4">
<td>
<table>
<tbody class=subcontent>
<tr id="item_41"><td>four.one</td></tr>
<tr id="item_42"><td>four.two</td></tr>
<tr id="item_43"><td>four.three</td></tr>
<tr id="item_44"><td>four.four</td></tr>
<tr id="item_45"><td>four.five</td></tr>
</tbody>
</table>
</td>
</tr>
<tr id="chapter_4"><td>Chapter Four</td></tr>
</tbody>
</table>
我使用的代碼如下:
//for sorting chapters - which is outer table
$("#subsortable tbody.content").sortable({
opacity: 0.7,
cursor: 'move',
placeholder: "ui-state-highlight",
forcePlaceholderSize: true,
update: function(){
var order = $('#subsortable tbody.content').sortable('serialize') + '&action=updateChaptersOrder';
$.post("/admin/ajax/ajax_calls.php", order, function(theResponse){
});
}
});
// For sorting and updating items within a specific chapter - which is nested tbody
$("tbody.sortItems").subcontent({
opacity: 0.7,
cursor: 'move',
placeholder: "ui-state-highlight",
forcePlaceholderSize: true,
update: function(){
var order = $('tbody.subcontent').sortable('serialize');// + '&action=updateListings';
$.post("/admin/ajax/ajax_calls.php", order, function(theResponse){
});
}
});
你能告訴你用用JS代碼? – PeeHaa
請在上面找到我使用的代碼。 –
反正,我已經得到了我自己的問題的答案..以防其他人遇到同樣的問題。我已經更改了內部表中的以下代碼: var order = 至 var order = $(this).sortable('serialize'); –