0

I use several datatables on a single html page which is a report. I use pagination and column management which are all managed through javascript on the jquery document ready. All works fine - no problem.

When I print I need to specify different datatable settings - mainly to remove pagination for each grid. If it was css, you would just use the media tag. Is there any way to do something similar with javascript?

Using datatables print functions is not a solution as I need to print the whole report including the html around it.

One option I will probably implement if I dont get any better suggestions is Leo Lam's suggestion here; run-javascript-jquery-only-on-screen-media-not-print

Example of my config FWIW - the main change necessary would be to add paging: false on print and remove it on screen.

$(document).ready(function() {
    var muttable =  $('#mut-table').DataTable(  
    {   searching: false,
        "columnDefs": [
            {
                "targets": 5,
                "visible": false,
                "bAutoWidth": false,                
            },
            { 
            type: 'alt-string', targets: 4 
            }
            ],
        order: [[ 4, "asc" ],[ 5, "desc" ]],

    } );

    });
3
  • Can you use the @media print rule? (And pop up a page for printing) Commented Nov 21, 2014 at 1:26
  • I don't think so - unless i am mistaken, isnt that only for css? The layout of datatable is defined in javascript. There is no difficulty with the print bit - the standard browser print will be fine, it is just updating the pagination for that view Commented Nov 21, 2014 at 3:15
  • When you use the standard browser print, the @media print css rules should take effect-- I was thinking you could use them for pagination at that point. Commented Nov 21, 2014 at 17:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.