How to add Datatables buttons with language file?

How to add Datatables buttons with language file?

Loulou90Loulou90 Posts: 11Questions: 4Answers: 0

Hello,
I try, but without success, to use my translation file with extraction buttons

Here is my code:

  $(document).ready(function(){
    var table = $('#table').DataTable({
      "columnDefs": [{"orderable": false, "targets": 5}],
      "order": [1, "desc"],
      "oLanguage": { "sUrl": "/public/us.txt" },
      buttons: [{
        extend: 'csv',
        text: '<i class="fa fa-download"></i> Export to CSV',
        title: 'Data export - <?= date("YmdHi") ?>',
        className: 'btn-sm',
        exportOptions: { columns: [0, 1, 2, 3, 4, 5] }
      },{
        extend: 'excel',
        text: '<i class="fa fa-download"></i> Export to Excel',
        title: 'Data export - <?= date("YmdHi") ?>',
        className: 'btn-sm',
        exportOptions: { columns: [0, 1, 2, 3, 4, 5] }
      }]
    });
    table.buttons().container().appendTo( '.button-container' );
  });

The problem is when I add the line "oLanguage": { "sUrl": "/public/us.txt" } the buttons do not appear and I have no errors in the google console

So How to add Datatables buttons with language file?
Thank you

Answers

  • Loulou90Loulou90 Posts: 11Questions: 4Answers: 0

    us.txt :

        {
            "sEmptyTable":     "No data available in table",
            "sInfo":           "Showing _START_ to _END_ of _TOTAL_ entries",
            "sInfoEmpty":      "Showing 0 to 0 of 0 entries",
            "sInfoFiltered":   "(filtered from _MAX_ total entries)",
            "sInfoPostFix":    "",
            "sInfoThousands":  ",",
            "sLengthMenu":     "_MENU_ entries",
            "sLoadingRecords": "Loading...",
            "sProcessing":     "Processing...",
            "sSearch":         "",
            "searchPlaceholder": "Search ...",
            "sZeroRecords":    "No matching records found",
            "oPaginate": {
                "sFirst":    "First",
                "sLast":     "Last",
                "sNext":     "Next",
                "sPrevious": "Previous"
            },
            "oAria": {
                "sSortAscending":  ": activate to sort column ascending",
                "sSortDescending": ": activate to sort column descending"
            }
        }
    
  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    Hi @Loulou90 ,

    That does look right, the same (more or less) as this example. If you could link to a running test case showing the issue we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • ASKempASKemp Posts: 19Questions: 7Answers: 0

    How do you reference the buttons from the language file, what are the identifiers?

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    The documentation for each Button states where it will read the language information from - for example for copyHtml5 you use the language.buttons.copy property for that button in the language file:

    The button's display text. The text can be configured using this option (see buttons.buttons.text) or the buttons.copy option of the DataTables language object.

    We're going to work on a central repository of all translatable strings we use at some point (not sure of the time frame yet).

    Allan

This discussion has been closed.