如何编辑数据表()打印标题



我尝试在谷歌中搜索如何更改数据表标题,我找到了这个线程 数据表 API:如何更改打印页面标题

此线程的最佳答案是

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

我不明白它是如何工作的,使用它会在控制台"indexOf."中给我带来错误。

这就是我想改变的画面 数据表网站自定义打印示例

编辑 1尝试此代码

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

看看:

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

您可以在按钮扩展中使用标题:

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

或者只是标记

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

摆弄一个例子: 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

您的"编辑 1"在正确的轨道上,但有一个错误。 我已经更正了下面的代码。 这样做会使标题动态,即;它是在打印时生成的。 这允许您 否则,在创建打印按钮时,标题将固定在字符串上...

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

数据表按钮扩展 它不是关于您要实现的目标,只需使用标题标签

<table>
<caption id="tablecaption"></caption>
....
</table>
$('#tablecaption').text(foo.title);

最新更新