Datatables API:如何更改打印页面标题 [英] Datatables API: how to change Print page title

查看:197
本文介绍了Datatables API:如何更改打印页面标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jquery数据表中的打印按钮,并且试图以编程方式更改打印按钮的打印页面标题。这是我第一次配置它的方式。

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

所以基本上我需要使用API​​更改 title 。请注意,该标题不是按钮上的文字。它是打印页面上的标题。 (当我单击打印按钮时显示的页面)

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)

我已经尝试使用这样的API更改标题

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.

推荐答案

看一下数据表的源代码,似乎按钮的配置设置为初始化。因此,在您进行配置时更改配置将无效。

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

这篇关于Datatables API:如何更改打印页面标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆