Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JS DataTables ColReorder API重新排序错误?_Javascript_Jquery_Datatable - Fatal编程技术网

Javascript JS DataTables ColReorder API重新排序错误?

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

使用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 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);