Export multiple DataTables (Loaded with ajax call) into the same Excel

Export multiple DataTables (Loaded with ajax call) into the same Excel

CristianESCristianES Posts: 6Questions: 2Answers: 0
edited March 2022 in DataTables 1.10

I have 2 different datatables in the same page and they both work fine, as they load data from database using ajax call, I was able to export both to the same excel file, each datatable into a worksheet.

In The first worksheet the first table appears correctly with all data, but in the second one only it appears the header and columns of the second table and not the rows with data as I expect.

I have used the below examples, only what I have done was calling ajax to load data from database tables instead of typing the data in the datatables rows manually.

http://live.datatables.net/qinoxinu/6/edit
http://live.datatables.net/kuyayeto/9/edit

it would be appreciated if someone could help me to fix that.

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736
    Answer ✓

    I think those examples might only support array data. Are you using columns.data to define object data? If so that might be the problem. Those examples have been updated to support object or array based data. See this thread. However the examples were built to support exporting RowGroup data which won't help for your case. I updated the examples to allow exporting multiple tables whether object or array based. See the thread for more details about the changes.
    http://live.datatables.net/towequro/1/edit

    Kevin

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736
    Answer ✓

    Although the code might look similar to the two examples you linked they are different in many spots. You should copy all of the Javascript code between document.ready() and the first Datatabe init code to make sure you have all the fixes/changes.

    Kevin

  • CristianESCristianES Posts: 6Questions: 2Answers: 0

    Thank you very much Kevin for your help for the quick answer and for the explanation, it has worked perfectly using your example "http://live.datatables.net/towequro/1/edit", only I have changed the URL instead of using txt I have used ajax call to MVC controller.

    Answering to your question: yes, I was using columns.data

    Cristian.

Sign In or Register to comment.