I am using new feature in Datatables: \"HTML5 export buttons\". I am loading data with Ajax.
https://datatables.net/extensions/buttons/examples/html5/simple.html
Just wanted to post an actual answer for people struggling with this.
If you are exporting using the excel button, you can use the customizeData button property to format the data going to excel a moment before it exports.
I used this to make a synchronous api call to my server to get the data, return it, massage it, and then let it continue on it's way. Code below.
{
extend: 'excel',
customizeData: function (p)
{
//get the params for the last datatables ajax call
var params = JSON.parse(options.dataTable.ajax.params());
//flag to tell the server to ignore paging info and get everything that matches the filter
params.export = true;
UC.Api(options.api.read.getHook(), params, function (data)
{
p.body = new Array();
$.each(data.data, function (i, d)
{
var item = [d.serial, UC.FormatDateToLocal(d.meta.Date), d.transmission.title, d.transmission.type, d.transmission.information];
p.body.push(item);
});
}, null, { async: false });
}
},