简体   繁体   English

编写扩展时,Jquery DataTables在preInit上默认“dom”命令更新

[英]Jquery DataTables default 'dom' order update on preInit when writing an extension

Below code works fine. 下面的代码工作正常。 I can write my extension logics in _constructor and extended defaults will get overwrite in all the tables. 我可以在_constructor中编写扩展逻辑,扩展默认值将在所有表中覆盖。

(function(window, document, undefined){

var factory = function($, DataTable) {
    "use strict";

    $.extend(true, DataTable.defaults, {
        dom: '<"dataTablesTop"' +
            'f' +
            '<"dataTables_toolbar">' +
            '>' +
            'rt' +
            '<"dataTablesBottom"' +
            'lip' +
            '>'
    });

    myExtension.prototype = {
            _constructor: function(){
                  ....
            }
    }

    ....

    return myExtension;

})(window, document);

But my expected out come is to apply the extended overwrites based on a config value passed along with the DataTables initialization. 但我的预期结果是根据与DataTables初始化一起传递的配置值应用扩展覆盖。

var oTable = $('#table').DataTable({
     myExtension: true
});

Ideally it should be something like, 理想情况下它应该是这样的,

(function(window, document, undefined){

var factory = function($, DataTable) {
    "use strict";

    myExtension.prototype = {
            _constructor: function(){
                if(settings.myExtension){
                   $.extend(true, DataTable.defaults, {
                       dom: '<"dataTablesTop"' +
                            'f' +
                            '<"dataTables_toolbar">' +
                            '>' +
                            'rt' +
                            '<"dataTablesBottom"' +
                            'lip' +
                            '>'
                   });
                }
            }
    }

    .....

    return myExtension;


})(window, document);

Anybody have an idea how to achieve it? 有人知道如何实现它吗?

Looks like this isn't possible at the moment. 目前看来这是不可能的。 DataTables initialize dom elements before 'preInit' callback. DataTables在'preInit'回调之前初始化dom元素。 So looks like need to push/inject additional elements in the construction stage. 因此看起来需要在构建阶段推送/注入其他元素。

Reference: https://datatables.net/forums/discussion/25342/init-dt-is-not-fired-before-the-first-xhr-event#Comment_69825 参考: https//datatables.net/forums/discussion/25342/init-dt-is-not-fired-before-the-first-xhr-event#Comment_69825

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM