[英]jQuery Datatables Export Buttons Dynamic file name and title
I use jQuery datatable and Export buttons. 我使用jQuery数据表和导出按钮。
I change the filename and the title. 我更改文件名和标题。
My problem is that I want the title to be dynamic, based on the filters and custom filters. 我的问题是,我希望标题基于过滤器和自定义过滤器是动态的。
My problem is that The file name configured on the first load only 我的问题是仅在首次加载时配置的文件名
.withButtons([
{
extend: "excelHtml5",
filename :$scope.getFileName(false),
title:$scope.getFileName(true),
exportOptions: {
columns: ':visible'
},
//CharSet: "utf8",
exportData: { decodeEntities: true}
},
Of course $scope.getFileName()
is only called once, or the number of times you intentionally call it. 当然, $scope.getFileName()
仅被调用一次,或者您有意调用它的次数。 Go the other way around : Use the init()
function along with a $watch
: 反过来:将init()
函数与$watch
一起使用:
.withButtons([{
extend: "excelHtml5",
//filename: $scope.getFileName(false),
//title: $scope.getFileName(true),
exportOptions: {
columns: ':visible'
},
//CharSet: "utf8",
exportData: {
decodeEntities: true
},
init: function(dt, node, config) {
$scope.watch('fileName', function()
//config.filename is in fact config.title + config.extension
config.title = $scope.fileName.title;
config.extension = $scope.fileName.extension;
})
}
}])
You are not explaining why you need to use a $scope.getFileName()
despite you are using angular where such things is easily automated. 您并没有解释为什么需要使用$scope.getFileName()
尽管您使用的是容易进行自动化的角度操作。 With the above you can now update a fileName
struct on $scope
whenever it is needed, and the export filename will change accordingly 通过上面的内容,您现在可以随时在$scope
上更新fileName
结构,并且导出文件名也将相应更改。
$scope.fileName = {
extension: '.xls',
title: 'my-table-export'
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.