How to implement Serverside Export to Excell ?

How to implement Serverside Export to Excell ?

SAKIFSAKIF Posts: 8Questions: 3Answers: 0
edited April 2018 in Free community support

I believe I am missing something, probably the mapping of data is all out of wack. However the pdf export works fine but when I do "copy,csv ,export to excell" the data shows the number of rows but the data is not there but the header seems to come out fine.

jQuery.fn.DataTable.Api.register('buttons.exportData()', function (options) {
if (this.context.length) {
var jsonResult = $.ajax({
type: "POST",
//datatype: "html5",
url: "/Home/GetData/?CheckDate=' + $("#EventDates option:selected").val(),
success: function (result) {
},
async: false
});
var a = jsonResult.responseJSON;
return { body: jsonResult.responseJSON, header: $("#tblPayroll thead tr th").map(function () { return this.innerHTML; }).get() };
}
});

Answers

  • SAKIFSAKIF Posts: 8Questions: 3Answers: 0

    I have not received any Reply so just wondering .

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin

    That's a clever hack to get around the export data not being available at the client-side.

    Can you link to a test case showing the issue which will hopefully let me see and help debug the issue.

    Allan

  • SAKIFSAKIF Posts: 8Questions: 3Answers: 0

    Allan the application I am was building is for proprietary data I will not be able to share that particular one but if you want i can build something just for the purpose of this and put it in a github repo for you to look into please let me know if that sounds okay.

  • SGCongerSGConger Posts: 2Questions: 0Answers: 0

    I am running into this problem too. I would love to get a resolution. Has anyone figured this on out yet?

    Thanks :-)

  • SGCongerSGConger Posts: 2Questions: 0Answers: 0

    I found the solution the return of the body has to be changed from:

    body: jsonResult.responseJSON
    

    to:

    body: jsonResult.responseJSON.data.map(el => Object.keys(el).map(key => el[key]))
    

    I found this on the following blog:
    https://diogenesggblog.wordpress.com/2017/02/02/how-to-export-all-rows-from-datatables-using-server-side-ajax/

    In the comments section. Tried it and it work!

This discussion has been closed.