POST accepts only non-string data, does not populate

POST accepts only non-string data, does not populate

fcssbanasfcssbanas Posts: 8Questions: 3Answers: 0

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

  • allanallan Posts: 63,893Questions: 1Answers: 10,530 Site admin

    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

  • fcssbanasfcssbanas Posts: 8Questions: 3Answers: 0
    edited May 2017

    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:

        editor.on('preSubmit', function (e, data, action) { 
          console.log("data: ", data);
         }
    

    And data returns:

        {"5":{"Name":"Test - this one","CostPerEach":"12","PricePerEach":"18","Enabled":"true"}}
    

    Even though it's supposed to return:

         {"5":{"ID":"35","Name":"Test - this one","Description": "content here","PartNo:" "35", "Taxable": "1","CostPerEach":"12","PricePerEach":"18","Enabled":"true"}}
    
  • fcssbanasfcssbanas Posts: 8Questions: 3Answers: 0

    Please ignore/close this thread, as this had something to do with someone elses code, not datatables. :)

  • allanallan Posts: 63,893Questions: 1Answers: 10,530 Site admin

    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 the form-options object to tell it to submit all parameters (which it looks like you need).

    You mentioned you tried AllIfChanged and All - neither are actually valid values. They should be allIfChanged and all (since Javascript is case sensitive).

    Can you show me how you are triggering the editing or configuring those options?

    Allan

  • fcssbanasfcssbanas Posts: 8Questions: 3Answers: 0

    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.

  • allanallan Posts: 63,893Questions: 1Answers: 10,530 Site admin

    Fantastic - thanks for the update.

    Regards,
    Allan

This discussion has been closed.