Limit data() to changed cells only in preSubmit event

Limit data() to changed cells only in preSubmit event

Karl_SKarl_S Posts: 20Questions: 6Answers: 0

In the preSubmit event, is there a way to have the data() returned show only the changed data and not the entire row(s)? I tried the submit option of the form-options object but that doesn't seem to limit the row().data() to only change the values in the preSubmit event. I know I can get the row's values prior to edit and then compare them in the preSubmit but if something is available to do this then I would rather use what is available. And since I am using this with Google Apps Script I am grabbing and submitting the edits in the preSubmit event.

Regards,
Karl S

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Hi @Karl_S ,

    The formOptions submit property may help here - you can determine what to send based on what's changed. This example here shows that with inline(),

    Hope that helps,

    Cheers,

    Colin

  • Karl_SKarl_S Posts: 20Questions: 6Answers: 0

    I guess I am not seeing the data that would be submitted as opposed to thew entire row of data. I have this and data() is showing me the entire row(s) information.

      myEditor[assignmentsTableID] = new $.fn.dataTable.Editor( {
        'table': jq_tableID,
        'fields': [
            { label: 'Name', name: 'name', multiEditable: false },
            { label: 'Email', name: 'email', multiEditable: false },
            { label: 'Reg Type',  name: 'type', multiEditable: false  },
            { label: 'Position',
              name: 'workStudyPosition',
              placeholder: '',
              multiEditable: true,
              multiple: true,
              separator: ',',
              type:'select',
              options: positions,
              submit: 'changed'
            }
        ]
      } );
    
        $(jq_tableID).on('click', 'a.editor_edit', function (e) {
            e.preventDefault();
    
            myEditor[assignmentsTableID].edit( $(this).closest('tr'), {
                title: 'Edit record',
                buttons: 'Update',
                submit: 'changed'
            } );
        } );
    
            myEditor[assignmentsTableID].on('preSubmit', function (e, json, data) {
                var modifier = myEditor[assignmentsTableID].modifier();
                console.log('in preSubmit');
                console.log('modifier');
                console.log(modifier);
                console.log('data');
                console.log(data);
    
                if ( modifier ) {
                  var table = $(jq_tableID).DataTable();
                  var row = table
                    .rows( modifier )
                    .nodes();
                }
            }
          );
    
  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin
    Answer ✓

    What you are looking for isn't something that Editor provides directly I'm afraid. row().data() will always get the original data object for the row - i.e. the whole thing.

    The best way to do what you want is to use row().data() in both preEdit and postEdit and then do a diff between the objects (Lodash for example provides a method to do that, or use a small custom function). That would account for any changes to the data that the server-side has made.

    The alternative is to use the data object (third parameter) passed into postEdit to find the data for the row that was submitted to the server. If you have submit: 'changed' then it will only contain the changed values.

    Allan

  • Karl_SKarl_S Posts: 20Questions: 6Answers: 0

    Thank you, Allan. I managed to get the things configured to have the form return only the changed values in the postEdit. This is actually exactly what I was looking for. I was just going about it the wrong way. Thank you for recognizing that possibility and getting me back on track!

    Karl S

This discussion has been closed.