我使用的是Datatables.net,并且需要根据输入字段的值更改导出文档(excelHtml5和pdfHtml5)的标题。这个想法是让用户根据他们的搜索来更改导出文件的标题。
现在,我的所有按钮都有相同的title值:
{
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
}我如何才能做到这一点呢?
发布于 2017-02-25 19:26:37
为了更新导出按钮的title属性,我使用了该按钮的action方法:
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);
},希望这能有所帮助。
发布于 2018-10-09 01:55:20
我发现这在我的情况下很管用。jQuery DataTable Set Title On Button Click
buttons: [
{
extend: 'excelHtml5',
title: function() {
return $("#exportTitle").val();
}
},
{
extend: 'pdfHtml5',
title: function() {
return $("#exportTitle").val();
}
}
]https://stackoverflow.com/questions/42449582
复制相似问题