Reputation: 564
Every row has an ID, #row-(id from ajax). Now I want to select an row by id, I got this to work.
var row = verzondenTable.row('#row-' + k);
k = the key from ajax.
Every td has a class per column so the first column has the class .td-subject
and the second one has .td-open
.
I want to select the .td-open
cell from the specific selected row and set the data for it.
Code:
$().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'
});
});
});
Upvotes: 1
Views: 2648
Reputation: 85528
If you want to go through the API you can do something like
var row = verzondenTable.row('#row-' + k);
row.nodes().to$().find('.td-open').text((v['open_rate'] * 100).toFixed(2) + '%');
row.draw().invalidate();
nodes()
-> get all nodes
to$()
-> convert to jQuery instance
invalidate
-> update DT internals
Upvotes: 1
Reputation: 18099
How about using CSS selectors:
$('[id^="row-"] td.td-open').text(your_data);//your_data is the value you want to set.
Upvotes: 0
Reputation: 291
try this function row().child( data [, className ] )
from reference https://datatables.net/reference/api/row().child()
Upvotes: 0