Enable datatable warning alert

别等时光非礼了梦想. 提交于 2019-12-12 19:18:09

问题


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.

How can i do that?

here is my code:

        //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';

回答1:


You need to use error event after specifying errMode = 'none'

Error event

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.

To use this event, first specify errMode to none

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

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();

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



来源:https://stackoverflow.com/questions/50684951/enable-datatable-warning-alert

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!