[英]DataTables: loop through all rows and get value from specific cell on each row
[英]DataTables - How to get cell from specific row?
每行都有一個 ID,#row-(id from ajax)。 現在我想通過 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 內部
如何使用 CSS 選擇器:
$('[id^="row-"] td.td-open').text(your_data);//your_data is the value you want to set.
試試這個function row().child( data [, className ] )
從參考https://datatables.net/reference/api/row().child()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.