Results 1 to 2 of 2

Thread: Simulating a cancelEdit event on a grid

  1. #1

    Default Simulating a cancelEdit event on a grid

    Here's my use case:

    I have an Add button that creates a new row in a grid with the first field in edit mode.

    If the user hits 'Escape' and cancels the edit, I'd like to remove the blank row. There's no cancelEdit event on the EditorGrid, so I did this:

    Code:
    	    function addNew()
    	    {
    		detailStore.insert(0, detailReader.readRecords([{'id': '', 'desc': ''}]).records);
    		detailGrid.getView().focusCell(0, 1);
    		detailGrid.startEditing(0, 1);
    	    }
    
    	    // Used to catch edit cancels when adding a row
    	    function cancelAdd(o)
    	    {
    		if (!o.record.dirty)
    		{
    		    // Remove the record that was being edited, because they didn't actually
    		    // enter anything.
    		    detailStore.remove(o.record);
    		}
    	    }
    
    	    detailGrid.on('beforeedit', function(o) {
    		// Hook the hide on the editor to know if it gets cancelled.
                    var ed = detailGrid.colModel.getCellEditor(1, 0);
                    // The delay is necessary because removing a row in the midst of a cancel
                    // causes errors.
                    ed.on("hide", cancelAdd, this, {single: true, delay: 100});
    	    });
    So here are the questions: is there a better way to do this? And are there plans to add a cancelEdit event in the future?

    Hooking the hide event seems like a hack...

    Regards,
    -scott

  2. #2
    Sencha User
    Join Date
    Apr 2012
    Location
    Austin, Texas
    Posts
    4

    Default

    Added Editor canceledit event in SVN.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •