Chetan
Chetan

Reputation: 5095

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?

Upvotes: 3

Views: 8133

Answers (3)

Manas Sahoo
Manas Sahoo

Reputation: 91

buttons: [
    { extend: 'excel', text: 'Export to excel' }
]

Upvotes: 1

Emre Bolat
Emre Bolat

Reputation: 4552

With the new version of DataTables;

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

Here is the example from documentation.

Upvotes: 9

kapantzak
kapantzak

Reputation: 11750

You can try this:

buttons: [
   { 
      sExtends: 'copy',
      text: 'Custom text'
   }
]

Upvotes: 1

Related Questions