- Home
- Forum
- ASP.NET MVC
- How to stop saving the grid with external save button when validations are fail
How to stop saving the grid with external save button when validations are fail
Hi,
I'm using an external button to save my grid in batch edit mode. I have used ValidationRules in some columns and I want to stop saving the grid if those validations fail. Is there a way to do it with the external save button?
Thank you.
Kalum
I'm using an external button to save my grid in batch edit mode. I have used ValidationRules in some columns and I want to stop saving the grid if those validations fail. Is there a way to do it with the external save button?
Thank you.
Kalum
SIGN IN To post a reply.
5 Replies
PK
Prasanna Kumar Viswanathan
Syncfusion Team
June 8, 2018 09:26 AM UTC
Hi Kalum,
Thanks for contacting Syncfusion support.
According to your query we suspect that you want to stop saving the grid when validation is displayed. We have created a sample and in this sample we have used batchSave method of ejGrid in button click event to save the edited records in Grid.
We have used validationRules in some columns, so when we click on button the validationRules is displayed and stop saving the records in Grid. To display the validation message we need to refer the below script files in our sample
Jquery.validate.min.js
Jquery.validate.unobstrusive.min.js
Find the code example:
|
@Html.EJ().Button("buttonnormal").Text("BatchSave").Size(ButtonSize.Mini).ShowRoundedCorner(true).ClientSideEvents(e => e.Create("btnLoad").Click("btnClick"))
@(Html.EJ().Grid<OrdersView>("FlatGrid")
.Datasource((IEnumerable<object>)ViewBag.datasource)
------------------------------
.Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(90).ValidationRules(v => v.AddRule("required", true).AddRule("number", true)).Add();
col.Field("CustomerID").HeaderText("Customer ID").Width(90).ValidationRules(v => v.AddRule("required", true).AddRule("minlength", 3)).Add();
------------------------------------
col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Width(80).EditType(EditingType.Numeric).Format("{0:C}").ValidationRules(v => v.AddRule("range", "[0,1000]")).Add();
-----------------------------------
})
)
-------------------------------------------------------
<script type="text/javascript">
function btnClick(args) {
var grid = $("#FlatGrid").ejGrid("instance");
grid.batchSave();
}
</script>
---------------------------------------------------------
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
|
Regards,
Prasanna Kumar N.S.V
KA
kalum
June 8, 2018 10:22 AM UTC
Hi Prasanna,
Thank you very much for your kind support. But still there is a small problem. In my coding after grid.batchSave(); of btnClick event I have some more coding to execute. But those lines should not be executed when validation is displayed. In the sense if I press the button to save while validation is displayed it should show an alert in the browser window, saying that you cannot save and stop executing rest of the coding. Please help me to solve this matter.
Thank you
Kalum
Thank you very much for your kind support. But still there is a small problem. In my coding after grid.batchSave(); of btnClick event I have some more coding to execute. But those lines should not be executed when validation is displayed. In the sense if I press the button to save while validation is displayed it should show an alert in the browser window, saying that you cannot save and stop executing rest of the coding. Please help me to solve this matter.
Thank you
Kalum
PK
Prasanna Kumar Viswanathan
Syncfusion Team
June 11, 2018 07:41 AM UTC
Hi Kalum,
Thanks for update.
In this you have mentioned that you need to stop other operation when validation message is displayed and also display the alert window(“you cannot save and stop executing rest of the coding”). To achieve this requirement we suggest you to check the condition with isEdit property of ejGrid.
When the grid display validation then the grid will be in edit state only. The isEdit property will be set as true when the grid is in edit state. So, we can check with this property and achieve the requirement.
Find the code example:
|
@(Html.EJ().Grid<OrdersView>("FlatGrid")
.Datasource((IEnumerable<object>)ViewBag.datasource)
----------------------
.AllowPaging()
.Columns(col =>
{
-----------------------
})
)
<script type="text/javascript">
function btnClick(args) {
var grid = $("#FlatGrid").ejGrid("instance");
grid.batchSave();
if (grid.model.isEdit) {
alert("you cannot save and stop executing rest of the coding");
}
else {
alert("Execute other operation")
}
}
</script> |
Regards,
Prasanna Kumar N.S.V
KA
kalum
June 13, 2018 04:09 AM UTC
Hi Prasanna,
Thanks very much for your help. That solution works fine.
Thank you
Kalum
Thanks very much for your help. That solution works fine.
Thank you
Kalum
VN
Vignesh Natarajan
Syncfusion Team
June 14, 2018 04:10 AM UTC
Hi Kalum,
Thanks for the update.
We are glad to hear that your query has been resolved by our solution.
Please get back to us if you have further queries.
Regards,
Vignesh Natarajan
SIGN IN To post a reply.
- 5 Replies
- 3 Participants
-
KA kalum
- Jun 7, 2018 05:23 AM UTC
- Jun 14, 2018 04:10 AM UTC