我正在使用这段代码,它工作正常。
但我想从数据表的一行中获取有限的行数据和有限的单词。
我在做什么 Jquery 代码:
if( $('.clienttable').length > 0 ) {
$('.clienttable').DataTable( {
pageLength: 10,
responsive: true,
dom: '<"html5buttons"B>lTfgitp',
buttons: [
{
extend: 'copyHtml5',
exportOptions: {
columns: [1, 2, 3,4,5,6]
}
},
{
extend: 'csvHtml5',
exportOptions: {
columns: [1, 2, 3,4,5,6]
}
},
{
extend: 'excelHtml5',
exportOptions: {
columns: [1, 2, 3,4,5,6]
}
},
{
extend: 'pdfHtml5',
exportOptions: {
columns: [1, 2, 3,4,5,6]
},
title: 'List of Clients',
}
],
columnDefs: [
{ targets: [0], orderable: false },
{ targets: [7], orderable: false }
],
"order": [[ 6, "desc" ]]
});
}
前端代码:
<table class="table table-striped table-bordered table-hover clienttable" >
</table>
其他问题:
导出 excel 时如何去除列中的空白文本......? 我在 Excel 表格单元格中遇到诸如空格之类的问题,是否可以删除空格......?
最佳答案
您可以使用 DataTables 选择扩展名:DataTables Select
添加到按钮导出选项:
modifier: {
selected: true
}
和
select: true
初始化DataTable代码。
您的新代码:
if( $('.clienttable').length > 0 ) {
$('.clienttable').DataTable( {
pageLength: 10,
select: true,
responsive: true,
dom: '<"html5buttons"B>lTfgitp',
buttons: [
{
extend: 'copyHtml5',
exportOptions: {
columns: [1,2,3,4,5,6],
modifier: {
selected: true
}
}
},
{
extend: 'csvHtml5',
exportOptions: {
columns: [1,2,3,4,5,6],
modifier: {
selected: true
}
}
},
{
extend: 'excelHtml5',
exportOptions: {
columns: [1,2,3,4,5,6],
modifier: {
selected: true
}
}
},
{
extend: 'pdfHtml5',
exportOptions: {
columns: [1,2,3,4,5,6],
modifier: {
selected: true
}
},
title: 'List of Clients',
}
],
columnDefs: [
{ targets: [0], orderable: false },
{ targets: [7], orderable: false }
],
"order": [[ 6, "desc" ]]
});
}
现在您可以只打印选定的行。
关于php - 使用 jquery 导出 PDF、CSV、Excel 表单数据表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49275948/