这是没有预期功能的示例(导出为 PDF 时在我的单元格中显示换行符):
$('#example').DataTable({
dom: 'Bfrtpi',
buttons: [{
extend: 'pdfHtml5',
text: 'Save current page'
}],
columns: [
{
title: 'Person name',
defaultContent: '', // if no content set in field
data: 'name'
},
{
title: 'Person age',
type: 'num', // this would be a number field
data: 'age'
}
],
data: [
{name: 'John <br/> Doe', age: 25},
{name: 'Michael <br/> Jackson', age: 30},
{name: 'Tom Jones', age: 32},
{name: 'Monica Beluchi', age: 34}
]
});
<link href="https://cdn.datatables.net/buttons/1.1.2/css/buttons.dataTables.min.css" rel="stylesheet"/>
<link href="https://cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.1.2/js/dataTables.buttons.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
<script src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/pdfmake.min.js"></script>
<script src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/buttons/1.1.2/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.0.1/js/buttons.colvis.min.js"></script>
<table id="example" class="display" cellspacing="0"></table>
<div id="r"> </div>
导出为 PDF 时的外观:
这个问题是有人问的,之前被删除了,我添加它是为了回答这个问题,让它对社区有用。
这是我找到的可能的解决方案。
细节是扩展导出按钮的功能,将其替换为
<br/>
,\n
希望对你有用,问候。导出后的示例: