How to export all data with HTML5 export buttons, when using AJAX as a datasource.

How to export all data with HTML5 export buttons, when using AJAX as a datasource.

topikertopiker Posts: 1Questions: 1Answers: 0

Hello,

I am using HTML5 export buttons. I am using AJAX as a datasource, which returns only the required data for current page. The problem is, that I want to export all data, not only current page. Is it possible?

PS: Export works good but it only exports current page.

Here is configuration:

var table = $('#zadosti').DataTable({
            searchDelay: 2000,
            processing: false,
            serverSide: true,
            
            ajax: {
                url: instance.DataTableSourceURL,
                type: "POST",
-----
some code
-----
buttons: [
                {
                    extend: 'pdfHtml5',
                    text: 'PDF',
                    title: 'Requests',
                    exportOptions: {
                        "columns": ':visible',
                    }
                },

Answers

  • kwein1kwein1 Posts: 16Questions: 2Answers: 0

    topiker, I'm having the same issue.

  • kwein1kwein1 Posts: 16Questions: 2Answers: 0

    Now I'm reading that this is part of serverside processing - the current page of data is all that's available when trying to export. Now I'm investigating client-side rendering while only displaying some records.

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin

    serverSide: true,

    This is the issue. The file export is client-side, but if you are using server-side processing then the data available at the client-side is only that which is currently displayed (that is the whole point of server-side processing - only a limited sub-set is available at the client-side).

    If you want to export the full data set, you would need to either:

    1. Disable server-side processing, or
    2. Have the server create the files for you.

    Allan

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75
    edited October 2015

    Just curious... How many rows are you expecting to be exported? (Just ballpark it)

    (In my opinion), if you're using the serverSide option, then overall, you're playing around with more rows than you would want to export.. I would think it would be best to play around with the lengthMenu, giving the viewers limits of how much they can export, then allow them to filter for the relevant data they want to export via search... EG: If they want to export all rows containing "Some Data", then set the page length to the highest you would let it go (100, 200?), then filter for "Some Data", and export that.

  • kwein1kwein1 Posts: 16Questions: 2Answers: 0

    topiker, I solved my similar problem by simply adding a -1 option to the dropdown of the paging options. That allows me to select all records (it takes a while to display, true) so then the Excel export button exports all records, since they're all displayed. I had to modify a LIMIT statement in my DB grab in my PHP so it would do the right thing when it received a -1.

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    @kwein1 May as well not even use serverSide

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin

    Agreed - if you are going to just load all the data to the client-side anyway, I don't see any benefit of using server-side processing. In fact it will just hurt performance due to the latency it introduces.

    Allan

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    As I said in the other thread, and ill re-state it for @topiker

    you should just provide some high limits in the page limits array, and let them export only those amounts. If you want to let them export everything, theres really no point in using serverSide at all.. If they even have the ability to export everything without freezing the browser, then you dont have enough records to justify using serverSide, just use ajax

This discussion has been closed.