Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change default name of buttons in datatable plugin?

I am using datatables plugin for by displaying data in my html page. I have a requirement where I want to export the data inside the datatable.

Datatable supports this functionality by some plugins and a example can be seen here.

what I get on screen is that the export buttons with the fixed default names like below

enter image description here

I want to change the default names to custom names. eg. "Excel" to "Export to Excel"

How can I do that?

$(document).ready(function() {
    $('#example').DataTable( {
        dom: 'Bfrtip',
        buttons: [
            'copy', 'csv', 'excel', 'pdf', 'print'
        ]
    } );
} );

In the above code if I change the default names , then my functionality breaks because datatable recognizes the functionality of button by its name. Is there any property which I should use which will help me achieve what I want or any other way out?

like image 847
Chetan Avatar asked Dec 13 '25 21:12

Chetan


2 Answers

With the new version of DataTables;

buttons: [
   { 
      extend: 'copy',
      text: 'Copy to clipboard'
   }
]

Here is the example from documentation.

like image 154
Emre Bolat Avatar answered Dec 16 '25 10:12

Emre Bolat


You can try this:

buttons: [
   { 
      sExtends: 'copy',
      text: 'Custom text'
   }
]
like image 27
kapantzak Avatar answered Dec 16 '25 09:12

kapantzak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!