启用数据表警告警报 [英] Enable datatable warning alert

查看:132
本文介绍了启用数据表警告警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的js脚本开始用数据填充数据表之前停止数据表警告警报.所以我添加了这一行:

I wanted to stop the datatable warning alert before my js script start filling the datatable with data. So i added this line:

    //hide the warning
    $.fn.dataTable.ext.errMode = 'none';

但是当创建并填充该数据表时,我想再次为脚本中的其余数据表启用警告.

But when that datatable is created and filled, i want to enable the warnings again again for the rest of datatables that are in my script.

我该怎么做?

这是我的代码:

        //hide the warning
    $.fn.dataTable.ext.errMode = 'none';

    //add rows
    $("#addRows").on("click", function ()
    {
        table.clear();

            for (idxT in players)
            {

                table.row.add([
                    pl[idxT],
                    nSh[idxT],
                    onT[idxT],
                    offT[idxT],
                    nG[idxT]                        
                ]).draw(false);

            } //endFor

    });

    // Automatically add rows
    $("#addRows").click();

//now i want to enable warnings again
//eg: $.fn.dataTable.ext.errMode = 'active';

推荐答案

您需要使用错误事件指定 errMode ='none'

错误事件

DataTables提供此事件,使您可以将应用程序自身的错误处理挂接到DataTables中.例如,您可以触发一个Ajax调用,该调用将记录错误以进行调查,或者使用错误事件向最终用户显示自定义错误消息.

DataTables provides this event to allow you to hook your application's own error handling into DataTables. For example you could trigger an Ajax call that will log an error for investigation, or use the error event to show a custom error message to the end user.

要使用此事件,首先将errMode设置为none

To use this event, first specify errMode to none

$.fn.dataTable.ext.errMode = 'none';

并触发此事件,请向.dt命名空间添加此事件,如下所示:

and to trigger this event, append .dt namespace with this event as follow:

$('#example')
    .on( 'error.dt', function ( e, settings, techNote, message ) {
        console.log( 'An error has been reported by DataTables: ', message );
    } )
    .DataTable();

演示>> http://jsfiddle.net/mmushtaq/n2jv0kh8/

Demo >> http://jsfiddle.net/mmushtaq/n2jv0kh8/

这篇关于启用数据表警告警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆