Drag a column header and drop it here to group by that column
Id
Name
Date
Chef
Meals
Bonus Meal
4315
cabbage
1/6/2025
Naked Chef
Mango, Apple
Papaya
675
asdasda
6/8/2007
Gaia Earth
Rice
Apple
673
Apples
9/17/2018
Peter Gibbons
Broccoli, Mango
Banana
671
Cookies
11/13/2019
Joanna Stan
Tomato, Walnuts, Cauliflower
Cucumber
669
Morning Tea
6/15/2009
Pepper Tomato
Hazelnuts
Cucumber
667
Morning meal
8/11/2018
Pepper Tomato
Walnuts
Buckwheat
665
Snacks and movie
10/9/2020
Joanna Stan
Buckwheat
Wheat
663
Apero
10/27/2010
Gaia Earth
Almonds, Buckwheat, Apple
Lettuce
661
petit dej
8/3/2009
Joanna Stan
Walnuts, Buckwheat
Banana
659
Breakfast
10/27/2012
Casse Croute
Mango
Broccoli
show code
Grid crud, built using the Grid and PopupForm helpers called via InitCrudPopupsForGrid,
each PopupForm has Success js function assigned, these functions are located in aweUtils.js.
Post actions return a json object which tells the PopupForm that the result is a success, that json object contains the id property which is used to flash the row.
Delete PopupForm has OnLoad js func used to animate the row that is about to be deleted.
Make sure to use "return PartialView" for PopupForm/Popup views this will ignore _viewstart.cshtml so that you don't use the _Layout.cshtml and realod all the scripts, and as a result break the js.
Shared/Demos/GridCrud.cshtml
@{ var gid = "DinnersGrid"; } @Html.InitCrudPopupsForGrid(gid, "DinnersGridCrud")
/// </summary> /// parameters for Edit, Delete controller Actions need to remain called "id", that's how they are set in GridUtils.cs ( "params:{{ id:" ); /// or in MapToGridModel additionally to o.MyId add another property Id = o.MyId /// and for the action columns (edit, delete btns) you can either specify the MyId property (e.g. GridUtils.EditFormatForGrid("DinnersGrid", "MyId")); /// change the Bind = "MyId" (if you have an Id column), /// Note: If your Key Property is not "Id" (but "MyId"), you need to change the GridModelBuilder.Key = "MyId" in GridGetItems and in the view /// <summary> public class DinnersGridCrudController : Controller { private static object MapToGridModel(Dinner o) { return new { o.Id, o.Name, Date = o.Date.ToShortDateString(), ChefName = o.Chef.FullName, Meals = string.Join(", ", o.Meals.Select(m => m.Name)), BonusMeal = o.BonusMeal.Name }; }
public IActionResult GridGetItems(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, GetItem = () => Db.Get<Dinner>(Convert.ToInt32(g.Key)), // used when calling api.update (signalrSync.js) };
return Json(model.Build()); }
public IActionResult Create() { // make sure to use "return PartialView" for PopupForm/Popup views // this will ignore _viewstart.cshtml so that you don't use the _Layout.cshtml and reload all the scripts return PartialView(); }
[HttpPost] public IActionResult Create(DinnerInput input) { return save(input); }
public IActionResult Edit(int id) { var dinner = Db.Dinners .Single(o => o.Id == id);
var input = new DinnerInput { Id = dinner.Id, Name = dinner.Name, ChefId = dinner.Chef.Id, Date = dinner.Date, MealsIds = dinner.Meals.Select(o => o.Id), BonusMealId = dinner.BonusMeal.Id };
return PartialView("Create", input); }
[HttpPost] public IActionResult Edit(DinnerInput input) { return save(input); }
private IActionResult save(DinnerInput input) { if (!ModelState.IsValid) return PartialView("Create", input);
var isCreate = !input.Id.HasValue;
var ent = isCreate ? new Dinner() : Db.Dinners .First(o => o.Id == input.Id);