Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    How to cancel a ListGrid cell edit?

    Using SC 8.2

    My question is regarding how to prevent an update post to the server from a cell whose contents are null or the empty string.

    Details:

    I've got a ListGrid with some columns that are editable. The user can type strings into cells in these columns. The behavior presently is that when a user single-clicks in a cell, it becomes editable. When the user clicks elsewhere, the editable cell's contents get posted to the server.

    What I've noticed happening is that a lot of empty strings get posted. I want to eliminate these spurious requests to the server.

    Things I've tried:

    ListGridField editorExit() function - I tried returning false from this method when the value was null or empty, but the cell never reverted out of editing mode.

    ListGridField editorExit() with grid.cancelEditing() - I tried this as well, and blew up the browser with a recursion problem.

    Please advise on how to best solve this problem. Thanks.

    #2
    I was able to get this to work with the following:

    Code:
    editorExit: function(editCompletionEvent, record, newValue, rowNum, colNum, grid) {
        if (editCompletionEvent == "enter" && ! newValue) {
            grid.discardEdits(rowNum, colNum);
        }
        return true;
    }
    If I'm recalling correctly the infinite loop was due to grid.cancelEditing() resulting in another call to editorExit with editCompletionEvent == "programmatic". The test for == "enter" avoids that.

    Although the above is working, I'd think it better to specify a Validator with type 'required'. That seems cleaner, and would be enforced serve-side as well. Starting from the ListGrid I'm not seeing an obvious place to override the "onError" behavior to discardEdits rather than showErrorIcons/Text. Is this possible, and if so what API would I use?

    Thanks,

    Ian

    Comment

    Working...
    X