javascript 如何在表为空或在 jquery 数据表中找不到匹配项时添加自定义警告消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20181740/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 17:57:51  来源:igfitidea点击:

How to add custom warning message on table empty or no match found in jquery datatable

javascriptphpjquerydatatablewarnings

提问by user2691372

I have 2 data-table sharing the same jquery-dataTables-js because I cannot change it inside the JavaScript file, is there any alternate way that I can change it

我有 2 个数据表共享相同的 jquery-dataTables-js,因为我无法在 JavaScript 文件中更改它,是否有任何替代方法可以更改它

I want to customize the default error message to my own.

我想将默认错误消息自定义为我自己的。

No matching records found - We don't add anything yet No data available in table - no data of your choice.

没有找到匹配的记录 - 我们还没有添加任何内容 表中没有可用数据 - 没有您选择的数据。

回答by sansarp

check this which sets your custom messages.

检查此设置您的自定义消息。

$(document).ready(function() {
    $('#data_table_id').DataTable( {
        "language": {
            "lengthMenu": "Display -- records per page",
            "zeroRecords": "No matching records found - We don't add anything yet No data available in table - no data of your choice.",
            "infoEmpty": "No records available"
        }
    } );
} );

回答by Jompper

See here for http://datatables.net/usage/i18nediting default datatable texts. Also here's an example http://datatables.net/examples/basic_init/language.html

有关编辑默认数据表文本的信息,请参见http://datatables.net/usage/i18n。还有一个例子http://datatables.net/examples/basic_init/language.html

回答by sumit

You can also do it in initCompletelike below. It is more flexible in terms of adding custom classes and designs

你也可以initComplete像下面那样做。在添加自定义类和设计方面更加灵活

"initComplete": function(settings, json) {

        $('.dataTables_empty').html("<span class='label label-danger'>No records found</span>");

    }

回答by Urja Satodiya

I am using Datatable 1.10.12 and below code works for me:

我正在使用 Datatable 1.10.12 和以下代码对我有用:

"language": {
    "processing": '<div class="widget-loader" id="loader"><div class="load-dots"><span></span><span></span><span></span></div></div>',
    // show when no record found in a table...
    "emptyTable": '<h4 class="block text-center"><i class="fa fa-exclamation-triangle" style="color: #C49F47;"></i> {{ __("no_record_found") }}</h4>',
    // shown when no matching row found in filtering...
    "zeroRecords": '<h4 class="block text-center"><i class="fa fa-exclamation-triangle" style="color: #C49F47;"></i> {{ __("no_record_found") }}</h4>'
}

Refer: How to show empty data message in Datatables

参考:如何在数据表中显示空数据消息