Mark Angelo Mark Angelo - 6 months ago 48
jQuery Question

How to edit DataTable() Print Title

I tried searching in google how to change datatable title and i found this thread Datatables API: how to change Print page title

The best answer for this thread is

var table = $('table').DataTable({
buttons: [
extend: 'print',
title: function(){
return foo.title
}
]
});


I don't understand how it works using this gives me error in console 'indexOf..'

this is the picture of what i want to change
DataTable Website Customized Print Example

EDIT 1 trying this code

var table = $('table').DataTable({
buttons: [
extend: 'print',
title: function(){
var printTitle = 'New Title';
return printTitle.title
}
]
});

Answer Source

Take a look at:

https://datatables.net/extensions/buttons/examples/print/customisation.html

You can use title in buttons extension:

title: 'Datatables example: Customisation of the print view window'

Or just tag

<caption>Datatables example: Customisation of the print view window</caption>

Fiddle with a example: https://jsfiddle.net/f14ykjem/1/

    <table id="example" class="display" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Position</th>
                    <th>Office</th>
                    <th>Age</th>
                    <th>Start date</th>
                    <th>Salary</th>
                </tr>
            </thead>
            <tfoot>
                <tr>
                    <th>Name</th>
                    <th>Position</th>
                    <th>Office</th>
                    <th>Age</th>
                    <th>Start date</th>
                    <th>Salary</th>
                </tr>
            </tfoot>
            <tbody>
                <tr>
                    <td>Tiger Nixon</td>
                    <td>System Architect</td>
                    <td>Edinburgh</td>
                    <td>61</td>
                    <td>2011/04/25</td>
                    <td>$320,800</td>
                </tr>
                <tr>
                    <td>Garrett Winters</td>
                    <td>Accountant</td>
                    <td>Tokyo</td>
                    <td>63</td>
                    <td>2011/07/25</td>
                    <td>$170,750</td>
                </tr>
      </tbody>
    </table>

    $('#example').DataTable( {
            dom: 'Bfrtip',
            buttons: [
                {
                    extend: 'print',
                    text: 'ButtonLabelHere',
                    title: 'Datatables example: Customisation of the print view window',
                    customize: function ( win ) {
                        $(win.document.body)
                            .css( 'font-size', '10pt' )
                            .prepend(
                                '<img src="http://datatables.net/media/images/logo-fade.png" style="position:absolute; top:0; left:0;" />'
                            );

                        $(win.document.body).find( 'table' )
                            .addClass( 'compact' )
                            .css( 'font-size', 'inherit' );
                    }
                }
            ]
    });

**External code:**

//code.jquery.com/jquery-1.12.4.js
https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js
https://cdn.datatables.net/buttons/1.4.0/js/dataTables.buttons.min.js
//cdn.datatables.net/buttons/1.4.0/js/buttons.print.min.js

https://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css
https://cdn.datatables.net/buttons/1.4.0/css/buttons.dataTables.min.css
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download