1
データテーブル内の上下の矢印が表示されているときに、jqueryでデータテーブル行を入れ替えようとしています。jqueryデータテーブルの行を交換する
$('#example tbody').on('click', '.swapDown', function(event) {
var _this = $(this),
ind = table.row(_this.closest("tr")).index();
var movedData = table.row(_this.closest("tr")).data(),
otherData = table.row(_this.closest("tr").next()).data();
console.log(movedData);
console.log(otherData);
table.row(_this.closest("tr").next()).data(movedData).draw(false);
table.row(_this.closest("tr")).data(otherData).draw(false);
console.log(_this.closest("tr").next());
console.log(_this.closest("tr"));
});
$('#example tbody').on('click', '.swapUp', function(event) {
var _this = $(this),
ind = table.row(_this.closest("tr")).index();
console.log(ind)
if(ind > 0){
var movedData = table.row(_this.closest("tr")).data(),
otherData = table.row(_this.closest("tr").prev()).data();
table.row(_this.closest("tr").prev()).data(movedData).draw(false);
table.row(_this.closest("tr")).data(otherData).draw(false);
}
});
});
は私のjavascriptのコードのサンプルに従います。ここで
datatablesプラグインAPIを使用してこれを行う方法はありますか? – Raavanan
@Raavanan更新された回答とjsFiddleをチェックアウトする – thekodester