How to add confirmation window for jQuery Kendo Ui Grid through update?

Coda Chang

For Kendo UI, it would give a confirmation window before you delete a record. enter image description here

Is there a way to add it to the update button? and the add record?

Here is an example, it seems hook all the callback already.

<!DOCTYPE html>
<html>
<head>
    <base href="https://demos.telerik.com/kendo-ui/grid/editing-inline">
    <style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
    <title></title>
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2020.2.617/styles/kendo.default-v2.min.css" />

    <script src="https://kendo.cdn.telerik.com/2020.2.617/js/jquery.min.js"></script>
    
    
    <script src="https://kendo.cdn.telerik.com/2020.2.617/js/kendo.all.min.js"></script>
    
    

</head>
<body>
        <div id="example">
            <div id="grid"></div>

            <script>
                $(document).ready(function () {
                    var crudServiceBaseUrl = "https://demos.telerik.com/kendo-ui/service",
                        dataSource = new kendo.data.DataSource({
                            transport: {
                                read:  {
                                    url: crudServiceBaseUrl + "/Products",
                                    dataType: "jsonp"
                                },
                                update: {
                                    url: crudServiceBaseUrl + "/Products/Update",
                                    dataType: "jsonp"
                                },
                                destroy: {
                                    url: crudServiceBaseUrl + "/Products/Destroy",
                                    dataType: "jsonp"
                                },
                                create: {
                                    url: crudServiceBaseUrl + "/Products/Create",
                                    dataType: "jsonp"
                                },
                                parameterMap: function(options, operation) {
                                    if (operation !== "read" && options.models) {
                                        return {models: kendo.stringify(options.models)};
                                    }
                                }
                            },
                            batch: true,
                            pageSize: 20,
                            schema: {
                                model: {
                                    id: "ProductID",
                                    fields: {
                                        ProductID: { editable: false, nullable: true },
                                        ProductName: { validation: { required: true } },
                                        UnitPrice: { type: "number", validation: { required: true, min: 1} },
                                        Discontinued: { type: "boolean" },
                                        UnitsInStock: { type: "number", validation: { min: 0, required: true } }
                                    }
                                }
                            }
                        });

                    $("#grid").kendoGrid({
                        dataSource: dataSource,
                        pageable: true,
                        height: 550,
                        toolbar: ["create"],
                        columns: [
                            "ProductName",
                            { field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: "120px" },
                            { field: "UnitsInStock", title:"Units In Stock", width: "120px" },
                            { field: "Discontinued", width: "120px", editor: customBoolEditor },
                            { command: ["edit", "destroy"], title: "&nbsp;", width: "250px" }],
                        editable: "inline"
                    });
                });

                function customBoolEditor(container, options) {
                    $('<input class="k-checkbox" type="checkbox" name="Discontinued" data-type="boolean" data-bind="checked:Discontinued">').appendTo(container);
                }
            </script>
        </div>


</body>
</html>

Swati

You can do that by using click event of jquery .So , whenever edit button or create new button is clicked then click handler will get called and then you can use confirm(..) box to get response from user .If user select cancel then we can use cancelChanges() to avoid any changes else do required operation.

Demo Code :

$(document).ready(function() {
  var crudServiceBaseUrl = "https://demos.telerik.com/kendo-ui/service",
    dataSource = new kendo.data.DataSource({
      transport: {
        read: {
          url: crudServiceBaseUrl + "/Products",
          dataType: "jsonp"
        },
        update: {
          url: crudServiceBaseUrl + "/Products/Update",
          dataType: "jsonp"
        },
        destroy: {
          url: crudServiceBaseUrl + "/Products/Destroy",
          dataType: "jsonp"
        },
        create: {
          url: crudServiceBaseUrl + "/Products/Create",
          dataType: "jsonp"
        },
        parameterMap: function(options, operation) {
          if (operation !== "read" && options.models) {
            return {
              models: kendo.stringify(options.models)
            };
          }
        }
      },
      batch: true,
      pageSize: 20,
      schema: {
        model: {
          id: "ProductID",
          fields: {
            ProductID: {
              editable: false,
              nullable: true
            },
            ProductName: {
              validation: {
                required: true
              }
            },
            UnitPrice: {
              type: "number",
              validation: {
                required: true,
                min: 1
              }
            },
            Discontinued: {
              type: "boolean"
            },
            UnitsInStock: {
              type: "number",
              validation: {
                min: 0,
                required: true
              }
            }
          }
        }
      }
    });

  $("#grid").kendoGrid({
    dataSource: dataSource,
    pageable: true,
    height: 550,
    toolbar: ["create"],
    columns: [
      "ProductName",
      {
        field: "UnitPrice",
        title: "Unit Price",
        format: "{0:c}",
        width: "120px"
      },
      {
        field: "UnitsInStock",
        title: "Units In Stock",
        width: "120px"
      },
      {
        field: "Discontinued",
        width: "120px",
        editor: customBoolEditor
      },
      {
        command: ["edit", "destroy"],
        title: "&nbsp;",
        width: "250px"
      }
    ],
    editable: "inline"
  });
});

function customBoolEditor(container, options) {
  $('<input class="k-checkbox" type="checkbox" name="Discontinued" data-type="boolean" data-bind="checked:Discontinued">').appendTo(container);
}

//onclick of edit and new recors
$(document).on('click', '.k-grid-edit,.k-grid-add', function() {

  var r = confirm("Are you sure  ?"); //show alert
  //if  user select cancel
  if (r == false) {
    //cancel changes
    $('#grid').data('kendoGrid').dataSource.cancelChanges();
    console.log("Cancel!");
  }
})
html {
  font-size: 14px;
  font-family: Arial, Helvetica, sans-serif;
}
<base href="https://demos.telerik.com/kendo-ui/grid/editing-inline">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2020.2.617/styles/kendo.default-v2.min.css" />
<script src="https://kendo.cdn.telerik.com/2020.2.617/js/jquery.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2020.2.617/js/kendo.all.min.js"></script>
<div id="example">
  <div id="grid"></div>
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Kendo UI jQuery Grid Server Side Filtering

Remove row from Kendo UI Grid with jQuery

Kendo UI grid update

Kendo UI DropDownList - change confirmation

How to update Kendo Grid row from window

How to hide the grid header kendo ui?

Kendo UI for Angular2 - Grid How to Add Columns Dynamically

How to prevent grid popup editor from closing on update and create on kendo ui for angular?

how to add json through mapping material-ui grid component

How to get the value of a checkbox in a Kendo UI Grid?

How to load manually data in kendo ui grid

Kendo UI Web - Grid Create/Update/Delete

How to close kendo window through jquery onsucess on button click

kendo UI grid update function wont fire

Custom Kendo UI Grid Footer - Update Dynamically

How to update and reload the datasource of a Kendo UI MVC grid from clientside upon search

In Kendo UI MVC Grid how do i add a Kendo Upload to each row?

Use of Kendo UI Grid & Window Very high CPU Usage

How to set kendo UI grid width

how to open a confirmation dialog window with Jquery UI through a click in a botton

Kendo UI Grid add link

How to automatically resize Kendo UI grid in a modal window

Kendo UI MVC Grid with Kendo Window - 500 error

How create confirmation popup in kendo UI?

Confirmation delete message kendo grid

How can I widen the popup window in Kendo UI grid?

How to pass Kendo Grid row data to Kendo popup window in a partial view in jQuery?

jquery kendo ui: Grid with custom autocomplete column

How to configure a confirmation window on Kendo UI Wizard?