$("#dataTable").DataTable({
dom: 'Bfrtip',
buttons: [
{ extend: 'excel', text:'export to excel',title:'1'},
],
})
I can change the text of the button by the following code,but I can't get the title property.
var table= $("#dataTable").DataTable();
tabele.button(0).text('excel');
once it has been set in the object and the datatable initialized it can't be changed. you can set it dynamically from a page element on the init though.
("#dataTable").each( function(index) {
var exportTitle = $("#somePageElement").text();
$(this).DataTable({
dom: 'Bfrtip',
buttons: [
{
extend: 'excel',
title: exportTitle
},
{
extend: 'pdf',
title: exportTitle
}
]
});
this post has a good suggestion on how to deal with this as well. Setting up a custom file name datatables export excelHtml5 with a select text
In my case, I had to override the button's action, to add something to change the title, then call the original button method.
Extending CSV in this example:
$("#dataTable").DataTable({
dom: 'Bfrtip',
buttons: [
{extend: 'csv',
text:'export to csv',
title:'1',
action: function(e, dt, button, config) {
config.title = "New title";
// This checks whether the HTML5 or flash version needs
// to be called, so it's not needed if the button you are using
// doesn't have that distinction
if ($.fn.dataTable.ext.buttons.csvHtml5.available( dt, config )) {
$.fn.dataTable.ext.buttons.csvHtml5.action(e, dt, button, config);
}
else {
$.fn.dataTable.ext.buttons.csvFlash.action(e, dt, button, config);
}
}}
]
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With