How to export all rows to excel file

How to export all rows to excel file

menymeny Posts: 3Questions: 0Answers: 0

Link to test case:
Debugger code (debug.datatables.net):
...
dom: 'Bfrtip',
buttons: [
{ extend: 'excel', text: 'Download Excel',

                    exportOptions: {
                    columns: ':visible',
                    orthogonal: 'excel',
                    modifier: {
                        order: 'current',
                        page: 'all',
                        selected: null,
                    },

                } ,        
                }
            ]

....
Error messages shown:
Description of problem: I want to export all data in datatable to excel file , but only its export the current page data, how can I solve it ... I could see this example https://datatables.net/forums/discussion/54915/always-export-all-rows-to-excel in this forum but ,is not working for my

Replies

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    If you are using the select extension then see this example of how to export all rows when there are selected rows.

    However it sounds like you have a different issue. I'm guessing you have server side processing enable ( serverSide: true ). With server side processing the only rows at the client are the rows currently displayed. These are the only rows that are exportable. See this FAQ for more details.

    If you still need help then please post a link to your page or a test case replicating the issue so we can see exactly what you have and to help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • menymeny Posts: 3Questions: 0Answers: 0
    edited May 2023

    Hi this is my code and I get [object Object] in csv file

     let dt = $('#new-cons').DataTable({
                    'serverSide': true,
                    'processing': true,
                    'ajax' : url,
                    'columns': [
                        {data: 'DT_RowIndex', name: 'DT_RowIndex', orderable: false, searchable: false},
                        { data: "user_name" },
                        { data: store_details },
                        { data: "order_no" },
                        { data: "created_at" },
                        { data: "total_pay" , class: "currency"},
                        { data: "status", class: "order-status" },
                        { data: "action", class: "order-status" },
                    ],
                    dom: 'Bfrtip',
                  
    
                        buttons: [
                                {
                                text:       'Export CSV',
                                action: function (e, dt, node, config) {
                                   // alert(Object.keys(dt.ajax.params()));
                                    $.ajax({
                                        "url": url,
                                        "data": dt.ajax.params(),
                                        "success": function(res, status, xhr) {
                                            var csvData = new Blob([res], {type: 'text/csv;charset=utf-8;'});
                                            var csvURL = window.URL.createObjectURL(csvData);
                                            var tempLink = document.createElement('a');
                                            tempLink.href = csvURL;
                                            tempLink.setAttribute('download', 'export.csv');
                                            tempLink.click();
                                        }
                                    });
                                }
                        }],
                });
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Hi,

    What does csvData contain? Is it a string of CSV data, or (I presume) an object? It might need to convert csvData into actual CSV data.

    Allan

  • menymeny Posts: 3Questions: 0Answers: 0

    Hi allan how can I convert to actual CSV DATA

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    I don't know, because I don't know what the response from your server is. I should have actually asked what res in your Ajax success callback is. Is that CSV formatted data already?

    If you could link to a test case showing the issue, as Kevin requested above, that would greatly assist in our ability to help.

    Allan

Sign In or Register to comment.