Ticket T677557
Visible to All Users

DataGrid popup editing - cancel confirm

created 6 years ago

I use popup editing to create/update the rows in the datagrid and I want to ask a confirmation if the user closes the popup (using the close button or the cancel buttom) when some field has changed.
I subscribed to the editorOptions.onValueChanged event to update my isDirty flag and I subscribed to onRowInserting ad onRowUpdating to clear the isDirty flag and allow the popup to close without confirmation.
My problem is that I'm using the onPopupHiding event to ask the confirmation, because I couldn't find any suitable event in Datagrid or Form and I'm afraid it gets fired too late.

In most cases it works, but there is a situation which I can't solve: if I open a popup, change some fields, cancel, answer No to keep the popup open I loose all the changes. They are still visible on the screen, but they're gone from the form data: if I click save the onRowUpdating/onRowInserting event is not raised and no change is recorded in the datagrid and if I change another field and click save, this will be the only one updated; the changes made before Canceling are gone.

Is there any other event that I can use instead of onPopupHiding to keep the changes? Is there a way to subscribe to the click event of the Cancel button and the Close button of the Popup?

function onEditorPreparing(e) {
    if (e.parentType === "dataRow") {
        if (e.dataField === "MessageBody") {
            e.editorName = "dxTextArea";
        }
        e.editorOptions.onInitialized = function (args) {
            editors[e.dataField] = args.component;
        };
        e.editorOptions.onValueChanged = function (args) {
            isDirty = true;
            e.setValue(args.value);
        };
    }
}

function onRowInserting(e) {
    isDirty = false;
}
function onRowUpdating(e) {
    isDirty = false;
}
function onPopupHiding(e) {
    if (isDirty && confirm("Vuoi abbandonare le modifiche?") === false)
        e.cancel = true;
}

Thanks

Stefano

Comments (1)
Alisher (DevExpress Support) 6 years ago

    Hello Stefano,

    The cause of the issue is unclear to me. I suggest that you check the dxDataGrid - How to customize buttons in the Popup Edit Form ticket where Nikolai demonstrated the approach of how to handle the popup form's Cancel and Save buttons. I believe that this approach is easier to implement. If it is not suitable for your task, please prepare a simple project illustrating the problem so that we can give it a closer look. We will do our best to find an appropriate solution for you.

    Thanks,
    Alisher

    Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

    Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.