Export all regardless of pagination

Export all regardless of pagination

Jensen010Jensen010 Posts: 20Questions: 6Answers: 1
edited February 2018 in Free community support

I've searched and searched for this, but can't seem to find a straightforward answer -

I have a collection of export buttons that looks like this:

buttons: [{
  extend: 'collection',
  className: 'exportButton',
  text: 'Data Export',
  buttons: ['copy','excel','csv','pdf','print'],
  exportOptions: {
    modifer: {
      page: 'all',
      search: 'none'`    }
  }
}]

What I need is for each of those buttons to export the contents of whatever the table is displaying, regardless of pagination. Currently, if I run a search, and then export with any of those buttons (besides 'print'...oddly) the exported file or clipboard copy only contains the amount of rows as selected in the length dom box.

Is there a way that I can bypass this, and get an export with all matching records of any search?

EDIT: Updated code formatting to use Markdown

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,325Questions: 26Answers: 4,949
    edited February 2018

    I believe your exportOptions needs to be inside your buttons array to go with each button. For example:

    buttons: [{
      extend: 'collection',
      className: 'exportButton',
      text: 'Data Export',
      buttons: [{ extend:'copy',
                  exportOptions: {
                    modifier: {
                      page: 'all',
                      search: 'none'    
                    }
                 },
                 //the remaining buttons here  
        }]
    }]
    

    Also note you misspelled modifer above.

    Kevin

  • Jensen010Jensen010 Posts: 20Questions: 6Answers: 1
    edited February 2018

    Thank you for that catch, I wouldn't have caught the typo for a long while :)

    I retooled a bit and came back with this, but it's still only exporting the records currently displayed in the first page of the results (in this case, 25 out of 1675):

    buttons: [
    { extend: "create", className: 'newButton', editor: contactsEditor, submit: 'changed', drawType: 'full-hold' },
    { extend: "edit", className: 'editButton', editor: contactsEditor, submit: 'changed', drawType: 'full-hold' },
    { extend: "remove", className: 'deleteButton', editor: contactsEditor, submit: 'changed', drawType: 'full-hold' },
    //Options and exports dropdowns
    { extend: 'collection', className: 'optionsButton', text: 'Table Options', buttons: ['colvis'] },
    { extend: 'collection', className: 'exportButton', text: 'Data Export',
    buttons: [
    { extend: 'copy', exportOptions: { modifier: { page: 'all', search: 'none' } } },
    { extend: 'excel', exportOptions: { modifier: { page: 'all', search: 'none' } } },
    { extend: 'csv', exportOptions: { modifier: { page: 'all', search: 'none' } } },
    { extend: 'pdf', exportOptions: { modifier: { page: 'all', search: 'none' } } },
    { extend: 'print', exportOptions: { modifier: { page: 'all', search: 'none' } } }
    ]
    }
    ],

    Am I just missing the wrong exportOptions modifier?

  • kthorngrenkthorngren Posts: 21,325Questions: 26Answers: 4,949
    edited February 2018

    If you have server side processing enabled please see the SSP FAQ regarding export buttons.
    https://datatables.net/faqs/index

    Kevin

  • Jensen010Jensen010 Posts: 20Questions: 6Answers: 1

    Ok, so that answers that - server side processing does not allow for this, that makes sense.

    I'm lost on how to create a custom solution, however. If I was to leave SSP on, Is there a method to call in order to fetch and render the extra data based on a custom trigger?

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Answer ✓

    You can use ajax.params() to get the parameters that are used for the current server-side processing request (e.g. sorting, filtering information), then use an Ajax request in a custom button that will send those parameters to the server to create the required PDF / CSV file.

    Allan

  • Jensen010Jensen010 Posts: 20Questions: 6Answers: 1

    Ok, that gives me a starting point :)
    Thanks!

  • sruthirbabusruthirbabu Posts: 6Questions: 2Answers: 0

    Hai!!. Iam also trying to implement the same. But I would like to know what does 'search:none' within the the modifier option do??. Iam new to datatable.

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

    Hi @sruthirbabu - the documentation for that with an explaination of that value is available here.

    Allan

  • vhackerovhackero Posts: 1Questions: 0Answers: 0

    Aún si tienes esta configuración:

                           {
                                extend: 'excelHtml5',
                                exportOptions: {
                                    modifier : {
                                        order : 'index', // 'current', 'applied','index', 'original'
                                        page : 'all', // 'all', 'current'
                                        search : 'none' // 'none', 'applied', 'removed'
                                    },
                                    columns: [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
                                }
                            },
    

    Cuando el parámetro serverSide: true
    Sólo descarga por página.

    Si pones el parámetro serverSide: false o simplemente eliminas ese parámetro, entonces descargará todas las páginas.

  • jasper502jasper502 Posts: 25Questions: 9Answers: 0

    The simple solution (to me anyway) was to add "all" to lengthMenu:

    https://datatables.net/examples/advanced_init/length_menu

    Once you refine your search etc. you can change that to "All" the the buttons work just fine and export "all".

  • KartikiKartiki Posts: 1Questions: 0Answers: 0

    Hi, do we have option to export all the data without loading or binding data to dataTable

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    @Kartiki I'm not sure what that means, or how that relates to this thread. Please can you create a new thread with a test case that demonstrates the issue you want help with,

    Colin

  • _mercury_mercury Posts: 12Questions: 3Answers: 0

    he means to load ( all ) data on front-end then download it .. which is not efficient

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

    @_mercury Colin's last comment was over two years ago. Are you having a similar issue?

    Allan

Sign In or Register to comment.