Adding a datatable form widget inside a repeater doesn't save the data.
@bennothommo this something you'd be interested in looking into?
@LukeTowers no worries, will have a look.
I'd say it's a confirmed bug. It appears the Datatable widget is not following the same form key structure that other fields inside the repeater use on form submit.

eg. The suburb field inside the repeater has the form key Country[states][0][item][1][subtitle] whereas the safety datatable just starts with safetyTableData.
The way that data tables return their data lead me to believe they are not set up to be used more than once on a page. I'm still trying to grasp how repeaters and widgets pass their data between each other so I can't yet point someone in the right direction on how this could be resolved.
This https://github.com/octobercms/october/blob/master/modules/backend/widgets/Table.php#L81-L86 is probably the problem. It might need to be changed to use $this->alias instead
@bennothommo the alias property is usually the one used to construct the actual name attributes for the inputs on a form, and this alias gets passed around by the Repeater and the Nested Form and the Relation Controller. The alias property is used for generating the field names and for namespacing the AJAX handlers
@LukeTowers The alias is already fed through this line here I believe:
https://github.com/octobercms/october/blob/master/modules/backend/widgets/Table.php#L61
I feel It might have something to do with the arrayName value that is defined in the FormField class encasing the widget - it doesn't seem to feed down into the Table widget, or doesn't seem to be handled in any way. When I added the arrayName to the fieldName of the Table widget, it did actually save the table data in the database - although it contains said data in a TableData JSON object. It also couldn't load the data after save.
Interesting, are you able to continue digging into it further @bennothommo or do you need me to take a longer look at it?
I'll be happy to continue looking into it, but I anticipate my spare time over the next couple of weeks will be very limited.
I have noticed that the data tables in the Builder plugin are being processed via JS first in which the data is extracted from the table. This is before it ever reaches the AJAX handlers. I have yet to actually see it used in a standard form context yet.
Maybe throw the "Help wanted" label on this one, as I'd be keen to hear from anyone who has used the datatable in a project or plugin and if they did just add it through a form config and used the standard save functionality or if they required some extra handling in place first.
@LukeTowers I've continued to look into this a bit further. I might have set it up incorrectly, but I've found the datatable doesn't really save correctly even outside of a repeater because of the way it renames the field data to <fieldName>TableData, so unless you've set up a model to specifically handle the data with that name, you can't just simply the use the datatable as is.
I've noticed with the datatable widgets in the Builder plugin, the data is extracted via JS and saved in an AJAX call. It's possible that this was the intended way of using it when it was built.
We could potentially rewrite this to use a standard field name on save, but I am concerned it may cause a BC break for anyone currently using it.
@bennothommo isn't that the purpose of the getSaveValue() method, to interpret the data that gets sent to the server and return it in a useful form to the Form widget? https://github.com/octobercms/october/blob/master/modules/backend/formwidgets/DataTable.php#L108
@LukeTowers @bennothommo
https://www.bountysource.com/issues/68728539-datatable-not-saved-when-inside-repeater
PR submitted :) https://github.com/octobercms/october/pull/4102
Fix will be in the next build (448). @seanthepottingshed please release the bounty to @bennothommo
@LukeTowers I'm happy for the bounty to go to the October war chest :)
@bennothommo thanks, I appreciate that and the code contributions!
@bennothommo @LukeTowers
Thanks guys, I've released the Bounty for the claim. Will raise another Bounty for another issue later on today if I get the opportunity.
Appreciate it @seanthepottingshed. If you don't mind, I'd prefer bounties were run straight through PayPal, bountysource takes a 10% fee for not really that much added value in my opinion.
@LukeTowers
Sorry I wasn't aware of the 10% tax - absolutely no problem going forwards, should I just totally bypass Bountysource in the future?
I'll DM you on Slack when I see you're about.
Most helpful comment
@LukeTowers no worries, will have a look.