JS DataTables ColReorder API Reorder Bug?
JS DataTables ColReorder API Reorder Bug?
JS DataTables ColReorder 在使用 API 对列重新排序时会导致意外行为。https://github.com/DataTables/ColReorder/
第一次重新订购工作正常,例如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>
行为是设计使然,而不是错误。
//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);
相关文章:
- 在这个使用hasOwnProperty的对象扩展程序中有一个错误,I'我不确定那个bug是什么,也不确定这个扩展
- Socket.io客户端在使用名称空间时忽略端口[Bug?]
- angularjs formly submit bug in safari & IE 11
- Bug修复放弃了Firefox插件Wikilook
- “*[attribute ^="string”是如何/为什么是有效的querySelector?(JS bug
- HTML5 Canvas drawImage ratio bug iOS
- PrependTo() bug
- Backbone.js bug?
- Android的Bug:调试修复JS
- 在NodeJS网站中查找Bug
- SyntaxError: missing ) after argument list in fire bug
- IE11-Only Submit Bug
- jquery IE8 bug 中的 .on 方法
- fadeOut”;被禁用”;通过一行看似温和的CSS(jquery bug?)
- 使用javascript(IE bug?)在文本区域插入新行
- document.body.innerHTML 在 IE 中剥离 JavaScript - bug
- Serviceworker Bug event.respondWith
- JavaScript:将插入符号位置设置为第一段的开头(Opera bug)
- WebView bug - 替换 ContentEditable 中的选定文本
- JS DataTables ColReorder API Reorder Bug?