【问题标题】:Customizing pagination info in jquery datatable is not working while table is empty表为空时,在 jquery 数据表中自定义分页信息不起作用
【发布时间】:2015-12-23 09:55:24
【问题描述】:

我正在自定义分页信息,当 jquery 数据表中有一些数据时它工作正常。但是当表为空时,同样不起作用。

将 sInfo 从“显示_START_to_END_of_TOTAL_条目”自定义为“显示_START_to_END_of_TOTAL_”。

示例代码在这里。 http://jsfiddle.net/inDiscover/d1fg8mrt/

HTML

<table id="myTable">
    <thead>
        <tr>
            <th>Header</th>
        </tr>
    </thead>
    <tbody>

    </tbody>
</table>

JS代码

$(document).ready(function(){
 var oDTOptions = {};
 oDTOptions = {"oLanguage": {"sInfo": "Showing _START_ to _END_ of _TOTAL_"}};

    $('#myTable').dataTable(oDTOptions);
});

【问题讨论】:

    标签: jquery datatable datatables


    【解决方案1】:

    空记录的信息文本存储在sInfoEmpty。所以

    "oLanguage": {
       "sInfoEmpty": "Showing 0 to 0 of 0",
       "sInfo": "Showing _START_ to _END_ of _TOTAL_"
    }
    

    _START__END__TOTAL_ 在使用 sInfoEmpty 时不会被转换,因为这些值总是 0,所以没有意义。

    更新小提琴 -> http://jsfiddle.net/d1fg8mrt/1/


    上述答案针对的是 OP 正在使用的 dataTables 1.7.5,但也适用于所有 dataTables 1.9.x 和 1.10.x 版本。如果有人想在 1.10.x 中使用非匈牙利命名约定,则等价于:

    language: {
      infoEmpty: "Showing 0 to 0 of 0",
      info: "Showing _START_ to _END_ of _TOTAL_"
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-27
      • 1970-01-01
      • 2018-06-15
      • 2016-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多