MultiLookup control demo
MultiLookup needs a controller or urls to be specified, by default convention it
will look for a controller with the same name as it + "MultiLookupController"
-
action GetItems
- used to show the value in the readonly field, it will receive av
parameter which is going to be the keys of the selected items -
action Search
- gets data for the search result in it's popup, it receives aselected
parameter that represents the selected values, it should return aJson(AjaxListResult)
, so it has same features as the AjaxList (table layout, custom item template) action Selected
- gets data for the selected items in the popup
MultiLookupDemo/Index.cshtml
@(Html.Awe().MultiLookupFor(o => o.Meals)
.Controller<MealsMultiLookupController>()
.ClearButton()
.HighlightChange())
Awesome/MultiLookup/MealsMultiLookupController.cs
public class MealsMultiLookupController : Controller
{
public IActionResult GetItems(int[] v)
{
var items = new List<Meal>();
if (v != null)
{
items = Db.Meals
.Where(o => v.Contains(o.Id)).ToList();
}
return Json(items.Select(meal => new KeyContent(meal.Id, meal.Name)));
}
public IActionResult Search(int[] selected, int page, string search)
{
selected = selected ?? new int[] { };
var query = Db.Meals.AsQueryable().Filter(search, o => o.Name).Where(o => !selected.Contains(o.Id));
var res = AweUtil.BuildList(query, page, keyContentFunc: o => new KeyContent(o.Id, o.Name));
return Json(res);
}
public IActionResult Selected(int[] selected)
{
var items = new List<Meal>();
if (selected != null)
{
items = Db.Meals
.Where(o => selected.Contains(o.Id)).ToList();
}
return Json(new AjaxListResult
{
Items = items.Select(o => new KeyContent(o.Id, o.Name))
});
}
}
MultiLookup Grid
MultiLookup with grids inside the popup, done using the MultiLookupGrid mod that also uses PopupUrl extension.
MultiLookupDemo/Index.cshtml
@(Html.Awe().MultiLookup(new MultiLookupOpt
{
Name = "MealCustomPopup",
Dropdown = false,
Modal = true,
Height = 700,
MaxWidth = 900,
Controller = "MealsMultiLookup"
})
.MultiLookupGrid(Url.Action("MealMultiLookupGrid")
))
Awesome/MultiLookup/MealsMultiLookupController.cs
public class MealsMultiLookupController : Controller
{
public IActionResult GetItems(int[] v)
{
var items = new List<Meal>();
if (v != null)
{
items = Db.Meals
.Where(o => v.Contains(o.Id)).ToList();
}
return Json(items.Select(meal => new KeyContent(meal.Id, meal.Name)));
}
public IActionResult Search(int[] selected, int page, string search)
{
selected = selected ?? new int[] { };
var query = Db.Meals.AsQueryable().Filter(search, o => o.Name).Where(o => !selected.Contains(o.Id));
var res = AweUtil.BuildList(query, page, keyContentFunc: o => new KeyContent(o.Id, o.Name));
return Json(res);
}
public IActionResult Selected(int[] selected)
{
var items = new List<Meal>();
if (selected != null)
{
items = Db.Meals
.Where(o => selected.Contains(o.Id)).ToList();
}
return Json(new AjaxListResult
{
Items = items.Select(o => new KeyContent(o.Id, o.Name))
});
}
}
MultiLookupDemo/MealMultiLookup.cshtml
Could not find file '/app/Views/MultiLookupDemo/MealMultiLookup.cshtml'.
MultiLookup with Custom Items
MultiLookupDemo/Index.cshtml
@(Html.Awe().MultiLookup(new MultiLookupOpt {
Name = "MealsCustomItem",
Controller = "MealsCustomItemMultiLookup",
Value = Db.Meals.Take(3).Select(o => o.Id).ToArray(),
Dropdown = false,
Modal = true,
CustomSearch = true,
Height = 700,
MaxWidth = 1000,
CssClass = "MLLimH" // limit caption height
}))
MultiLookup bound to many parents
Parent Categories:
Parent Category:
Child Meals:
Setting predefined parameters
Meals (categories =
Fruits):
Comments