Debug ajax response for Editor (no errors given)
Debug ajax response for Editor (no errors given)
Is there a way to debug the Ajax response the server sends back after an edit is submitted?
I think I followed the client/server directions properly.
DT is acknowledging the return of the in-line edit with a short fade in/out of the record that was changed, but it's not showing the change in the table. My changed value is reverted back to what it was before. I get no error.
I have a bunch of fields defined in the Editor declaration. Here is one of them:
{ name: 'fields.validated_supporting_event',
type: 'select',
options: [
{ label: "Yes", value: true },
{ label: "No", value: false }
]},
The data the server returns is proper json and looks like this:
{
"data": [
{
"pk": "239",
"fields.friendly_name": "HIE Refresh",
"fields.validated_supporting_event": true,
"fields.need_by_date": "2021-03-03",
"fields.scheduled_submission_date": "2021-02-18",
"fields.fpm": "Kim Xxxx",
"fields.asm": "Mike Xxxx",
"fields.fisse": ""
}
]
}
The same happens when I change a datetime field, so it's not limited to my select field.
This question has an accepted answers - jump to answer
Answers
Does the structure of the json server response need to match the json structure used to setup the table? Look at the two following two json structures:
This one is used to populate the Datatable (just showing one record):
and here is the response I am sending back from the server.
Do I need to match the "fields" branch as it was set in the first json?
As you can see, I'm trying to refer to the fields as with the "field." prefix. Is that correct?
Exactly, the two should match. It would be worth looking at this simple example here - the "Ajax load" and "Ajax data" show the data sent under those two conditions (first load and after an edit) - and as you can see, the format is the same.
Colin
Thanks Colin. The json that finally worked included both the "fields {}" tag as well as the "data {}". I'm all good!
Colin, a quick follow up if I may. I've tested around and was able to only return the pk and the attribute(s) that was/were changed. In the example you cite it appears that the entire record was returned to DataTables.
Can you confirm that I could only return the changed attributes (along with the pk), or is this in unintended / discouraged / depreciated?
Yep, if you've got
submit
set toallIfChanged
in theform-options
it would only send the changed values, so that would be fine. There's an example of that here (for in-line, but the same principle applies),Colin