Javascript JS DataTables ColReorder API重新排序错误?
使用API对列重新排序时,JS DataTables ColReorder会导致意外行为。 第一次重新订购效果很好。 fnOrder([2,1,0]) 但随后的重新排序应该将列返回到其原始顺序,但事实并非如此。为什么不呢? fnOrder([0,1,2]) 这里有一个简单的小提琴示例: html:Javascript JS DataTables ColReorder API重新排序错误?,javascript,jquery,datatable,Javascript,Jquery,Datatable,使用API对列重新排序时,JS DataTables ColReorder会导致意外行为。 第一次重新订购效果很好。 fnOrder([2,1,0]) 但随后的重新排序应该将列返回到其原始顺序,但事实并非如此。为什么不呢? fnOrder([0,1,2]) 这里有一个简单的小提琴示例: html: 1 2 三 1 2 三 1 2 三 行为是设计的,而不是bug //To switch position of two columns, always reorder based on arra
1
2
三
1
2
三
1
2
三
行为是设计的,而不是bug
//To switch position of two columns, always reorder based on array of consecutive integers (array length = number of columns).
//Even if columns already moved. Start with array of consecutive integers.
newColOrder = [0,1,2];
// Set new order of columns.
newColOrder[colTo] = colFrom; // colFrom = index to move column from.
newColOrder[colFrom] = colTo; // colTo = index to move column to.
e.g. to switch first and last column.
newColOrder[0] = 2;
newColOrder[2] = 0;
// [2,1,0];
// Reorder columns. Switch position of first and last column.
tableColReorder.fnOrder(newColOrder);
// Switch position of first and last column again. Returns columns to original position.
tableColReorder.fnOrder(newColOrder);
<table border="1">
<thead>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</tbody>
</table>
//To switch position of two columns, always reorder based on array of consecutive integers (array length = number of columns).
//Even if columns already moved. Start with array of consecutive integers.
newColOrder = [0,1,2];
// Set new order of columns.
newColOrder[colTo] = colFrom; // colFrom = index to move column from.
newColOrder[colFrom] = colTo; // colTo = index to move column to.
e.g. to switch first and last column.
newColOrder[0] = 2;
newColOrder[2] = 0;
// [2,1,0];
// Reorder columns. Switch position of first and last column.
tableColReorder.fnOrder(newColOrder);
// Switch position of first and last column again. Returns columns to original position.
tableColReorder.fnOrder(newColOrder);