Inline Editor sometimes adds new row to table instead of updating
Inline Editor sometimes adds new row to table instead of updating
I'm using inline editing with version 1.5.5, and using custom ajax to post the updates.
This works perfectly most of the time. However, occasionally (around 1/10th of the time), instead updating the row after a successful post, it creates a new row in the table, just below the one I'm updating.
What can I do to prevent this new row from being added and instead always correctly update the row being edited?
Here's the code that's doing the post:
ajax: function (method, url, data, onSuccess, onError) {
$.ajax({
'type': 'POST',
'contentType': 'application/json; charset=utf-8',
'url': "api/mywebservice",
'data': JSON.stringify({ ...my custom data...}),
'dataType': 'json',
'dataSrc': '',
'cache': false,
success: function (json) {
onSuccess(json);
},
error: function (xhr, error, thrown) {
alert("error!");
onError(xhr, error, thrown);
}
});
}
This question has an accepted answers - jump to answer
Answers
What is the code behind
api/mywebservice
? Are you using the DataTables.dll (or PHP libraries, but I suspect its .NET from the above)?My suspicion is that the web service, whatever it is, is not correctly seeing the edited data and therefore adding a new row. Perhaps it isn't matching on the submitted id?
Allan
Allan,
Thanks, thanks for the reply. It is a .net web service (web api). I'm not using any of the libraries provided for the server side stuff.
What would be scenarios where the data would cause the table to create a new row instead of updating? You mentioned the ID coming back differently, which I'll look into, but are there any other cases where this could happen?
I would suggest you start by looking at the data being submitted to the server. See if there is any different between when the edit completes successfully and when a new row is incorrectly created.
My initial thoughts are that the server doesn't find the original row based on the submitted id for whatever reason (moved, deleted, error) and thus things the old row doesn't exist and creates a new one - but that's a function of the server-side script you are using.
Allan