@{
var contactDropDown = new Syncfusion.EJ2.DropDowns.DropDownList
{
DataSource = Model.ContactSelectList,
Query = "new ej.data.Query()",
Fields = new Syncfusion.EJ2.DropDowns.DropDownListFieldSettings
{
Value = "Id",
Text = "ProdId"
},
AllowFiltering = true,
ActionComplete="contactActionComplete"
};
}
@(Html.EJS()
.Grid("ContactGrid")
.DataSource(Model.Contacts)
.ActionBegin("contactActionBegin")
.ActionComplete("contactActionComplete")
.EditSettings(edit => edit.AllowAdding(true).AllowDeleting(true).AllowEditing(true).Mode(EditMode.Dialog))
.Toolbar(new List<object> {"Search", "PdfExport", "ExcelExport", "Add", "Delete"})
.Columns(col =>
{
col.Field("ProdId").HeaderText("Producer ID").EditType("dropdownedit").Edit(new { @params = contactDropDown }).Add();
col.Field("FirstName").HeaderText("First Name").Add();
col.Field("LastName").HeaderText("Last Name").Add();
})
.AllowPdfExport()
.AllowExcelExport()
.ToolbarClick("toolBarHandler")
.AllowSorting()
.Render())
public class PoolViewModel
{
public int Id { get; set; }
// ... Other Fields not involved with the Grid ...
public ICollection<ContactViewModel> Contacts { get; set; }
public ICollection<ContactViewModel> ContactSelectList { get; set; }
}
function contactActionBegin(args) {
addGridItem(args, "ProdId", this.columns);
}
function addGridItem(args, visibleColumn, columns) {
if ((args.requestType === 'beginEdit' || args.requestType === 'add')) {
showSingleColumn(visibleColumn, columns);
}
}
function showSingleColumn(columnName, columns) {
for (var i = 0; i < columns.length; i++) {
if (columns[i].field != columnName) {
columns[i].visible = false;
}
else {
columns[i].visible = true;
}
}
}
function contactActionComplete(args) {
if (args.requestType === 'save') {
showAllColumns(this.columns);
$.ajax({
async: false,
type: 'GET',
url: '****Intentionally Hidden***' + args.data.ProdId,
dataType: 'json',
success: function (data) {
args.data.ProdId = data.ProdId;
args.data.FirstName = data.FirstName;
args.data.LastName = data.LastName;
}
});
refreshGrid("ContactGrid");
}
}
function showAllColumns(columns) {
for (var i = 0; i < columns.length; i++) {
columns[i].visible = true;
}
}
@Html.EJS().Grid("grid").DataSource(dataManger =>
{
dataManger.Url("/Home/UrlDatasource").BatchUrl("/Home/BatchUpdate").Adaptor("UrlAdaptor");
}).Columns(col =>
{
col.Field("OrderID").HeaderText("OrderID").IsPrimaryKey(true).Width("50").Add();
...
}).AllowPaging().Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Batch); }).Render()
|
public ActionResult UrlDatasource(DataManagerRequest dm)
{
ICollection<OrdersDetails> ordcol = orddata.ToList();
IEnumerable<OrdersDetails> DataSource = ordcol;
DataOperations operation = new DataOperations();
if (dm.Search != null && dm.Search.Count > 0)
{
DataSource = operation.PerformSearching(DataSource, dm.Search); //Search
}
if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting
{
DataSource = operation.PerformSorting(DataSource, dm.Sorted);
}
if (dm.Where != null && dm.Where.Count > 0) //Filtering
{
DataSource = operation.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);
}
int count = DataSource.Cast<OrdersDetails>().Count();
if (dm.Skip != 0)
{
DataSource = operation.PerformSkip(DataSource, dm.Skip); //Paging
}
if (dm.Take != 0)
{
DataSource = operation.PerformTake(DataSource, dm.Take);
}
return dm.RequiresCounts ? Json(new { result = DataSource, count = count }) : Json(DataSource);
} |
public ActionResult BatchUpdate(string action, CRUDModel batchmodel)
{
if (batchmodel.Changed != null)
{
for (var i = 0; i < batchmodel.Changed.Count(); i++)
{
var ord = batchmodel.Changed[i];
OrdersDetails 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;
val.ShipAddress = ord.ShipAddress;
val.ShippedDate = ord.ShippedDate; //update the changed records
}
}
if (batchmodel.Deleted != null) {
for (var i = 0; i < batchmodel.Deleted.Count(); i++)
{
orddata.Remove(orddata.Where(or => or.OrderID == batchmodel.Deleted[i].OrderID).FirstOrDefault()); //for delete operation
}
}
if (batchmodel.Added != null) {
for (var i = 0; i < batchmodel.Added.Count(); i++)
{
orddata.Insert(0, batchmodel.Added[i]); //for insert operation
}
}
var data = orddata.ToList();
return Json(data);
} |