Database update, but rows do not refresh on submit

Database update, but rows do not refresh on submit

camgracamgra Posts: 3Questions: 2Answers: 0
edited September 2016 in Free community support

I have a data sourced from an MSSQL database being sent/received via a WCF service. I have been able to GET the data from the service, and can send an object to the service via a PUT action. This PUT action does update the SQL database, but the data on the datatable is not refreshing.
I know the return data needs to be in a specific format, so I attempted to match this on the service. This is the response payload coming back from the service.

{
    "data":
        [
            {
                "AccessDB":"GL",
                "AccessType":"DEPARTMENT",
                "CostCenter":"107110012",
                "CostCenterOwner":"JOE SHALBOTNIK",
                "Department":"FINANCE",
                "Initials":"BROSAL",
                "MagicKey":null,
                "Manager":"BROCHA",
                "Menu":"IT Menu",
                "Position":"COORDINATOR",
                "Status":3,
                "User":null,
                "Changer":"CAMGRA",
                "CreatedBy":null,
                "CreatedDate":"2016-09-01T14:23:02.31",
                "Id":8,
                "IsActive":null,
                "ModifiedBy":"CAMGRA",
                "ModifiedDate":"2016-09-02T12:40:33.8"
            }
        ],
    "error":null,
    "fieldErrors":null
}

I've also adjusted the editor ajax function so that works properly when sending the data:

var editor = new $.fn.dataTable.Editor({
            ajax: {
                create: {
                    type: 'POST',
                    url: 'api/UserStatusData',
                    data: function (d) {
                        return JSON.stringify(d);
                    }
                },
                edit: {
                    type: 'PUT',
                    url: 'api/UserStatusData',

                    data:
                        function (d) {
                            d.data.Changer = 'CAMGRA';
                            return JSON.parse(JSON.stringify(d))

                        }
                    
                }
            },

            legacyAjax: true,
            table: '#UserStatus',
            idSrc: 'Id',
            Fields: <removed>
        });

I do have full control over the service, so if I need to modify the existing object, I can do that as well.
It is not producing an error when it receives the data, but it also does not refresh. If I manually refresh the data, the changes are noticeable.

So, my question is, what is missing from the payload that is preventing it from updating the table, or is there another problem that I am missing.

Many thanks

Edit: I added in some trap code to see what the server was returning from the server to the client. using the "postSubmit" call, I was able to see that the json value coming from the server is empty, although I can see the payload (updated above to include the error and fieldErrors) has data in it... So the js for DataTables appear to not be picking it up.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,815Questions: 1Answers: 10,517 Site admin
    Answer ✓

    I think the issue is that the data being returned is in the new format, but you have the legacyAjax option enabled. The legacy format has a different return structure.

    The key difference is that data would become row and it would just be the object with the row's data, not an array (since the legacy format only supports single row editing).

    Allan

  • camgracamgra Posts: 3Questions: 2Answers: 0

    Thanks Allan, you are absolutely correct. I changed the data output on the c# from an array to a straight object and returned it as "row" instead of "data".

This discussion has been closed.