How to use callback in buttons action call
How to use callback in buttons action call
datatable_user
Posts: 19Questions: 6Answers: 0
I want to use callback because I prefer to set the default row per page with callback rather than setTimeout. However I dont receive any response after execute $.fn.DataTable.ext.buttons.excelHtml5.action.call(dtButton, e, dt, node, config, cb);
I also upgraded button to version 3. Below is my test code
https://jsfiddle.net/qto7yL5a/3/
Snippet:
{
extend: 'excelHtml5',
text: 'Excel',
exportOptions: {
columns: ':visible'
},
title: '',
action: function(e, dt, node, config) {
var self = this; //we need this as param for action.call()
var currentPageLen = dt.page.len();
var currentPage = dt.page.info().page;
function cb() {
console.log("Callback function executed!"); // why does this line is not triggered?
dt.page.len(currentPageLen).draw(); //set page length
dt.page(currentPage).draw('page'); //set current page
}
dt.one('draw', function() {
$.fn.DataTable.ext.buttons.excelHtml5.action.call(self, e, dt, node, config, cb); //trigger export
});
//draw all before export
dt.page.len(dt.page.info().recordsTotal).draw();
}
}
Thanks in advance.
This question has an accepted answers - jump to answer
Answers
Old versions of the Button types are being loaded in. I'd suggest using the download builder to make sure you get the latest versions of everthing.
Allan
Callback works after updating the links. Thanks!
https://jsfiddle.net/061n2srf/1/
Updated example incase someone needs it.