Is it possible to compare values of a row/column before/after saving to database?

Is it possible to compare values of a row/column before/after saving to database?

pansengtatpansengtat Posts: 66Questions: 26Answers: 1

Hi,

I received an update to an existing feature request on using Datatables/Editor, where instead of triggering a presubmit event all the time whenever Editor makes changes to the selected row/entry, the presubmit event should be triggered only when there is a difference in value(s) of the selected entry between the original value and the current value (to be written to the database). How do I detect such a difference - is there a way to read the old value during presubmit and intercept only when it can read both new and old values, and then code accordingly?

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Currently there is no option for this in Editor, although it is on the feature roadmap and will appear in a future version.

    At the moment what you would need to do is take a copy of the data in the initEdit event (same for create) and then compare the values in the preSubmit to see if there is a difference.

    Allan

  • pansengtatpansengtat Posts: 66Questions: 26Answers: 1
    edited September 2014

    Here is what I might do using @allan's answer to implement such a comparison.
    All code are within the same JS file within the $(document).ready(function() {}) block:

    Event initEdit check:

    editor.on('initEdit', function(e,node,data) {
        tr_status_init = editor.field( 'RequestMain.Status' ).val();
        //--- Get the  data of column of the row selected ---//
    } );
    

    Event preSubmit check:

    editor.on('preSubmit', function(e,obj,action){
    ...
        var tr_status_after = obj.data.RequestMain.Status;
    ...
        if (tr_status_init != tr_status_after )
        {
            //--- Perform necessary functions here. ---//
        }
    });
    
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Thanks for posting back with your solution!

    Allan

This discussion has been closed.