Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82756

Appears that I cannot update json object in editor postSubmit event

$
0
0

I am trying to use the postSubmit event with Editor v1.9.6 after a create REST call. My test Editor code is below.

propertiesEditor = new $.fn.dataTable.Editor( {
            ajax: {
            create: {
                type: 'POST',
                url:  'property',
                contentType: "application/json; charset=utf-8",
                data: function ( d ) {
                    return JSON.stringify( d['data'][Object.keys(d['data'])[0]] );
                },
                "dataSrc": ""
            },
            edit: {
                type: 'PUT',
                url:  'property/_id_',
                contentType: "application/json; charset=utf-8",
                data: function ( d ) {
                    return JSON.stringify( d['data'][Object.keys(d['data'])[0]] );
                }
            },
            remove: {
                type: 'DELETE',
                url:  'property/_id_'
            }
        },
            table: "#example2",
            "idSrc": "id",
            fields: [ {
                    label: "Name:",
                    name: "name"
                }, {
                    label: "Value:",
                    name: "value"
                }, {
                    label: "Status:",
                    name: "status"
                }
            ],
            formOptions: {
                main: {
                    scope: 'cell' // Allow multi-row editing with cell selection
                }
            }
        } );

propertiesEditor.on('postSubmit', function( e, json, data, action ) {
        console.log("Beginning: " + JSON.stringify(json));
        json = "junk";
        console.log("End: " + JSON.stringify(json));
});

The output from the console is the following.
Beginning: {"data":[{"id":3,"status":1,"name":"test","value":"test"}]}
End: "junk"

In this case the Editor considers the response a success and lets the table update. Wouldn't the update of the json variable cause editor to fail the response since the json variable is no longer in the format required by editor? Maybe I am understanding the documentation incorrectly.

In the future I would like to use the postSubmit event to manipulate the response from existing REST services to match the required Editor response format.

Thanks,
Kyle


Viewing all articles
Browse latest Browse all 82756

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>