如何用语言文件添加数据表按钮?

时间:2018-09-13 09:55:36

标签: javascript jquery datatables

我尝试将我的翻译文件与提取按钮一起使用,但没有成功

这是我的代码:

  $(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' );
  });

问题是,当我添加"oLanguage": { "sUrl": "/public/us.txt" }行时,按钮没有出现,并且在Google控制台中没有错误

编辑:

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"
    }
}

0 个答案:

没有答案