javascript - DataTables - 如何从特定行获取单元格?
问题描述
每行都有一个 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 内部
推荐阅读
- python - 在 python 中从 Matlab 中加载 .fig 图形。误差线使图形看起来很奇怪
- python - 如何有效地在 if 语句中为多个元素使用 WebDriverWait?
- node.js - 如何提示下载数据缓冲区?
- html - 我刚刚建立的网站上的页脚在显示器上看起来就像我想要的那样,但在笔记本电脑上,页脚周围有框,看起来不完整
- asp.net-mvc - 为什么单击表格标题以展开/折叠时,它对我的所有表格都在这样做,而不仅仅是单击的表格?
- r - str_split 分成多行并根据 r 中的分隔符从另一列复制字符串
- html - 将整个文本的字体从悬停在 nth:child 上更改
- maven - 如何在单个 maven settings.xm 中添加内部和外部工件
- python - 根据Python3中的给定变量索引或映射
- python - 字符串中的多个捕获