Javascript 从datatable导出选定行的csv文件
我使用以下示例创建了一个datatable: 一, 二, 我的代码如下:Javascript 从datatable导出选定行的csv文件,javascript,jquery,html,datatable,Javascript,Jquery,Html,Datatable,我使用以下示例创建了一个datatable: 一, 二, 我的代码如下: <script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Setup - add a text input to each footer cell $('#example tfoot th').each( function () { var title = $(th
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Setup - add a text input to each footer cell
$('#example tfoot th').each( function () {
var title = $(this).text();
$(this).html( '<input type="text" placeholder="Search '+title+'" />' );
} );
// DataTable
var table = $('#example').DataTable({'scrollX':true, 'dom': 'lBfrtip','buttons': ['csv']});
// Apply the search
table.columns().every( function () {
var that = this;
$( 'input', this.footer() ).on( 'keyup change', function () {
if ( that.search() !== this.value ) {
that
.search( this.value )
.draw();
}
} );
} );
} );
</script>
$(文档).ready(函数(){
//设置-向每个页脚单元格添加文本输入
$('#示例tfoot th')。每个(函数(){
var title=$(this.text();
$(this.html(“”);
} );
//数据表
变量表=$(“#示例”).DataTable({'scrollX':true,'dom':'lBfrtip','buttons':['csv']});
//应用搜索
table.columns().every(函数(){
var=这个;
$('input',this.footer()).on('keyup change',函数(){
如果(that.search()!==this.value){
那个
.search(this.value)
.draw();
}
} );
} );
} );
这段代码工作得很好。现在,我只想导出选定的行,而不更改示例1中的datatable结构。我不是Jquery方面的专家。有人能帮我吗?是否可以添加用于选择行的复选框
谢谢我通过使用以下代码成功地做到了这一点:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Setup - add a text input to each footer cell
$('#example tfoot th').each( function () {
var title = $(this).text();
$(this).html( '<input type="text" placeholder="Search '+title+'" />' );
} );
// DataTable
var table = $('#example').DataTable({'scrollX':true, 'dom': 'lBfrtip',buttons: [{ extend: 'csv',text: 'CSV all'},{extend: 'csv',text: 'CSV selected',exportOptions: {modifier: {selected: true}}}],select: true});
// Apply the search
table.columns().every( function () {
var that = this;
$( 'input', this.footer() ).on( 'keyup change', function () {
if ( that.search() !== this.value ) {
that
.search( this.value )
.draw();
}
} );
} );
} );
</script>
你能说得更具体些吗?请详细说明“选定行”我的表中有N行。用户可以根据表中的可用信息选择行(不同的列将提供不同的信息),然后他们可以将这些选定行作为csv文件下载
buttons: [{ extend: 'csv',text: 'CSV all'},{extend: 'csv',text: 'CSV selected',exportOptions: {modifier: {selected: true}}}],select: true