扩展数据表”;fnInitComplete”;

Extend Datatables "fnInitComplete"?

本文关键字:fnInitComplete 数据表 扩展      更新时间:2023-09-26

我知道你可以为所有数据表设置默认值,如下所示:

jQuery.extend(jQuery.fn.dataTableExt.oSort, {
    "num-html-desc": function (a, b) {
        return ((a < b) ? 1 : ((a > b) ? -1 : 0));
    }
});

但我想为fnInitComplete设置一个默认函数,该函数将与/不在其他地方覆盖该函数一起工作,因此是默认函数。我怎样才能做到这一点?

您可以添加fnInitComplete默认值:

$.extend($.fn.dataTable.defaults, {
    "fnInitComplete": function (oSettings, json) { doSomething(); }
});

为了防止在设置数据表时被覆盖,您可以这样做:

$('#myTable').dataTable({
    //lots of other properties here
    "fnInitComplete": function (oSettings, json) {
       $.fn.dataTable.defaults.fnInitComplete(oSettings, json);
       doSomethingElse();
    }
});