on 'open' event for all editors
on 'open' event for all editors
Loren Maxwell
Posts: 387Questions: 94Answers: 10
in Editor
I have several editors on a single page and want to modify each with the open
:
var editor_1 = new $.fn.dataTable.Editor( {
... Blah Blah Blah ...
}).on( 'open', function ( e, mode, action ) {
$(".modal-dialog").addClass("modal-xl")
})
var editor_2 = new $.fn.dataTable.Editor( {
... Blah Blah Blah ...
}).on( 'open', function ( e, mode, action ) {
$(".modal-dialog").addClass("modal-xl")
})
var editor_3 = new $.fn.dataTable.Editor( {
... Blah Blah Blah ...
}).on( 'open', function ( e, mode, action ) {
$(".modal-dialog").addClass("modal-xl")
})
Is there a way to do a single open
for any and all instances of editors that open on that page?
Something like:
var editor_1 = new $.fn.dataTable.Editor( {
... Blah Blah Blah ...
})
var editor_2 = new $.fn.dataTable.Editor( {
... Blah Blah Blah ...
})
var editor_3 = new $.fn.dataTable.Editor( {
... Blah Blah Blah ...
})
any_and_all_editors.on( 'open', function ( e, mode, action ) {
$(".modal-dialog").addClass("modal-xl")
})
This question has accepted answers - jump to:
Answers
There isn't like that, but you can at least share the function between them:
However, there is a better option. The same modal is shared between them all, so you only need to add it once. Of course you might not be sure which one will be opened first, but you can use
displayNode()
to get the modal container. So aftereditor_1
initialisation:will do it. Or even better, use the
classes
property of the Bootstrap controller for Editor:I'd go with the last option, but there is more than one way of doing this
Allan
Thanks @allan, that's good for the modal but I was actually hoping to do a few other things as well (I shortened the code in my original question for brevity, but unfortunately lost some of the detail I should have captured!):
It seems the
editorOpen
function might be the best given the other things I'm trying to do.Thanks!
Agreed - a shared function would be best in this case.
Allan
My ultimate solution was to use the
initEditor
to attach anopen
to each new instance of Editor: