问题
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