confusion about function parameters to editor.inline() function
confusion about function parameters to editor.inline() function
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
The
fieldName
parameter is optional and is expected to be astring
. Theopts
parameter is also option and is ofform-options
which looks like its essentially an object. I think the Datatables code does type checking and if, in this case, the type is astring
it will process it a thefieldName
parameter. Otherwise if its an object (form-options
) it will process it as theopts
parameter.I've seen this type of pattern in other places in Datatables.
Does this answer your question?
Kevin
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.
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:
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
Thank you Allan!