I'm puzzled to why columns.render is not included in the execution pipeline of DataTable().draw(). An example: HTML
Solution 1:
Instead of destroying the datatable and repopulating it I ended up modifying jquery.datatables.js version 1.10.2.
The main issue is that the line 1935 in jquery.datatables.js checks if the row is already created:
if ( aoData.nTr === null )
{
_fnCreateTr(oSettings, iDataIndex);
}
One option to remedy this is to set aoData.nTr = null. But this might break other functionality or cause unwanted side effects so this is not an acceptable solution.
I opted to instead add an argument to the .draw() function (line 7137) and adding a setting called bForceReDraw (draw() already takes an argument so we add a second argument):
I found that, contrary to .draw(), .columns.adjust().draw(); will fire the render function again. But, unfortunately, it doesn't re-render the table... (?)
The only workaround I found is to .destroy() the table, replace $('#data').html() with its original contents and start again with $('#data').DataTable({ columnDefs: colDefs });.
$(document).ready(function () {
var table_data = $('#data').html();
var colRender = function (data, type, row, meta) {
var today = newDate();
var ms = today.getMilliseconds();
var ss = today.getSeconds();
var mn = today.getMinutes();
var hh = today.getHours();
var time = ' time:' + hh + ':' + mn + ':' + ss + ':' + ms
console.log('data+time', data + time);
return data + time;
}
var colDefs = [{
targets: 0,
render: colRender
}];
$('#data').DataTable({
columnDefs: colDefs
});
$('#refresh').click(function () {
// $('#data').DataTable().columns.adjust().draw();// $('#data').DataTable().draw();
$('#data').DataTable().destroy();
$('#data').html(table_data);
$('#data').DataTable({
columnDefs: colDefs
});
});
});
Post a Comment for "Why Doesn't Columns.render Execute When Datatable().draw() Is Called?"