|
<ejs-grid id="Grid" dataSource="ViewBag.DataSource" actionBegin="begin" toolbarClick="toolbarClick" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })" >
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="100"></e-grid-column>
</e-grid-columns>
</ejs-grid>
<script>
function begin(args) {
if (args.requestType == "save") {
var grid = document.getElementById("Grid").ej2_instances[0];
var message = "Are you sure to enter "+ args.data.OrderID +" in OrderID and " + args.data.ShipCountry + " in Country"
if (isupdate) {
if (confirm(message)){
//if yes ,data will save
}
else
args.cancel = true // if no the data wount save
}
isupdate = false
}
}
function toolbarClick(args) {
var grid = document.getElementById("Grid").ej2_instances[0];
if (args.item.properties.prefixIcon == "e-update") {
isupdate = true
}
}
</script>
|
|
<ejs-grid id="Grid" dataSource="ViewBag.DataSource" beforeBatchSave="SaveBatch" toolbarClick="toolbarClick" allowGrouping="true">
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Batch" showConfirmDialog="false"></e-grid-editSettings>
...
</ejs-grid>
<script>
function SaveBatch(args) {
var grid = document.getElementById("Grid").ej2_instances[0];
var message = "";
for (var i = 0; i < args.batchChanges.changedRecords.length; i++) {
var message = message +"\n" + "Are you sure to enter " + args.batchChanges.changedRecords[i].OrderID + " in OrderID and " + args.batchChanges.changedRecords[i].ShipCountry + " in Country" +" for the row "+ i
}
if (isupdate) {
if (confirm(message)){
//if yes ,data will save
}
else
args.cancel = true // if no the data wount save
}
isupdate = false
}
function toolbarClick(args) {
var grid = document.getElementById("Grid").ej2_instances[0];
if (args.item.properties.prefixIcon == "e-update") {
isupdate = true
}
}
</script> |
|
<ej-grid id="FlatGrid" allow-paging="true">
<e-datamanager url="/Home/DataSource" batch-url="/Home/BatchUpdate" adaptor="UrlAdaptor" />
<e-columns>
. . .
</e-columns>
</ej-grid>
public ActionResult BatchUpdate([FromBody]submitvalue myObject)
{
if (myObject.Changed != null && myObject.Changed.Count > 0)
{
foreach (var temp in myObject.Changed)
{
var ord = temp;
Order val = orddata.Where(or => or.OrderID == ord.OrderID).FirstOrDefault();
val.OrderID = ord.OrderID;
val.EmployeeID = ord.EmployeeID;
val.CustomerID = ord.CustomerID;
val.Freight = ord.Freight;
val.OrderDate = ord.OrderDate;
val.ShipCity = ord.ShipCity;
}
}
if (myObject.Added != null && myObject.Added.Count > 0)
{
foreach (var temp in myObject.Added)
{
orddata.Insert(0, temp);
}
}
if (myObject.Deleted != null && myObject.Deleted.Count > 0)
{
foreach (var temp in myObject.Deleted)
{
orddata.Remove(orddata.Where(or => or.OrderID == temp.OrderID).FirstOrDefault());
}
}
var data = orddata;
return Json(data);
}
|
Hi Frédéric,
By default, the batch mode of editing shows a confirmation dialog when the update icon in the toolbar is clicked. To show a customized confirmation dialog for the batch mode of editing, just like what we have provided for the normal mode of editing we suggest you to follow the below codes.
<ejs-grid id="Grid" dataSource="ViewBag.DataSource" beforeBatchSave="SaveBatch" toolbarClick="toolbarClick" allowGrouping="true"><e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Batch" showConfirmDialog="false"></e-grid-editSettings>...</ejs-grid><script>function SaveBatch(args) {var grid = document.getElementById("Grid").ej2_instances[0];var message = "";for (var i = 0; i < args.batchChanges.changedRecords.length; i++) {var message = message +"\n" + "Are you sure to enter " + args.batchChanges.changedRecords[i].OrderID + " in OrderID and " + args.batchChanges.changedRecords[i].ShipCountry + " in Country" +" for the row "+ i}if (isupdate) {if (confirm(message)){//if yes ,data will save}elseargs.cancel = true // if no the data wount save}isupdate = false}function toolbarClick(args) {var grid = document.getElementById("Grid").ej2_instances[0];if (args.item.properties.prefixIcon == "e-update") {isupdate = true}}</script>In the above code example, we have disabled the default batch confirmation dialog by setting the “showConfirmDialog” property of Grid as false. Then in the “beforeBatchSave” event of Grid we have opened the confirmation as just like the normal edit confirmation message from our previous update. There is no need to check for request types, as the beforeBatchSave event will be triggered only before a batch save action is performed. Please refer the documentation links below,
Documentations :We have also modified the sample from our previous response, based on your requirement, please download from the link below,
Please get back to us if you need further assistance.
Regards,Renjith Singh Rajendran.
|
<script>
setTimeout(function () {
var confirmDialogObj = document.getElementById('confirm_dialog').ej2_instances[0];
confirmDialogObj.hide(); //hiding at initial time
}, 500)
</script>
<div class=" col-lg-8 control-section" id="target">
<ejs-dialog id="confirm_dialog" open="dialogOpen" close="dialogClose" width="400px"target="#target" visible="false" content="Sure need to be updated?"showCloseIcon="true">
<e-dialog-buttons>
<e-dialog-dialogbutton buttonModel="ViewBag.Okbutton"click="dlgButtonOkClick"></e-dialog-dialogbutton>
<e-dialog-dialogbutton buttonModel="ViewBag.Cancelbutton"click="dlgButtonCancelClick"></e-dialog-dialogbutton>
</e-dialog-buttons>
</ejs-dialog>
</div>
<ejs-grid id="Grid" dataSource="ViewBag.DataSource" height="315" allowPaging="true"beforeBatchSave="SaveBatch" toolbarClick="toolbarClick" toolbar="@(new List<string>() {"Add", "Edit", "Delete", "Update", "Cancel" })" locale="es-AR" allowGrouping="true">
...
</ejs-grid>
<script type="text/javascript">
...
function dlgButtonOkClick() {
var dialogObj = document.getElementById("confirm_dialog")
dialogObj.ej2_instances[0].hide();
//close the dialog.
}
</script>
<script>
function dlgButtonCancelClick(args) {
... //perform cancel operation in grid
}
function SaveBatch(args) {
var grid = document.getElementById("Grid").ej2_instances[0];
var dialog = document.getElementById("confirm_dialog").ej2_instances[0];
document.getElementById("confirm_dialog").style["left"] = "330px";
document.getElementById("confirm_dialog").style["top"] = "210px";
dialog.show(); //showing the dialog while saving the record.
}
</script>
|
|
<ejs-grid id="Grid" dataSource="ViewBag.DataSource" height="315" allowPaging="true" toolbarClick="toolbarClick" >
...
</ejs-grid>
<script>
function toolbarClick(args) {
var grid = document.getElementById("Grid").ej2_instances[0];
...
grid.localeObj.localeStrings.BatchSaveConfirm = message;
}
</script> |