export button don't export the row added via drawCallback
export button don't export the row added via drawCallback
I have a code:
$('#dimensions-table').dataTable({
"ajax": route,
"processing": true,
"serverSide": true,
"destroy": true,
"order": [[0, "asc"]],
"scrollX": true,
"aLengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]],
"pageLength": 25,
"columns": [
{"data": "user_name"},
{"data": "company_name"},
{"data": "style_1"},
{"data": "style_2"},
{"data": "style_3"},
{"data": "style_4"},
{"data": "style_5"},
{"data": "style_6"},
{"data": "style_7"},
{"data": "style_8"},
{"data": "style_name"}
],
"columnDefs": [
{"visible": false, "targets": 1}
],
"drawCallback": function (settings) {
var api = this.api();
var rows = api.rows({page: 'current'}).nodes();
var last = null;
api.column(1, {page: 'current'}).data().each(function (group, i) {
if (last !== group) {
var data_row = '<tr class="bg-opacity-white">' + '<td>' + group + '</td>';
$.each(settings.json.group_data, function (index, value) {
data_row += '<td>' + value.avg_point + '</td>';
});
if (settings.json.group_style){
data_row += '<td>' + settings.json.group_style + '</td>';
}
data_row += '</tr>';
$(rows).eq(i).before(data_row);
last = group;
}
});
},
dom: 'lBfrtip',
buttons: [
{
extend: 'excel',
text: 'Download scores',
className: 'btn btn-success show-scores-excel-button',
exportOptions: {
modifier: {
page: 'current'
}
},
filename: 'scores'
}
]
});
It works fine with except one thing:
All the columns are exported normally, but not the column added via drawCallback option.
How can I fix it?
https://datatables.net/faqs/#buttons - probably It's the answer but I can't understand what should I do(
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
No - it wouldn't. The export uses
buttons.exportData(), which ultimately usesrows().data(). That doesn't see any rows injected into the DOM I'm afraid. There is no way to have it include your injected row.Allan
It's really bad(((