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