table.editor() results in 'undefined'

table.editor() results in 'undefined'

raffaelraffael Posts: 4Questions: 1Answers: 0
edited January 2020 in Editor

Hi,

I am using a local inline editor with submit on blur which works just fine.

Now, I also want to submit just edited values when the submit button of the whole form is clicked. However, when the submit button is directly clicked, the submit on blur does not take effect.

Therefore, I call a JavaScript function before the actual submit action. In the JavaScript function I manually trigger editor.submit(). This also works fine as you can see in this example.

However, when I use the same submit() JavaScript function in my code, the editor variable is always undefined.

Any idea what could cause this issue?

Can this be narrowed down to some specific calls which I could post here? I do not want to post the whole JavaScript code here.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    That would suggest it hasn't been declared. Or declared outside the scope of the area you're calling it in. WIthout seeing the code, or a link to the page, it's hard to say.

    Colin

  • raffaelraffael Posts: 4Questions: 1Answers: 0

    Hi Colin,

    I tried to create a minimal example from my code to show the described behavior, see here.

    Clicking the submit button results in error "editor is undefined".

    Note that commenting out the scroller and scrollY property seems to fix the error but I need to use the scroller extension.

    Thanks for your help.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Thanks for the test case, but it's not loading for me. Please could you take a look and ensure it replicates the issue reported.

    Colin

  • raffaelraffael Posts: 4Questions: 1Answers: 0

    Interesting. For me the linked test case works as expected. No matter which browser, even on different machines. Perhaps you need to clear your browser cache?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Its also not running for me I'm afraid (Firefox Linux), but is it this like that is causing your problems:

    var editor = dataTable.editor();
    

    ?

    If so, try adding:

    editor: localEditor,
    

    into your DataTables initialisation object. The editor() method isn't always able to pick up the Editor instance defined for a table and this change should address that.

    Allan

  • raffaelraffael Posts: 4Questions: 1Answers: 0

    Hi Allan,

    thanks, it seems that this solved it.
    I never stumbled upon this editor property. Is it described somewhere?

    And I am still wondering why the example does not work for both of you. I have tried it on different machines, different browsers, mobile, it always works.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    No idea why it isn't working I'm afraid!

    The editor property actually isn't document - it's really a fallback. Indeed I wouldn't really encorage use of editor() since it is quite possible to have multiple Editor instances for a single DataTable. Normally I would suggest assigning the instance to a variable and then using that variable whenever you need to access the instance.

    Allan

This discussion has been closed.