あなたが使用することができます。列を()の順序を()
var table = $('#example').DataTable();
table
.columns('.status')
.order('desc')
.draw();
さらに詳しい情報: https://datatables.net/reference/api/columns().order()
EDIT
あなたはdataTables.colReorder.minを使用することによって、これを達成することができます.jsプラグインを使用している場合は、ドラッグ&ドロップの初期設定を無効にすることもできます。
var table = $('#example').DataTable({
colReorder: true
});
table.on('click', 'td:first-of-type', function() {
var values = [];
var row = $(this).parent();
row.children('td').each(function(i){
values.push($(this).text());
});
var colOrder = values.sortIndices;
table.colReorder.order(colOrder);
});
//get index after sort
//credit to this post:
//http://stackoverflow.com/questions/3730510/javascript-sort-array-and-return-an-array-of-indicies-that-indicates-the-positi
function sortWithIndeces(toSort) {
for (var i = 0; i < toSort.length; i++) {
toSort[i] = [toSort[i], i];
}
toSort.sort(function(a, b) {
return a[0] - b[0]
});
toSort.sortIndices = [];
for (var j = 0; j < toSort.length; j++) {
toSort.sortIndices.push(toSort[j][1]);
toSort[j] = toSort[j][0];
}
return toSort;
}
ここ
全作業例:私はここまで得ているではないと思われることなく、上記の彼の解決のためにStryderへ https://jsfiddle.net/qjp8Lnam/6/
はい、それを行うための方法があります。しかし、何を試しましたか? – Quotidian
何もない - 私はDatatablesのドキュメントでそれを行う方法を見つけることができませんでした。それとも私は何かが恋しい? –
このサンプルは水平方向のソートhttp://stackoverflow.com/questions/3127503/sorting-table-column-with-jquery-table-sorterが見つかりましたが、これをどのようにしてデータテーブルで処理するのですか? –