Editor "datatable" field type depends on Select extension. Bug or a feature?
Editor "datatable" field type depends on Select extension. Bug or a feature?

Error messages shown:
Dev console says: "Uncaught TypeError: Cannot read properties of undefined (reading 'init')" in dataTables.editor.js:5598
This is on statement: "DataTable$4.select.init(api);"
Description of problem:
Seems like "datatable" Editor field type needs Select extension loaded to init Editor instance, even when not using any select functionality at all.
I use simple click on table row (or icons for example) to open editor. Inside editor, datatable field is pure read-only table of child records with no select functionality either. Just spent entire day trying to figure out why I get this error while folloowing all exmaples and discussions.
Proposed solution:
Either refactor Editor to depend on Select only when needed, or add warning to documentation and examples using this functionality
This question has an accepted answers - jump to answer
Answers
You will be if you are using the
datatable
field type. As the examples show thedatatable
field type is basically a replacement for aselect
list, and you need to be able to select values from the list.That's not a situation that I'd considered or have come across before as a use for the
datatable
field type. Its a good point though, I can see that it might be useful at times.What you can do for such a case is override the default of having Select enabled on the table by passing in a
config
object:Should do it I think.
I will add a note to
datatable
to say that Select is required for standard use.Thanks,
Allan
Hello Allan, that doesn't work either, Select still needed even if selecting is disabled.
Generally speaking selecting rows is most useful with Buttons, especially for multirow actions. For singe row edit/delete actions we use links or icons inside table rows, so it takes only one click for user and Select is not needed at all.
Using Datatable inside Editor is a great feature for listing complex related records, even if that records are not directly editable (there is no nested Editor instance). For example we edit submitted eshop order (status, delivery date, notes) with list of all order items. This is 1:M db relation between order and items, you are not selecting specific item for an order. So there is no "item" field in orders table.
Even some examples are a bit misleading. Here In Sites editor you are not really selecting from Users, you only list them for a Site and give an opportunity to quickly edit user's record. You select from sites inside nested users editor, that's right.
Ah yes, sorry, you are right.
datatable
will still use Select's methods got the get and set actions (since it is generally expecting to take a value like a normal field). You are right, in some cases it doesn't take a value, but even in the example linked to Select is used to allow editing on the nested table.I've added a note to the
datatable
page to state that Select is required for its operation at this time (I'll deploy the update to the site soon, it is in my git repo only atm). I'll also consider how this field might be made to operate without Select, or if a new readonly field type similar toreadonly
might be useful.Thanks for bringing this up!
Allan