0

I have a jsp file. I need to add confirm dialog box when user clicks on delete button

currently script has simple confirm, but i want kendo ui confirm box. I am not sure how confirm box is in jsp file.

function deleteRow(rowdata) {
if(confirm("Are you sure want to delete this record ?")){
        if(finalRowval){
            $.ajax({
                type : 'DELETE',
                url : "${pageContext.request.contextPath}/mvc/abc" + finalRowval.id + "/xyz",
                dataType : 'text/html',
                data : "",
                async : true,
            });
        }
    }
}

1 Answer 1

0

You need to modify your deleteRow function to use Kendo UI Dialog.

Edit : improved debug version of the deleteRow function

function deleteRow(rowdata) {
// Create a Kendo UI Dialog
$("<div></div>").kendoDialog({
    width: "450px",
    title: "Confirm",
    closable: false,
    modal: true,
    content: "<p>Are you sure you want to delete this record?</p>",
    actions: [
        { text: 'Cancel' },
        { 
            text: 'Delete', 
            primary: true, 
            action: function(e) {
                // Log rowdata to debug
                console.log("rowdata:", rowdata);
                if (rowdata) {
                    $.ajax({
                        type: 'DELETE',
                        url: "${pageContext.request.contextPath}/mvc/abc/" + rowdata.id + "/xyz",
                        dataType: 'html',
                        success: function(response) {
                            // Handle success response
                            console.log("Record deleted successfully.");
                            // Possibly refresh the table or remove the row from the DOM
                        },
                        error: function(xhr, status, error) {
                            // Handle error response
                            console.error("Error deleting record:", error);
                            alert("Failed to delete the record. Please try again.");
                        }
                    });
                } else {
                    console.error("Invalid rowdata:", rowdata);
                }
            }
        }
    ]
}).data("kendoDialog").open();

}

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the reply. I am getting this error. TypeError: name.toLowerCase is not a function at Object.eval [as action] (eval at compile (kendo.js?5.0.9:298:22), <anonymous>:3:159) I am not using any name.toLowerCase anywhere.
I edited my code, please inspect rowdata Structure: Ensure rowdata.id exists and is a valid value. @Adil

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.