3.2.0

Accessing Old Value


Hi,

What is the best way to revert a cell back to the original value in onCellValidated()?

I use onCellValidating() to ensure the cell value is decimal. Then, I use onCellValidated() to push the value out to the db. Obviously, for whatever reason, there may be an error on the server side. (I simplistically push back "SUCCESS" or "FAIL". No large XML returned.)

On fail, I want to revert (the js array and the grid) to the old value. How do people do this?

Basically, I have:

myGrid.onCellValidating = function(text, column, row) {
   if ( !isDecimal( text, false ) ) {
      alert( 'ERROR: Value is not decimal. Please correct value or hit <ESC> to cancel.' );
      return 1;
   }
   oldValue = myData[row][column]; 
}
                    
myGrid.onCellValidated = function(text, column, row) {
   var r = new AW.HTTP.Request;
   r.setURL("editCommissionDefaultSingle.asp");
   r.setRequestMethod("POST");
   r.setParameter("SID", myData[row][0] );
   r.setParameter("GID", myGID);
   r.setParameter("FC" , myHeaders[column] );
   r.setParameter("DP" , text );
   r.request();
   r.response = function( data ) {
      if ( data != "SUCCESS" ) {
         // restore old value
      }
   }
}
Paul Tiseo
April 14,
Okay, so I guess I solve my problem again! :) Here's the approach I used. If anyone reading this knows of a better way, please reply.

var oldValue;

// store original value to be able to restore
myGrid.onCellEditStarting = function(text, column, row) {
    oldValue = myData[row][column]; // signifies a "cancel edit" for this event handler; value will revert
}

// allow edit to "stick" only if user types in a decimal number
myGrid.onCellValidating = function(text, column, row) {
    if ( !isDecimal( text, false ) ) {
        alert( 'ERROR: Value is not decimal. Please correct value or hit <ESC> to cancel.' );
        return 1; // signifies
    }
}

// when validated, call page to push edited value
myGrid.onCellValidated = function(text, column, row) {
    var r = new AW.HTTP.Request;
    r.setURL("editCommissionDefaultSingle.asp");
    r.setRequestMethod("POST");
    r.setParameter("SID", myData[row][0] );
    r.setParameter("GID", myGID);
    r.setParameter("FC" , myHeaders[column] );
    r.setParameter("DP" , text );
    r.request();
    r.response = function( data ) {
        if ( data != "SUCCESS" ) {
            // restore old value if page doing update signals error
            alert( data );
            myData[row][column] = oldValue;
            myGrid.refresh();
        }
    }
}
Paul Tiseo
April 17,
Paul,

currently there is no built-in functions to achive the same, so your solution looks good to me. Just maybe small improvement, refresh single cell -

myGrid.getCellTemplate(column, row).refresh();

instead of the whole grid control -

myGrid.refresh();
Alex (ActiveWidgets)
April 17,
Thanks for the suggestion, Alex. An oversight on my part. I'm also glad I could contribute a little bit; I have received a lot of help already.
Paul Tiseo
April 17,

This topic is archived.

See also:


Back to support forum