更新jQuery数据表中单元格的正确方法

更新jQuery数据表中单元格的正确方法,jquery,datatables,Jquery,Datatables,我正在尝试通过UI为表中的行重新排序。用户选择一行,单击“上移”或“下移”,然后移动该行。多次移动同一行无法正常工作 // This returns the data in currently displayed order whether 'current' or 'index' is passed as the modifier var primaryKeyColData = self.DataTable.column(0, 'current').data(); // updatedFie

我正在尝试通过UI为表中的行重新排序。用户选择一行,单击“上移”或“下移”,然后移动该行。多次移动同一行无法正常工作

// This returns the data in currently displayed order whether 'current' or 'index' is passed as the modifier
var primaryKeyColData = self.DataTable.column(0, 'current').data();

// updatedFieldOrder is correct
for (const field of updatedFieldOrder)
{
    for (var index = 0; index < primaryKeyColData.length; index++)
    {
        if (primaryKeyColData[index] != field[0]) continue;

        // The issue is here. cell(index) returns based on the original order. 
        // I can't get column() to return data in this order nor get that data to update. 
        // Stepping into the source the original order data is in aoData
        self.DataTable.cell(index, 8).data(field[1]);
        self.DataTable.row(index).invalidate();

        break;
    }
}

self.DataTable.draw(false);
//无论将“current”或“index”作为修饰符传递,都将按当前显示的顺序返回数据
var primaryKeyColData=self.DataTable.column(0,'current').data();
//updatedFieldOrder是正确的
for(updatedFieldOrder的常量字段)
{
对于(var index=0;index
我错过了什么?如何根据一列中的数据查找单个匹配行,更新另一列中的数据,重新绘制并多次执行此操作

谢谢,
-Mont

这里是手动重新定位行的最终工作代码

var self = this;

// Get the data for the column by which rows can be uniquely identified.
// Data will be in the original order.
var rowIdColData = self.DataTable.column(self.RowIdCol, { order: 'index' }).data();

// updateFieldOrder is a two dimensional array. Each entry holds a value to identify
// a row in the first position and the value to be changed in the second position
for (const field of updatedFieldOrder)
{
    for (var index = 0; index < rowIdColData.length; index++)
    {
        if (rowIdColData[index] != field[self.RowIdCol]) continue;

        // Update the data in the desired column. ".cell()" references rows
        // in their original order.
        self.DataTable.cell(index, self.ColToBeChanged).data(field[1]);

        break;
    }
}

self.DataTable.draw(false); // Update table, do not re-paginate
var self=this;
//获取可以唯一标识行的列的数据。
//数据将按原始顺序排列。
var rowIdColData=self.DataTable.column(self.RowIdCol,{order:'index'}).data();
//updateFieldOrder是一个二维数组。每个条目都有一个要标识的值
//第一个位置的行和第二个位置要更改的值
for(updatedFieldOrder的常量字段)
{
对于(var index=0;index
不是答案,只是观察:您在
列(0,'current')
中使用的语法看起来不正确。第二个参数(the)必须按如下方式指定:
列(0,{order:'current'})
。如何选择行?使用扩展或其他方式?扩展是否满足您的需要?(对所有的评论表示抱歉!)中有一个关于重新订购的示例。看看。。。因为您的代码似乎不接近。。。很难回答。谢谢你@andrewjames我在参数上犯的愚蠢错误就是问题所在。只要我正确地传递了'index'参数,一切都正常了。同样感谢您指出我现在知道的行重新订购扩展。