Nested Editing - Where is the data loaded from?
Nested Editing - Where is the data loaded from?
https://editor.datatables.net/examples/datatables/nested.html
I currently have two editor instances that work fine. The second editor uses the results of the first as a "select". In order to cut down on the number of editors/screens/modals/popups, I'm looking to use nested to get rid of the need for the separation.
While I have this "working" - specifically, the datatable appears, the editor is populated, the nested table is populated, and editing / new inserts works. However, when loading the page I get the generic:
Requested unknown parameter 'value' for row 0, column 0
The section of code that generates the error seems to be the column definition for the nesting:
columns: [
{
title: 'Id',
data: 'value'
},
{
title: 'Name',
data: 'label'
}
]
In the ajax of both the standalone editor, as well as the ajax for the nested (same destination), data is returned as id and name. However, when configuring the nest, I had to use value and label.
I'm unsure why, and that's the root of my question.
Where does the data come from that triggers this process? It can't be the ajax call itself, so it must be from the parent table/join? Something is changing the key/value pairs, triggering this required change, and I assume these errors, but I can't seem to nail down where and why.
I'm going to try to put together an example, but I have a feeling (looking at the example data on this website), I wont be able to reproduce it.
This question has an accepted answers - jump to answer
Answers
It looks like the data for the nest is pulled from the parent table request, including all join data, which is transformed to the different format (using field Options()).
https://editor.datatables.net/examples/datatables/select.html
Using the above as another example, I removed the ajax and buttons configuration on my config, and the errors went away.
The key part in the nested example for this point is:
You need to tell Editor where to take the value of the field from in the data populating the table. In the nested example that is the
id
property. You might use something else. TheOptions
will use avalue
/label
pair, which the field expects by default. So when using nested editing, you will very likely want to set theoptionsPair.value
property.Allan
And ... of course you're right. I had it in use before, but commented it out because I continue to get errors (for other reasons that since were fixed).
Thank you for the answer!
Spoke too soon, on submit of a new record (of the nest):
Requested unknown parameter 'label' for row 5, column 0.
Going to dig into that next
That suggests that the data being returned from a create action (possibly edit as well) is in a different format from what is initialise loaded as the data / options for the table field.
Allan
And that more or less defines my initial question and my confusion. The table is standard id/name, it's transformed to value/label by datatables in Options, to support select lists, and it has to be transformed back for submission.
On these tables, I'm likely going to just rename the backend database to be value/label, instead, in hope that addresses the fundamental problem.
I'm guessing the core issue might be here:
Is there any chance the php for the nested example could be added to its page? I'm guessing there isn't a translation of data like this for it, considering the results when interrogating the php itself.
Actually, that was exactly the issue. After removing the options altogether, all of the errors/problems went away, and the nested example works in my setup.
The above was definitely causing DT some grief when trying to parse the data.
Trying to figure out how to add validation back in, but minus the validation, it looks real good.
Do you mean like this?
https://editor.datatables.net/manual/net/validation#Multiple-validators
Kevin
Yes and no - previously the validator was defined by Options
This was throwing off the nested feature, so I had to remove it. Then I just had to figure out how to define these things within the dbValues() call, instead of having it defined in options:
I think it's all working, including field validation now. Thanks for listening to the ramblings of a user.
Awesome - good to hear that you've got it working.
Allan