button - 如何在数据表中动态更改导出文件名?

标签 button datatables export filenames

 $("#dataTable").DataTable({                    
                    dom: 'Bfrtip',
                    buttons: [
                             { extend: 'excel', text:'export to excel',title:'1'},
                    ],
})

我可以通过以下代码更改按钮的文本,但无法获取 title 属性。
var table= $("#dataTable").DataTable();
tabele.button(0).text('excel');

最佳答案

一旦它在对象中被设置并且数据表被初始化,它就不能被改变。不过,您可以从 init 上的页面元素动态设置它。

("#dataTable").each( function(index) {
    var exportTitle = $("#somePageElement").text();
    $(this).DataTable({
        dom: 'Bfrtip',
        buttons: [
            {
                extend: 'excel',
                title: exportTitle 
            },
            {
                extend: 'pdf',
                title: exportTitle 
            }
        ]
    });

这篇文章也对如何处理这个问题提出了很好的建议。 Setting up a custom file name datatables export excelHtml5 with a select text

关于button - 如何在数据表中动态更改导出文件名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34703321/

相关文章:

javascript - 如何获取过滤后的行数

javascript - 在javascript中对对象的关联数组进行排序

涉及多个项目时的 C# 非托管导出 (Robert Giesecke)

ios - 将自定义的 UITableViewCell 导出到 UIImage

android - 错误:error: '#fffffffff' is incompatible with attribute android:color (attr) color

CSS 图像按钮不正确

javascript - 使数据表中的行可点击

mysql - 出现错误 : 2003: Can't connect to MySQL server while taking dump from RDS

c# - 全局按钮的动态样式,每个按钮都有不同的图像

android - 如何在选择器中设置按钮的文本样式?