Articles in this section
Category / Section

How to suppress grid confirmation messages

2 mins read

Problem:

1. Showing confirmation dialog while saving the changes of the current page.

2. Disable the confirmation dialog while navigating to another page and save the changes.

 

Solution: Showing confirmation dialog while saving the changes of the current page.

We can achieve the above requirement by using ShowConfirmDialog property of the grid while using Batch editing feature.

While using batch editing feature of the grid, the ShowConfirmDialog property of the EditSettings is enabled by default and so whenever the changes of the current page get saved it will show the confirmation dialog.

And also while navigating to another page without saving the changes of the current page it will show the confirmation dialog for confirming to save the changes.

Example:

We can enable the Batch editing feature and ShowConfirmDialog property of the grid as follows.

@(Html.EJ().Grid<object>("Grid")

.Datasource((IEnumerable<object>)ViewBag.datasource)

.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.Batch).ShowConfirmDialog(true); })

.AllowPaging()

 .Columns(col =>

        {

            col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();

            col.Field("CustomerID").HeaderText("Customer ID").Width(80).Add();

            col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).Width(75).Add();

            col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Width(75).Format("{0:C}") .Add();

            col.Field("ShipCity").HeaderText("Ship City").Width(110).Add();

            col.Field("ShipName").HeaderText("Ship Name").Width(110).Add();

        }))

)

Result:

(i) While saving edited record details in same page by clicking on the save button in toolbar.

 

(ii) While saving the edited records details when navigating from one page to another.

Solution: Disable the confirmation dialog while navigating to another page and saving the changes.

 

We can prevent the confirmation dialog by set “showConfirmDialog” property of the editSettings as “false” in ActionBegin event of the grid while navigating to another page.

 

Example:

@(Html.EJ().Grid<object>("Grid")

         .Datasource((IEnumerable<object>)ViewBag.datasource)

         

         .ClientSideEvents(eve=>{eve.ActionBegin("begin").ActionComplete("complete");})

 )

<script type="text/javascript">

function begin(args) {

var obj = $("#Grid").data("ejGrid");

if (args.requestType == "paging") {

//Getting edited records details using getBatchChanges method while navigating to another page

temp = obj.getBatchChanges();

$("#Grid").ejGrid("option", {

//set showConfirmDialog property as false

"editSettings": { showConfirmDialog: false }

});

}

}

 

 

In the above code snippet we have usedgetBatchChanges method for getting the changes of the current page and saved the changes in the global variable

We have assigned the changes of previous page to the “batchChanges” property of the grid for saving the changes in ActionComplete event of the grid while navigating to another page.

function complete(args)

{

if (args.requestType == "paging") {

var obj = $("#Grid").data("ejGrid");

//Enable showConfirmationDialog property

$("#Grid").ejGrid("option", { "editSettings": { showConfirmDialog: true } });

//Assigning edited records details(temp) to batchChanges property.

obj.batchChanges = temp;

//Saving edited records using batchSave method

$("#Grid").ejGrid("batchSave");

}}

</script>

 

 

In the above code snippet we have set the showConfirmDialog property of the editSettings as “trueagain for showing the confirmation dialog in the current page while clicking the save button from the toolbar.

Result:

Figure 1: Editing a record

The edited records are saved automatically while navigating from one page to another, without display any confirmation dialog.

Figure 2: Saving an edited record without displaying confirmation message.

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied