|
[Index.cshtml]
$(function () {// Document is ready.
var dataManager = ej.DataManager({
url: "UrlDataSource",
batchUrl: "BatchUpdate",
adaptor: new ej.UrlAdaptor()
});
$("#Grid").ejGrid({
dataSource: dataManager,
allowPaging: true,
editSettings: {
allowEditing: true,
allowAdding: true,
allowDeleting: true,
editMode: "batch",
showConfirmDialog: false
},
columns: [
----
]
});
});
------------------------------------------------
[HomeController.cs]
public object UrlDataSource(DataManager dm)
{
IEnumerable DataSource = OrderRepository.GetAllRecords().ToList(); ;
DataOperations ds = new DataOperations();
if (dm.Search != null && dm.Search.Count > 0)
{
DataSource = ds.PerformSearching(DataSource, dm.Search);
}
if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting
{
DataSource = ds.PerformSorting(DataSource, dm.Sorted);
}
if (dm.Where != null && dm.Where.Count > 0) //Filtering
{
DataSource = ds.PerformWhereFilter(DataSource, dm.Where, dm.Where[0].Operator);
}
var count = DataSource.AsQueryable().Count();
DataSource = ds.PerformSkip(DataSource, dm.Skip);
DataSource = ds.PerformTake(DataSource, dm.Take);
if (dm.RequiresCounts)
return Json(new { result = DataSource, count = count });
else
return Json(DataSource, JsonRequestBehavior.AllowGet);
}
public ActionResult BatchUpdate(List<EditableOrder> changed, List<EditableOrder> added, List<EditableOrder> deleted)
{
if (changed != null)
OrderRepository.Update(changed);
if (deleted != null)
OrderRepository.Delete(deleted);
if (added != null)
OrderRepository.Add(added);
var data = OrderRepository.GetAllRecords();
return Json(data, JsonRequestBehavior.AllowGet);
}
|
Thank you for replying.
I am already using batch edit mode. My problem is using addRecord with a duplicate will immediately send an update to the server. The serverChange parameter doesn't seem to have any effect.
|
$("#Grid").ejGrid({
dataSource: dataManager,
allowPaging: true,
beforeBatchSave: "beforesave",
editSettings: {
. . . . . .
});
function beforesave(args) {
if (args.batchChanges.added[0].OrderID == 12333)
args.cancel = true; // will disable form saving the record to the grid.
}
|
Cancelling the batch save indeed stops sending a request to the server, however the new row that's supposed to be a duplicate doesn't appear in the grid. My requirement is to batch all the changes until the user manually clicks the toolbar save button.
|
<input type="button" value="Update a Record in batchChanges" onclick="upateBatchChanges()" />
<input type="button" value="Save teh Grid Data" onclick="GridBatchSave()" />
<div id="Grid">
</div>
<script type="text/javascript">
$(function () {// Document is ready.
var dataManager = ej.DataManager({
url: "UrlDataSource",
batchUrl: "BatchUpdate",
adaptor: new ej.UrlAdaptor()
});
$("#Grid").ejGrid({
dataSource: dataManager,
allowPaging: true,
---
columns: [
----
]
});
});
function upateBatchChanges(args) {
var gridObj = $("#Grid").ejGrid('instance');
gridObj.batchChanges.added.push({ OrderID: 121223, EmployeeID: 3, CustomerID: "Jhon", ShipCity: "Lyon", ShipCountry: "France" });
gridObj.batchChanges.added.push({ OrderID: 121224, EmployeeID: 1, CustomerID: "Jhon", ShipCity: "Lyon", ShipCountry: "France" });
}
function GridBatchSave(args) {
var gridObj = $("#Grid").ejGrid('instance');
gridObj.batchSave();
}
|