How do I print all pages in a table?

How do I print all pages in a table?

jaredplanterjaredplanter Posts: 1Questions: 1Answers: 0
edited February 2016 in Free community support

Hello

As far as I can tell printing all pages is the default functionality of the print button but for some reason mine is only printing the current page. I haven't been able to find anything to try as most search results say it should work by default. Does anyone have any tips or advice on how I could achieve this?

Initialization code (coffeescript):

      $('table#contacts').DataTable
        columnDefs: [
          { orderable: false, targets: [ -1 ] }
        ]
        dom: 'Bfrtip'
        buttons: [
          'pageLength'
          'print'
        ]
        serverSide: true
        ajax: $('table#contacts').data 'source'

Debugger information: http://debug.datatables.net/emuliy

Unfortunately I cannot post a link to the website or I would.
If I missed any information please let me know and I will add it.

Thanks!

Jared

Answers

  • jacob.steinbergerjacob.steinberger Posts: 86Questions: 18Answers: 1

    If I had to guess, it's because of "serverSide: true". The web browser only knows about the rows passed to it, and with server side functionality it's only passing however many rows you have it configured for. Try added the "l" dom (lower case L) and set number of rows returned higher - does the print feature increase in what is available?

    If so, then I'd add the "l" dom and an "All" option for the purpose of printing.

    I'd assume you could take it a step further and have the print feature automatically set the rows to All before doing the print, but I'm not that great at java script.

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    Jacob is spot on. See also this FAQ.

    Allan

  • olesaknolesakn Posts: 1Questions: 0Answers: 0
    edited June 2016

    I am trying to do this exact same thing and can't get it to work. I currently have a datatable where I am handling the paging server side. I set up a custom print button, which when clicked will change the datatable page length to -1 so it will show all rows but then I need to call the draw() function on the datatable in order for the table to actually refresh from the server.

    So I added a drawCallback function to the datatable which will then trigger a click event on the print button, and it actually works EXCEPT that most browsers block the second click event because it is coming from outside of the event the user initiated. So now I'm stuck and don't know what else I can try. Is there a way I can trigger a print command for a datatable in the drawCallback() function without having to manually fire the click event of the print button?

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    Because of the async nature of Ajax I don't think there is going to be any way to have the window.print() command execute automatically if the browser is only allowing it to occur from a user action (since by the very fact that it is async it means it is no longer a user action).

    Do you really need server-side processing? Are you working with tens of thousands of rows? As soon as you display all rows with server-side processing and benefit you might have got from it has been mitigated and its only adding latency to your app.

    Allan

This discussion has been closed.