Enabling DeferRender in Datatable improved performance but fails in exporting data.
Enabling DeferRender in Datatable improved performance but fails in exporting data.
puneet.jayee
Posts: 18Questions: 8Answers: 0
Hi,
I am using data table to load huge amount of data and making "deferRender to true has helped to improve the performance but I have custom code to export the data to excel including input text column.
When I try to export to excel it fails ONLY WHEN DeferRender IS TRUE.
Kindly help
Here is the code-
table = $('#table').DataTable({
"ajax": {
"url": "../API/GETALLITEMS",
"type": "GET"
},
"deferRender": true,
dom: 'T<"clear"><"pull-right"B>lfrtip',
lengthChange: true,
buttons: [
{
extend: 'excelHtml5', text: 'Export to Excel', className: "btn-primary", exportOptions: {
format: {
body: function (data, row, column, node) {
if (column === 11) {// Column 11 is a INPUT TEXT
debugger;
var id = '#' + node.firstChild.id; // **It is a input text and fails here only when the deferRender is true but working fine when deferRender is false.**
if ($(id).val()) {
return $(id).val();
}
else {
return "";
}
}
else {
return data;
}
}
}
},
action: function (e, dt, node, config) {
$.fn.dataTable.ext.buttons.excelHtml5.action.call(this, e, dt, node, config);
}
},
],
Thanks!
Puneet
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This discussion has been closed.
Answers
Hi @puneet.jayee ,
It's working as expected here. Could you look at that, please, and see if it helps. If it's still not working for you, please can you update my example, or link to your page, so that we can see the problem.
Cheers,
Colin
Hi Colin,
Sorry If I was not clear but if you see the below line from the code mentioned in my original request-
var id = '#' + node.firstChild.id; // It is a input text and fails here only when the deferRender is true but working fine when deferRender is false.
The export does fails with the below error-
Uncaught TypeError: Cannot read property 'firstChild' of undefined.
It only fails when exporting data with input text and deferRender is true.
Thanks!
Puneet
Hi @puneet.jayee ,
Yep, that row hasn't been created - so the input elements won't be present. You can check for this with something like
and if not, put something default in there instead.
Cheers,
Colin
Thanks for the response Colin.
How to make sure that all the rows has been created before exporting to excel while deferRender is true?
Is this bug in datatable libraries?
No - this isn't a bug in DataTables. You are attempting to access DOM elements which haven't been created, which you've explicitly told DataTables not to create through the use of the
deferRender
option.You'd have to have the use show all of the rows!
Simply put, using
deferRender
is not compatible with exactly what it is that you are trying to do I'm afraid. I'd suggest removing it in this case.Allan
This is expected behavior with deferRender. From the
deferRender
docs:Kevin
Thanks everyone for the help and response.