ListGrid row edit confirmation

In my ListGrid, I would like the user to be able to edit a few cells in one row, and when editing is complete (navigate away, escape, enter, or tab to next row), a confirmation dialog pops up to save or cancel changes.

Here is what I have so far (based on the Modal Editing example):

isc.ListGrid.create({
    ID: "countryList",
    width:550, 
    height:224, 
    alternateRecordStyles:true, 
    showAllRecords:true, 
    cellHeight:22,
    dataSource: countryDS,
    fields:[
        {name:"countryCode", title:"Flag", width:40, 
            type:"image", imageURLPrefix:"flags/16/", 
            imageURLSuffix:".png", canEdit:false},
        {name:"countryName"},
        {name:"continent"},
        {name:"member_g8"},
        {name:"population", formatCellValue:"isc.Format.toUSString(value);"},
        {name:"independence"}
    ],
    canReorderFields: true,
    autoFetchData:true,
    canEdit: true,
    editEvent: "doubleClick",
    modalEditing: true,
    waitForSave: true,
    rowEndEditAction: "done",
    confirmCancelEditing: true, //--default = false
    autoSaveEdits: false, //--default = true
    rowEditorExit: function () {
            return isc.confirm("Save changes?");
        }
})

Obviously, I’m not implementing rowEditorExit properly. Where to go next? Add a callback function to isc.confirm to save edits?

I could not get the dialog pop-up to do the trick, so I changed tactics to “Save” and “Cancel” buttons below the ListGrid. This works rather nicely, unless someone sees a hole.

Again, this example uses the “Modal Editing” example from Feature Explorer/Grids/Editing at
http://www.smartclient.com/docs/6.5.1/a/system/reference/SmartClient_Explorer.html#modalEditing
so if you want to see it just copy code into JS tab

Basically, the jist is - once you enter edit mode, you can’t do anything else until you save or cancel. Our users don’t do a lot of edits, and didn’t want the ability to make changes to a record and “accidentally” click outside the row and lose or automatically save changes.

I suppose I should be able to implement the same mechanism with a pop-up dialog. Maybe I’ll try that next.

isc.ListGrid.create({
    ID: "countryList",
    width:550, 
    height:224, 
    alternateRecordStyles:true, 
    showAllRecords:true, 
    cellHeight:22,
    dataSource: countryDS,
    fields:[
        {name:"countryCode", title:"Flag", width:40, 
            type:"image", imageURLPrefix:"flags/16/", 
            imageURLSuffix:".png", canEdit:false},
        {name:"countryName"},
        {name:"continent"},
        {name:"member_g8"},
        {name:"population", formatCellValue:"isc.Format.toUSString(value);"},
        {name:"independence"}
    ],
    canReorderFields: true,
    autoFetchData: true,
    canEdit: true,
    editEvent: "doubleClick",
    modalEditing: true,
    rowEndEditAction: "done",
    autoSaveEdits: false,
    editorEnter: function (record, value, rowNum, colNum) {
            saveButton.enable();
            discardButton.enable();
        },
    rowEditorExit: function (editCompletionEvent, record, newValues, rowNum) {
            if(editCompletionEvent == 'programmatic') {
                saveButton.disable();
                discardButton.disable();
                return true;
            }
            return false;
        }
});
isc.IButton.create({
    ID: "saveButton",
    width: 60,
    left: 10,
    top: 240,
    showRollOver: true,
    showDisabled: true,
    showDown: true,
    title: "Save",
    click: function() {
            countryList.saveAllEdits();
            countryList.endEditing();
        },
});
saveButton.disable();
isc.IButton.create({
    ID: "discardButton",
    width: 60,
    left: 75,
    top: 240,
    showRollOver: true,
    showDisabled: true,
    showDown: true,
    title: "Cancel",
    click: function() {
            countryList.discardAllEdits();
            countryList.endEditing();
        },
});
discardButton.disable();

Ok I finally got a pop-up to work, so to finish this post, here it is:

isc.ListGrid.create({
    ID: "countryList",
    width:550, height:224, alternateRecordStyles:true, showAllRecords:true, cellHeight:22,
    dataSource: countryDS,
    fields:[
        {name:"countryCode", title:"Flag", width:40, type:"image", imageURLPrefix:"flags/16/", imageURLSuffix:".png", canEdit:false},
        {name:"countryName"},
        {name:"continent"},
        {name:"member_g8"},
        {name:"population", formatCellValue:"isc.Format.toUSString(value);"},
        {name:"independence"}
    ],
    canReorderFields: true,
    autoFetchData: true,
    canEdit: true,
    editEvent: "doubleClick",
    modalEditing: true,
    rowEndEditAction: "done",
    autoSaveEdits: false,
    rowEditorExit: function (editCompletionEvent, record, newValues, rowNum) {
            if(editCompletionEvent == 'programmatic') {
                return true;
            }
            isc.confirm("Save changes?", 
                function(value){
                    if(value) {
                        countryList.saveAllEdits();
                        countryList.endEditing();
                    }
                    else {
                        countryList.discardAllEdits();
                        countryList.endEditing();
                    }
            });
            return false;
        }
});

Thanks for posting that - that example will probably help others.