confusion about function parameters to editor.inline() function

confusion about function parameters to editor.inline() function

jettyappjettyapp Posts: 15Questions: 3Answers: 0

Description of problem: if you look at the editor's inline function page: https://editor.datatables.net/reference/api/inline()
NONE of the examples sends parameter 2 or 3 as documented.
One of the examples sends a 'settings' object as parameter #2 which is documented to be "a single field name to edit"...

What the heck is going on here? The examples I have seen don't work according to this documentation either.
see: https://editor.datatables.net/examples/inline-editing/fullRowCreate.html for an example.
What am I missing?

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 14,086Questions: 25Answers: 3,322
    Answer ✓

    The fieldName parameter is optional and is expected to be a string. The opts parameter is also option and is of form-options which looks like its essentially an object. I think the Datatables code does type checking and if, in this case, the type is a string it will process it a the fieldName parameter. Otherwise if its an object (form-options) it will process it as the opts parameter.

    I've seen this type of pattern in other places in Datatables.

    Does this answer your question?

    Kevin

  • jettyappjettyapp Posts: 15Questions: 3Answers: 0

    Thank you kthorngren, yes, maybe that's what is going on here. That does not jive well with TypeScript which is trying to protect us from getting parameters messed up, also it is really subtly documented. i.e. that the last to parameters are shown as optional. It would have been far better if the option could be either a value or null for no value.

  • allanallan Posts: 54,881Questions: 1Answers: 8,601 Site admin
    Answer ✓

    Hi,

    Kevin is spot on as usual. The square brackets in our method documentation indicate an optional parameter, so in a more overload type methodology the method signatures would be:

    inline( nodes )
    inline( nodes, fieldName )
    inline( nodes, opts )
    inline( nodes, fieldName, opts )
    

    We used the square bracket notation assuming that developers would be familiar with it from jQuery's documentation, but we guess we've moved away from that now :).

    The overload structure might be clearer, I'll look into doing that - although it would take time since there is a lot of documentation :).

    If TypeScript is objecting to that, then we must have messed up our TypeScript definition for Editor and looking at the code, that is indeed the case - sorry! I've logged a bug for that and will get it sorted out.

    Allan

  • jettyappjettyapp Posts: 15Questions: 3Answers: 0

    Thank you Allan!

Sign In or Register to comment.