The Awesome Grid supports inline editing with batch save. Using batch save you can perform the saving of all the edited rows in one single request. In case of validation errors on the server side you can decide to save only the valid rows or to cancel the save for all rows and show the validation messages.
Edit on row click and batch save
Grid inline editing with batch save.
Edit on row click, and save by clicking the save all button on top.
Save can be performed either for each row individually by clicking the row save button, for all at once using the "Save all" button.
You can turn off edit on row click by setting rowClickEdit: false (like in the inline editing demos).
Shared/Demos/GridInlineBatchEdit.cshtml
@{ var grid2Id = "BatchSaveGrid"; var initObj = new { Name = DemoUtils.RndName(), Date = DateTime.Now.ToShortDateString(), ChefId = Db.Chefs.First().Id, MealsIds = Db.Meals.Take(2).Select(o => o.Id).ToArray() }; } <div class="bar"> <div style="float: right;"> @Html.Awe().TextBox("txtSearch2").Placeholder("search...").CssClass("searchtxt") </div> <button type="button" onclick="$('#@grid2Id').data('api').inlineCreate()" class="awe-btn">Create</button> @Html.InlineCreateButtonForGrid(grid2Id, initObj, "Create with predefined values") <button type="button" onclick="$('#@grid2Id').data('api').batchSave()" class="awe-btn">Save All</button> <button type="button" onclick="$('#@grid2Id').data('api').inlineCancelAll()" class="awe-btn">Cancel All</button> </div>
// below properties used for inline editing only MealsIds = o.Meals.Select(m => m.Id.ToString()).ToArray(), // value for meals multiselect ChefId = o.Chef.Id, // value for chef dropdown BonusMealId = o.BonusMeal.Id // value for bonus meal dropdown }; }
public IActionResult GridGetData(GridParams g, string search = "") { var query = Db.Dinners.Where(o => o.Name.Contains(search)).AsQueryable();
var model = new GridModelBuilder<Dinner>(query, g) { KeyProp = o => o.Id, // needed for api select, update, tree, nesting, EF Map = MapToGridModel, };
return Json(model.Build()); }
[HttpPost] public IActionResult BatchSave(DinnerInput[] inputs) { var res = new List<object>();
foreach (var input in inputs) { var vldState = ModelUtil.Validate(input);
// custom validation example if (input.Name != null && input.Name.Contains("aaa")) { vldState.Add("Name", "Name can't contain aaa"); }
if (vldState.IsValid()) { try { var isCreate = !input.Id.HasValue;
var ent = isCreate ? new Dinner() : Db.Dinners.First(o => o.Id == input.Id);