Table not being updated after correct response

Table not being updated after correct response

hserveirahserveira Posts: 5Questions: 2Answers: 0

I'm facing a strange behavior with DataTables Editor when using custom REST endpoints.
Basically, on the preSubmit event I'm adding data into a 'children' key, which is then processed by a custom logic in the back-end. This is how the payload looks like:

{
    "data": {
        "4760": {
            "Worktime": {
                "FK_Worktime_User_UserID": 16,
                "Date": "2024-11-30",
                "DateType": 1,
                "StartTime": "08:30",
                "LeaveTime": "18:00",
                "Remarks": "",
                "children": {
                    "WorktimeDetail": [
                        {
                            "Amount": 100,
                            "Destination": "B",
                            "FK_WorktimeDetail_Worktime_WorktimeID": 4760,
                            "Origin": "A",
                            "PK_WorktimeDetailID": 8641,
                            "Type": "Car"
                        },
                        {
                            "PK_WorktimeDetailID": 8642,
                            "FK_WorktimeDetail_Worktime_WorktimeID": "",
                            "Origin": "B",
                            "Destination": "A",
                            "Amount": "100",
                            "Type": "Car"
                        }
                    ]
                }
            }
        }
    },
    "action": "edit"
}

It works, the inserts/updates are performed, and a response is returned in the format required. When ADDING or UPDATING data on the children, the results are reflected on the table. But, let's say, if I were to remove one of the records, the changes are not reflected. This is the response from the server when deleting one of the records:

{
  "data": [
    {
      "DT_RowId": 4760,
      "Worktime": {
        "Date": "2024-11-30",
        "DateType": 1,
        "FK_Worktime_User_UserID": 16,
        "LeaveTime": "18:00",
        "PK_WorktimeID": 4760,
        "Remarks": "",
        "StartTime": "08:30",
        "WorktimeDetail": [
          {
            "Amount": 100.0,
            "DT_RowId": 8641,
            "Destination": "B",
            "FK_WorktimeDetail_Worktime_WorktimeID": 4760,
            "Origin": "A",
            "PK_WorktimeDetailID": 8641,
            "Type": "Car"
          }
        ]
      }
    }
  ]
}

The changes are not reflected on the table unless I perform table.ajax.reload().

For reference, this is the table field:

                    {
                        data: 'Worktime.WorktimeDetail',
                        title: 'Expenses',                        
                        className: 'dt-center dt-head-center dt-body-center expensesDisplay',
                        render: function(data, type, row) {
                            // Render WorktimeDetail.Origin > WorktimeDetail.Destination: WorktimeDetail.Amount
                            if (Array.isArray(data) && data.length > 0 && type === 'display') {
                                return data.map(item => item.Origin + ' > ' + item.Destination + ': ' + $.fn.dataTable.render.number(',', '.', 2, '¥ ').display(item.Amount)).join('<br>');
                            } else {
                                return '';
                            }
                        },
                        orderable: false
                    },

I can provide a link and login details via DM if needed.
I appreciate any insight on this!

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,483Questions: 26Answers: 4,978

    The delete response is incorrect. According to the Editor client/server data docs the response should be an empty object { }.

    Kevin

  • hserveirahserveira Posts: 5Questions: 2Answers: 0

    Actually I'm only "deleting" from the children table.
    Technically it's an update on the parent row, which brings the updated data for the children as well.

    The response returns data for the entire row, with the updated data for the children. The weird thing is that on update and inserts this works, and only doesn't work when rows from the children table are removed

  • kthorngrenkthorngren Posts: 21,483Questions: 26Answers: 4,978

    I'm not sure what the problem would be then. You can PM the test case connection info to @allan using the Ask a Private Question button at the top right of this page.

    Kevin

  • hserveirahserveira Posts: 5Questions: 2Answers: 0

    I don't see the button, I assume it requires support credits?

  • kthorngrenkthorngren Posts: 21,483Questions: 26Answers: 4,978
    edited November 30

    No it doesn't require support. You aren't the first to mention not seeing the button. Click on Allan's name in my previous post to send him a message by clicking the message button. Don't add a comment to the Activity section as I believe that is publicly available to everyone.

    Kevin

  • allanallan Posts: 63,700Questions: 1Answers: 10,501 Site admin
    Answer ✓

    Long story short, it is a bug deep in the guts of Editor. I've committed a fix that will be included in 2.4.0 (which isn't too far away). There is also a workaround using preEdit in which you empty out the old array and allow the new one to fully take its place.

    Regarding the "Ask a Private Question" button - I think that only appears if you have purchased priority support at some point in the past.

    Allan

Sign In or Register to comment.