TableTools: is there a way to call fnPrint from outside the normal button functions?

TableTools: is there a way to call fnPrint from outside the normal button functions?

fortyCakesfortyCakes Posts: 3Questions: 1Answers: 0

For example, if I have a button on my page separate from the entire table, can I somehow call fnPrint from that button's onClick and have it work? All of the examples call fnPrint from one of the TableTools buttons, which isn't what I want.

(I would include an example of what I'm trying to do but I can't get TableTools to work in DataTables-live)

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin

    Sure - use the fnPrint method. It can be called on the TableTools instance.

    Allan

  • fortyCakesfortyCakes Posts: 3Questions: 1Answers: 0

    Having done:

    $('.table-auto').DataTable( {
    
            "dom": '<<"pull-right"f>>rtp',
            "tableTools": {
                "sSwfPath": '../Content/swf/copy_csv_xls_pdf.swf'
            }
        });
    

    and then tried to call

    $('table-printview').click(function () {
            $('.table-auto').DataTable.TableTools.fnPrint(true);
            });
    

    which gives me the JS error:

     Object doesn't support property or method 'fnPrint'
     
    

    Have I got the syntax for the call wrong? I can't find what the correct syntax for calling it should be.

    (This is with DataTables 1.10.6 and TableTools 2.2.4; the basic TableTools buttons work, including the print button, when I include them in the 'dom' attribute.)

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin
    Answer ✓

    Yes, there is no $('.table-auto').DataTable.TableTools option. If you found that in the documentation, could you show me where so I can correct it please?

    You want to use:

    var table = $('.table-auto').DataTable();
    var tableTools = $.fn.dataTable.TableTools.fnGetInstance( table.table().node() );
    
    tableTools.fnPrint();
    

    Very ugly... I'm working on a better solution!

    Allan

  • fortyCakesfortyCakes Posts: 3Questions: 1Answers: 0

    Thanks!

    No, it wasn't in the docs, I'd just missed the section about static and instance methods.

This discussion has been closed.