jQuery UIのsortableでtable並び替え(helperオプションで表示の修正)


jQuery UIsortable使table



divlitable


sortable(helper)helper
tablehelpertrtrwidth


helper

html
	<table id="sortable-table1">
		<thead>
			<tr>
				<th>番号</th>
				<th>項目</th>
				<th>備考</th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td>1</td><td>項目1</td><td></td>
			</tr>
			<!-- 省略 -->
		</tbody>
	</table>
css
#sortable-table1 {
	width: 50%;
	border-collapse: collapse;
}
#sortable-table1 td, #sortable-table1 th {
	border: solid 1px black;
}
javascript
$(function(){
	$('#sortable-table1 tbody').sortable({helper: helper1, cursor: "move", opacity: 0.5});
});
function helper1(e, tr) {
	var $originals = tr.children();
	var $helper = tr.clone();
	$helper.children().each(function(index) {
		$(this).width($originals.eq(index).width());
	});
	return $helper;
}

tr内のtdそれぞれに対してwidthを指定することでtableの行としての幅を保存できます。

デモ画面

このhelperというのはちょっと理解するのが難しいかもしれないです。
Sortable API(helper)