Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datatables API: how to change Print page title

Tags:

datatables

I am using the 'Print' button in Jquery datatables and I am trying to programmatically change the 'Print' button's print page title. This is how i configure it the first time.

var table = $('table').DataTable({
    buttons: [
        extend: 'print',
        title: 'Monthly Report' // need to change this
    ]
});

So basically i need to change the title using the API. Note that this title is not the text on the button. It is the title on the print page. (The page that shows up when i click the 'Print' button)

I've already tried to change the title using the API like this

table.api().buttons()[0].inst.c.buttons[0].title = 'Daily Reports';

But its not working. Any help would be much appreciated.

like image 264
bazi Avatar asked Feb 06 '23 04:02

bazi


1 Answers

Looking at the source code of datatables it seemed that the config of the buttons is set at initialization. So changing the config as you are doing wouldn't work.

What the source code did reveal though is that you can set the title as a function. So I suggest something like this might solve the issue:

var table = $('table').DataTable({
   buttons: [
      extend: 'print',
      title: function(){
         return foo.title
      }
   ]
});
like image 133
Tom Glover Avatar answered Mar 12 '23 16:03

Tom Glover