0
當使用API重新排列列時,JS DataTables ColReorder會導致意外的行爲。 https://github.com/DataTables/ColReorder/JS DataTables ColReorder API重新排列Bug?
第一次重新排序工作正常,例如, tableColReorder.fnOrder([2,1,0]);
但是,這個後續的重新排序應該返回列的原始順序,但它不。爲什麼不? tableColReorder.fnOrder([0,1,2]);
簡單撥弄例如這裏: http://jsfiddle.net/h7wdt72k/
$(document).ready(function() {
// Initialize data table extension.
var table = $('table')
.DataTable({
paging: false,
searching: false,
ordering: false,
bInfo: false
});
// Initialize column re-order extension.
tableColReorder = new $.fn.dataTable.ColReorder(table);
// Re-order columns. Switch first/last columns.
tableColReorder.fnOrder([2, 1, 0]);
// Re-order columns to original order 0, 1, 2. Does not work!?
tableColReorder.fnOrder([0, 1, 2]);
// Get current column order. Did not apply re-order directly above. Why not!?
alert(tableColReorder.fnOrder());
// This statement returns columns to original order 1, 2, 3. Works but why!?
//tableColReorder.fnOrder([2, 1, 0]);
});
HTML:
<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>