首页 > 解决方案 > 如何使用语言文件添加数据表按钮?

问题描述

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

这是我的代码:

  $(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" }按钮没有出现并且我在谷歌控制台中没有错误

编辑 :

我们.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"
    }
}

标签: javascriptjquerydatatables

解决方案


推荐阅读