Extending the Editor.models.displayController more than once on the same page

Extending the Editor.models.displayController more than once on the same page

fmeyer@nearbysoftware.comfmeyer@nearbysoftware.com Posts: 18Questions: 5Answers: 0
edited January 2016 in Editor

Hello,

I have a perfectly working DataTable/Editor where I extended the Editor form taking inspiration from Allan's sample here : http://editor.datatables.net/examples/plug-ins/displayController.html

Now I have to add in the same web page(!) another DataTable/Editor where I would like the custom form and behaviour to be somewhat different than from the first one.

The problem is that with the lines (taken from the sample):

...
(function () {
    var Editor = $.fn.dataTable.Editor;
    Editor.display.details = $.extend(true, {}, Editor.models.displayController, {
        "init": function (editor) {
        ...
        },
        "open": function (editor, append, callback) {
        ...
        },
       
        "close": function (editor, callback) {
        ...
        },
    });
})();
...

The second time I run this, obviously, it replaces the already overloaded "open", "init" and "close" functions from the first DataTable/Editor with these last ones (from the second run).
Thus, all tables even the first one is having only one overloaded version of those functions, which are the last ones overwritten by the second call to $.extend.

Is there a way to achieve what I want?
I am beginning to be not so sure about that.
A work around would then maybe to design the extension code so that it works for both and run the setup/extend code only once, provided that I have a way to distinguish both use cases in the code.

Can anyone confirm what is the correct way to go?

Thanks

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Would there be any issue with simply giving the second display controller a different name?

    Editor.display.details2 = $.extend( ... );
    

    I'm sure you could probably pick a better name than details2, but that shows the concept.

    Allan

  • fmeyer@nearbysoftware.comfmeyer@nearbysoftware.com Posts: 18Questions: 5Answers: 0

    Damn!
    It was as simple as that, and seems now obvious.
    Sorry ;)
    Seems I need to improve on my Javascript and DataTable skills!
    Thanks Allan.

This discussion has been closed.