我正在使用Datatables.net,我需要根据输入字段的值更改导出文档的标题(excelHtml5和pdfHtml5)。 我们的想法是让用户根据搜索结果更改导出的文件标题。
现在我的所有按钮都具有相同的标题值:
{
extend: 'excelHtml5',
title: 'Title 1', //change this value based on an input field
},
{
extend: 'pdfHtml5',
title: 'Title 2', //change this value based on an input field
}
我怎样才能做到这一点?
答案 0 :(得分:0)
要更新导出按钮的title属性,我使用了该按钮的操作方法:
action: function (e, dt, node, config)
{
///update title property based on the added input field
config.title = $("#exportTitle").val();
///procede with the export
$.fn.dataTable.ext.buttons.excelHtml5.action(e, dt, node, config);
},
希望这有帮助。
答案 1 :(得分:0)
我发现这种方法适用于我的情况。 jQuery DataTable Set Title On Button Click
buttons: [
{
extend: 'excelHtml5',
title: function() {
return $("#exportTitle").val();
}
},
{
extend: 'pdfHtml5',
title: function() {
return $("#exportTitle").val();
}
}
]