每行都有一个ID,#row-(来自ajax的id)。
现在,我想按ID选择一行,这样就可以了。
var row = verzondenTable.row('#row-' + k);
k =来自ajax的密钥。
每个td每列都有一个类,因此第一列具有类
.td-subject
,第二列具有.td-open
。我想从特定的选定行中选择
.td-open
单元格并为其设置数据。码:
$().ready(function() {
var verzondenTable = $('#tblVerzondenItems').DataTable({
"order": [[0,'desc']],
"columnDefs":[
{ "type": "date-nl", "targets": [ 'th-datum' ] },
{
sortable: false,
targets: [6,7]
}
],
"initComplete": function(settings, json) {
$.ajax({
url : '/mail/feed/mailgun.json',
type : 'GET',
dataType:'json',
success : function(data) {
$.each(data, function(k,v) {
var row = verzondenTable.row('#row-' + k);
verzondenTable.row('#row-' + k).cell('.td-open').data((v['open_rate'] * 100).toFixed(2) + '%');
});
$('#alert-mailgun').alert('close');
},
error : function(request,error)
{
alert("Request: "+JSON.stringify(request));
}
});
}
});
// loop over each element and create a tooltip using the data-attribute
$('.count').each(function() {
Tipped.create(this, {
ajax: {
data: $(this).data('querystring'),
type: "POST"
},
maxWidth: 300,
skin: 'dark'
});
});
});
最佳答案
如果您想通过API,则可以执行以下操作
var row = verzondenTable.row('#row-' + k);
row.nodes().to$().find('.td-open').text((v['open_rate'] * 100).toFixed(2) + '%');
row.draw().invalidate();
nodes()
->获取所有节点to$()
->转换为jQuery实例invalidate
->更新DT内部关于javascript - DataTables-如何从特定行获取单元格?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52718702/