POST accepts only non-string data, does not populate
POST accepts only non-string data, does not populate
Hi everyone -
I have a curious situation with DT and Editor (latest, 1.3 ish). I am trying to POST data with an Ajax call, but even when using 'preSubmit', all of the string fields are set to "undefined" in the JSON response. When I click to update (and the editor is set to All, and I have tried AllIfChanged as well), that String field is set to the new changes, but the rest of the strings are still undefined. Booleans, integers, etc., all populate correctly.
In AJAX, I have very simply:
function (row) { // pushes the data
if (row.action != "remove") {
var data = {};
$.each(row.data, function (key, value) {
data = { "ID": key, "Name": value.Name , "Description": value.Description }
});
console.log(JSON.stringify(data));
return JSON.stringify(data);
} else {
close();
return false;
}
When I update "Name", for example:
{"ID":"5","Name":"Testing - is returned"}
(in the grand scheme, wherein these are the rest of the columns in the table):
{"5":{"Name":"Testing - is returned,"CostPerEach":"12","PricePerEach":"18","Enabled":"true"}})
When I update "Description":
{"ID":"5","Description":"Name - is -ignored"}
(in the grand scheme, wherein these are the rest of the columns in the table):
{"5":{"Description":"Testing - is returned,"CostPerEach":"12","PricePerEach":"18","Enabled":"true"}})
I have tried setting the data to toString(), as well as $.fn.dataTable.render.text(), to no avail. At the same time, I am also unable to click on the "Save" button (or "Add" button) when using the modal. (Cancel works fine). Therefore, I am using bubble/inline editing (depending on the table). I believe the 2 issues are definitely related.
This is a local installation, by the way.
Answers
Your Ajax function appears to be expecting data in the legacy format, but if you are using Editor 1.5 or newer (1.6.3 is the current release) it will send data in a newer format that supports the multi-row editing feature.
The 1.5 upgrade notes include information about this and also detail how you can tell Editor to use the legacy format if you want that (that option will remain for the 1.x series).
Allan
My apologies, I forgot what release it was, but it was May 2017 release (so 1.6.X for sure), so this is occuring in the more modern release.
This is my preSubmit test:
And data returns:
Even though it's supposed to return:
Please ignore/close this thread, as this had something to do with someone elses code, not datatables.
I suspect you are running into this part of the 1.5 upgrade documents.
Inline and bubble editing will only submit the values which have been changed by default. You need to use the
submit
option for theform-options
object to tell it to submit all parameters (which it looks like you need).You mentioned you tried
AllIfChanged
andAll
- neither are actually valid values. They should beallIfChanged
andall
(since Javascript is case sensitive).Can you show me how you are triggering the editing or configuring those options?
Allan
It turns out, I had to add 'this.submit()' to all of my buttons:
{ label: 'Edit', fn: function () { this.submit(); } },
which fixed pretty much all of my issues.
Fantastic - thanks for the update.
Regards,
Allan