How to call print button in my function

How to call print button in my function

mamadsolimamadsoli Posts: 28Questions: 5Answers: 1
edited November 28 in Free community support

Hello, how to can call print function in datatables ?
I need to call print function in my custom button...
(without define any print buttons in my page, I only have my custom button)

buttons: [
{
    text: 'My Print Button',
    action: function (e, dt, node, config) {
        // Some code before call print function
        
                // Now call print
        table.printFuction(e, dt, node, config);

        // Some code after call print function
    });
}
]

thanks

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,602Questions: 1Answers: 10,486 Site admin
    Answer ✓

    Have a look at that last example in the buttons.buttons.action documentation for how to do what you are looking for. DataTable.ext.buttons.print.action is the function you want.

    Allan

  • mamadsolimamadsoli Posts: 28Questions: 5Answers: 1

    Thank you very much

  • mamadsolimamadsoli Posts: 28Questions: 5Answers: 1

    Excuse me, I write this code, but I don't have columns on output.
    Can you tell me where's my wrong? thank you

    {
    text: 'Print All',
    className: 'btn btn-light',
    action: function (e, dt, node, config) {
        
        config.label= 'Test company';
        config.messageTop= 'Test top message';
        config.messageBottom= 'test bottom';
        config.exportOptions= {
            columns: ':visible',
        };
        config.autoPrint= true;
        
        var totalPage = table.data().count();
        var pageNumber = table.data().page();
        
        var totalRows = table.page.info().recordsTotal;
        table.page.len(totalRows).draw();
        
        table.on('draw', function() {       
            var additionalParams = function() {
                table.off('draw');
                table.page.len(totalPage).page(pageNumber).draw('page');
            };      
            DataTable.ext.buttons.print.action(e, dt, node, config, additionalParams);      
        });
        
        }
    },
    
  • kthorngrenkthorngren Posts: 21,391Questions: 26Answers: 4,961

    Its difficult to debug code snippets. Please provide a simple test case replicating the issue so we can help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • mamadsolimamadsoli Posts: 28Questions: 5Answers: 1
    edited December 4 Answer ✓

    I found it.
    I have to set this code too:

    header: true,
    footer: true
    

    or

    config.header= true;
    config.footer= true;
    

    Thank you

Sign In or Register to comment.