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();

}

2
  • 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.
    – Adil
    Commented Jun 18 at 11:51
  • I edited my code, please inspect rowdata Structure: Ensure rowdata.id exists and is a valid value. @Adil
    – SKJ
    Commented Jul 2 at 13:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.