@(Html.EJ().Grid<object>("Editing")
.Datasource((IEnumerable<object>)ViewBag.datasource)
.AllowPaging()
.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.Dialog); })
. . . ..
.Columns(col =>
{
. . .. . ..
col.Field("CustomerID"). ValidationRules(v => v.AddRule("customRegex", 5)).Add();
col.Field("Freight").ValidationRules(rule =>
rule.AddRule("customCompare", new List<object>() { 0, 1000 }))
.Add();
})
)
<script type="text/javascript">
$(function () {
$.validator.addMethod("customCompare", function (value, element, params) {
return element.value > params[0] && element.value < params[1];
}, "Freight value must be between 0 and 1000");
$.validator.addMethod("customRegex", function (value, element, params) {
if (element.value.length == params)
return true;
return false;
}, "Customer ID must be 5 characters");
});
</script> |
@(Html.EJ().Grid<object>("Editing")
.Datasource((IEnumerable<object>)ViewBag.datasource)
.AllowPaging()
.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.Dialog); })
.Columns(col =>
{
. .. . . .
col.Field("EMail").ValidationRules(v => v.AddRule("email", true)).Add();
})
) |
@(Html.EJ().Grid<object>("Editing")
.Datasource((IEnumerable<object>)ViewBag.datasource)
.AllowPaging()
.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.Dialog); })
. . . .
.Columns(col =>
{
. . ..
col.Field("ShipPostalCode").HeaderText("Ship PostalCode")
.EditTemplate(a =>
{ a.Create("create").Read("read").Write("write"); })
.Width(80).Add(); . . ..
})
)
<script type="text/javascript">
function create() {
return $("<input>");
}
function write(args) {
args.element.ejMaskEdit({
maskFormat: "99-99-9999",
value: args.rowdata["ShipPostalCode"]
});
}
function read(args) {
return args.ejMaskEdit("get_StrippedValue");
}
</script> |
public ActionResult DialogInsert(Orders value)
{
GetData();
var obj = order.Where(o => o.OrderID == value.OrderID).FirstOrDefault();
if (obj != null)
throw new InvalidOperationException("OrderID already existis");//Exception thrown
order.Insert(0, value);
return Json(value, JsonRequestBehavior.AllowGet);
}
@(Html.EJ().Grid<object>("Editing")
.Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.datasource)
.InsertURL("/Home/DialogInsert")
.UpdateURL("/Home/DialogUpdate")
.RemoveURL("/Home/DialogRemove")
.Adaptor(AdaptorType.RemoteSaveAdaptor))
.AllowPaging()
.. . . . .
.ClientSideEvents(events => events.ActionComplete("complete").ActionFailure("failure"))
)
function complete(args) {
. .. .
if (args.requestType == 'save') {
alert("REcords save Successfully");
}
}
function failure(args) {
//args.error=> provides all the information
alert(args.error.statusText)
}
|
@(Html.EJ().Grid<object>("Editing")
. . .. .
.ClientSideEvents(events => events.ActionFailure("failure"))
)
<script type="text/javascript">
function failure(args) {
//args.error=> provides all the information
var error = $(args.error.responseText).find('i').text();
alert(error); //it will popup the alert with an exception message
$("#Editing").ejWaitingPopup("hide");// hides the waiting popup
}
</script>
public ActionResult DialogInsert(Orders value)
{
GetData();
var obj = order.Where(o => o.OrderID == value.OrderID).FirstOrDefault();
if (obj != null)
throw new InvalidOperationException("OrderID already exist");//Exception thrown
order.Insert(0, value);
return Json(value, JsonRequestBehavior.AllowGet);
} |
@(Html.EJ().Dialog("ErrorList").Title("Exception Thrown").ShowOnInit(false))
@(Html.EJ().Grid<object>("Editing")
. . ..
.ClientSideEvents(events => events.ActionFailure("failure"))
)
<script type="text/javascript">
function failure(args) {
$("#Editing").ejWaitingPopup("hide");
var str = "";
str = ($($(args.error.responseText).find('b')[0]).text() + ":" + $(args.error.responseText).find('i').text());
$("#ErrorList").html('<p style="font-family: cursive;color: blue;">' + str + '</p></br><button id="button1" style="margin-left: 50%">OK</button>');
$("#button1").ejButton({
click: function (args) {
$("#ErrorList").ejDialog("close");
}
});
$("#ErrorList").ejDialog({ enableModal: true });
$("#ErrorList").ejDialog("open");
}
</script> |
function failure(args) {
//$("#Editing").ejWaitingPopup("hide");
var str = "";
str = ($($(args.error.responseText).find('b')[0]).text() + ":" + $(args.error.responseText).find('i').text());
$("#ErrorList").html('<p style="font-family: cursive;color: blue;">' + str + '</p></br><button id="button1" style="margin-left: 50%">OK</button>');
$("#button1").ejButton({
click: function (args) {//click event of button
$("#ErrorList").ejDialog("close");
var gridObj = $("#Editing").ejGrid("instance");
gridObj.cancelEdit();//cancel the editing
$("#Editing_dialogEdit").ejDialog("close");// and closed dialog edit form
$("#Editing").ejWaitingPopup("hide");
}
});
$("#ErrorList").ejDialog({ enableModal: true });
$("#ErrorList").ejDialog("open");
} |
@(Html.EJ().Grid<object>("Editing")
. . . .
.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.DialogTemplate).DialogEditorTemplateID("#template"); })
. . . .
. . . .
.ClientSideEvents(events => events.ActionComplete("complete").ActionFailure("failure"))
)
<script type="text/javascript">
function failure(args) {
$("#Editing").ejWaitingPopup("hide");
var str = "";
str = ($($(args.error.responseText).find('b')[0]).text() + ":" + $(args.error.responseText).find('i').text());
$("#ErrorList").html('<p style="font-family: cursive;color: blue;">' + str + '</p>');
}
</script>
<script type="text/template" id="template">
<b>Order Details</b>
<table cellspacing="10">
<tr>
<td style="text-align: right;">
Order ID
</td>
</tr>
. . . .
</table>
</br>
<div id="ErrorList"></div>
</script>
|
function failure(args) {//ActionFailure event
var str = "";
str = "Record is failed to update";
$("#ErrorList").html('<p style="font-family: cursive;color: blue;">' + str + '</p></br><button id="button1" style="margin-left: 50%">OK</button>');
$("#button1").ejButton({
click: function (args) {//click event of button
$("#ErrorList").ejDialog("close");
var gridObj = $("#Editing").ejGrid("instance");
$("#Editing").ejWaitingPopup("hide");
gridObj.cancelEdit();//cancel the editing
$("#Editing_dialogEdit").ejDialog("close");// and closed dialog edit form
}
});
$("#ErrorList").ejDialog({ enableModal: true });
$("#ErrorList").ejDialog("open");
}
public ActionResult DialogInsert(Orders value)
{
GetData();
var obj = order.Where(o => o.OrderID == value.OrderID).FirstOrDefault();
if (obj != null)
throw new InvalidOperationException("OrderID already exist");//Exception thrown
order.Insert(0, value);
return Json(value, JsonRequestBehavior.AllowGet);
} |
function failure(args) {
//$("#Editing").ejWaitingPopup("hide");
var str = "";
str = ($($(args.error.responseText).find('b')[0]).text() + ":" + $(args.error.responseText).find('i').text());
$("#ErrorList").html('<p style="font-family: cursive;color: blue;">' + str + '</p></br><button id="button1" style="margin-left: 50%">OK</button>');
$("#button1").ejButton({
click: function (args) {//click event of button
$("#ErrorList").ejDialog("close");
var gridObj = $("#Editing").ejGrid("instance");
gridObj.cancelEdit();//cancel the editing
$("#Editing_dialogEdit").ejDialog("close");// and closed dialog edit form
$("#Editing").ejWaitingPopup("hide");
}
});
$("#ErrorList").ejDialog({ enableModal: true });
$("#ErrorList").ejDialog("open");
}
public ActionResult DialogInsert(Orders value)
{
GetData();
var obj = order.Where(o => o.OrderID == value.OrderID).FirstOrDefault();
if (obj != null)
throw new InvalidOperationException("OrderID already exist");//Exception thrown
order.Insert(0, value);
return Json(value, JsonRequestBehavior.AllowGet);
} |
@(Html.EJ().Grid<object>("Editing")
.Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.datasource)
.InsertURL("/Home/DialogInsert")
.UpdateURL("/Home/DialogUpdate")
.RemoveURL("/Home/DialogRemove")
.Adaptor(AdaptorType.RemoteSaveAdaptor))
.AllowPaging()
.. . . . .
.ClientSideEvents(events => events.ActionComplete("complete").ActionFailure("failure"))
)
function complete(args) {
. .. .
if (args.requestType == 'save') {
alert("REcords save Successfully");
}
}
|