How to edit DataTable() Print Title

Viewed 16451

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
      }
   ]
});
3 Answers

Your "Edit 1" was on the right track but with one error. I have corrected code below. Doing it this way makes the title dynamic, i.e.; it is generated at print time. This allows you to Otherwise, the title is fixed at the string when the print button is created...

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