Datatable custom error handling not working

感情迁移 提交于 2020-06-25 03:35:12

问题


I am writing an application using Data-table plugin. I want to handle the error thrown by plugin by my function but plugin always show a alert box with error message.

In the page load event, I am creating a datatable plugin and registering a handler.

function callOnLoad()
{
    $.fn.dataTable.ext.errorMode = "none";

    auditViewTable = $("#div").on("error.dt",function(e, settings, techNote, message ){
        console.log("error");
    })
    .DataTable({
        "processing": true,
        "serverSide": true,
        "ajax": "getData",
        "columns": [
            { "data": "events" },
            { "data": "id" },
            { "data": "name" },
            { "data": "obj_id" },
            { "data": "obj" }
        ]
    });
}

Please help me where I am going wrong.


回答1:


See the documentation -> http://datatables.net/reference/event/error

  1. error.dt was first introduced in 1.10.5 !! So you must use at least 1.10.5. Proof of concept : works not, 1.10.4 example / works, 1.10.5 example.

  2. The correct option to target is $.fn.dataTable.ext.errMode.

  3. A working example would be using >1.10.4 and

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


来源:https://stackoverflow.com/questions/30283140/datatable-custom-error-handling-not-working

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