[英]Datatables row reorder event issue
var table =$("#exampleList").DataTable({
paging:false,
rowReorder:false
}
});
table.on('row-reorder',function(e, diff,edit){
for(var i=0, ien = diff.length ; i<ien ; i++){
var rowData = table.row(diff[i].node).data();
sequence = sequence + "_" + rowData[0];
}
var data = table.rows().data();
data.each(function (value, index) {
alert('Data in index: ' + index + ' is: ' + value);
});
});
Hi, I am new to datatables.嗨,我是数据表的新手。 Issue I am having right now is I cant get the latest value in my table after the user reorder the row.
我现在遇到的问题是,在用户对行重新排序后,我无法在我的表中获取最新值。 The code above only shows the value before the reorder occurs.
上面的代码只显示重新排序发生之前的值。 I need to get the latest reorder sequence so I can update the database.
我需要获取最新的重新排序序列,以便更新数据库。
What you need to do is wait a few milliseconds before trying to read the data.您需要做的是在尝试读取数据之前等待几毫秒。
table.on('row-reorder',function(e, diff, edit){
for(var i=0, ien = diff.length ; i<ien ; i++){
var rowData = table.row(diff[i].node).data();
sequence = sequence + "_" + rowData[0];
}
setTimeout(()=> { lookAtData() }, 10);
});
function lookAtData() {
var data = table.rows().data();
data.each(function (value, index) {
alert('Data in index: ' + index + ' is: ' + value);
});
}
You should use column-reorder
not row-reorder
.您应该使用
column-reorder
而不是row-reorder
。
Please try :请尝试:
var rdata = table .columns().order().data();
console.log(rdata);
It will get the data after columns ordering.它将在列排序后获取数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.