Hi,
I am working with EJ1 syncfusion grid, with edit dialog
template. Everything works fine..but.. ☹
Since my dialog is large, have a lot of data to save, we
noticed that some of the users, during controller create execution , when DB response is slow, click
second time SAVE button on the dialog. In that case we got two same records in
the table.
Is that any way to prevent users to click more than once on
the add dialog?
Thanks in advance.
|
@(Html.EJ().Grid<object>("GridTarget")
.Datasource(ds => ds.URL("/Grid/UrlDataSource").UpdateURL("/Grid/UrlUpdate").InsertURL("/Grid/UrlInsert").RemoveURL("/Grid/UrlDelete")
.Adaptor(AdaptorType.UrlAdaptor))
.ClientSideEvents(Event=> Event.ActionComplete("actionComplete").ActionBegin("actionBegin"))
.EditSettings(edit =>
{
edit.AllowAdding();
edit.AllowEditing();
edit.AllowDeleting();
edit.AllowEditOnDblClick(false);
edit.ShowDeleteConfirmDialog(true);
edit.EditMode(Syncfusion.JavaScript.EditMode.DialogTemplate).DialogEditorTemplateID("#targetDialog");
})
.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();
. . .
})
)
<script>
function actionComplete(args) {
if (args.requestType == "save") {
$("#EditDialog_GridTarget_Save").ejButton("enable"); //enable the save button
}
}
function actionBegin(args) {
if (args.requestType == "save") {
$("#EditDialog_GridTarget_Save").ejButton("disable"); //disable the save button ---use EditDialog_GridID here
}
}
</script>
|
|
@(Html.EJ().Grid<object>("GridTarget")
.Datasource(ds => ds.URL("/Grid/UrlDataSource").UpdateURL("/Grid/UrlUpdate").InsertURL("/Grid/UrlInsert").RemoveURL("/Grid/UrlDelete")
.Adaptor(AdaptorType.UrlAdaptor))
.ClientSideEvents(Event=> Event.ActionComplete("actionComplete").ActionBegin("actionBegin").ActionFailure("failure"))
.Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();
. . .
})
)
<script>
function failure(args) {
if (args.requestType == "save") {
$("#EditDialog_GridTarget_Save").ejButton("enable"); //enable the save button use EditDialog plus GridID here
}
}
</script> |
|
GridFeatures.cshtml
@(Html.EJ().Grid<object>("GridTarget")
.Datasource(ds => ds.URL("/Grid/UrlDataSource").UpdateURL("/Grid/UrlUpdate").InsertURL("/Grid/UrlInsert").RemoveURL("/Grid/UrlDelete")
.Adaptor(AdaptorType.UrlAdaptor))
.ClientSideEvents(Event=> Event.ActionComplete("actionComplete").ActionBegin("actionBegin").ActionFailure("failure"))
edit.EditMode(Syncfusion.JavaScript.EditMode.DialogTemplate).DialogEditorTemplateID("#targetDialog");
.Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();
. . .
})
)
Serverside:-
GridController.cs
public ActionResult UrlUpdate(Orders value)
{
if (!ModelState.IsValid) //if validation got failed
{
var message = string.Join(" | ", ModelState.Values
.SelectMany(v => v.Errors)
.Select(e => e.ErrorMessage));
return new HttpStatusCodeResult(HttpStatusCode.BadRequest, message);//message returns the exception content
}
var ord = value;
Orders val = order.Where(or => or.OrderID == ord.OrderID).FirstOrDefault();
. . .
return Json(value, JsonRequestBehavior.AllowGet);
}
public ActionResult UrlInsert(Orders value)
{
if (!ModelState.IsValid) //if validation got failed
{
var message = string.Join(" | ", ModelState.Values
.SelectMany(v => v.Errors)
.Select(e => e.ErrorMessage));
return new HttpStatusCodeResult(HttpStatusCode.BadRequest, message);//message returns the exception content
}
order.Insert(0, value);
string msg = "Successfully performed editing the record";
return Json(new { value = value, message = msg });
}
[Serializable]
public class Orders
{
public long OrderID { get; set; }
[MinLength(3)]
public string CustomerID { get; set; }
public DateTime? OrderDate { get; set; }
}
|