Debug ajax response for Editor (no errors given)

Debug ajax response for Editor (no errors given)

stephanbstephanb Posts: 36Questions: 11Answers: 0

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

  • stephanbstephanb Posts: 36Questions: 11Answers: 0
    edited March 2021

    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):

            {
              "model": "CAsPr_Web.caspradminview",
              "pk": 239,
              "fields": {
                "friendly_name": "HIE Refresh",
                "assessment_type": "1D_T",
                "assessment_stage": "On Hold",
                "priority": 1,
                "validated_supporting_event": true,
                "need_by_date": "2021-03-03",
                "scheduled_submission_date": "2021-02-18",
                "fpm": "Kim Xxxxxx",
                "asm": "Mike Xxxxxx",
                "fisse": ""
              }
            }
    

    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?

        {
          "data": [
            {
              "pk": "239",
              "fields.friendly_name": "HIE Refresh",
              "fields.assessment_type": "1D_T",
              "fields.assessment_stage": 0,
              "fields.validated_supporting_event": false,
              "fields.need_by_date": "2021-03-03",
              "fields.scheduled_submission_date": "2021-02-18",
              "fields.fpm": "Kim Xxxxxx",
              "fields.asm": "Mike Xxxxxx",
              "fields.fisse": ""
            }
          ]
        }
    

    Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • colincolin Posts: 15,118Questions: 1Answers: 2,583
    Answer ✓

    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

  • stephanbstephanb Posts: 36Questions: 11Answers: 0

    Thanks Colin. The json that finally worked included both the "fields {}" tag as well as the "data {}". I'm all good!

  • stephanbstephanb Posts: 36Questions: 11Answers: 0

    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?

  • colincolin Posts: 15,118Questions: 1Answers: 2,583

    Yep, if you've got submit set to allIfChanged in the form-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

This discussion has been closed.