Lookup Grid

Meal:
 

Lookup with grid inside the popup, done using the lookupgrid mod that also uses PopupUrl extension.
LookupDemo/Misc.cshtml
@(Html.Awe().LookupFor(o => o.MealCustomPopup)
.LookupGrid(Url.Action("MealLookup"))
.Controller("MealLookup"))
Awesome/Lookup/MealLookupController.cs
public class MealLookupController : Controller
{
public IActionResult GetItem(int? v)
{
Check.NotNull(v, "v");
var o = Db.Meals.SingleOrDefault(f => f.Id == v) ?? new Meal();

return Json(new KeyContent(o.Id, o.Name));
}

public IActionResult Search(string search, int page)
{
const int PageSize = 7;
search = (search ?? "").ToLower().Trim();

var list = Db.Meals.Where(o => o.Name.ToLower().Contains(search));

return Json(new AjaxListResult
{
Items = list.Skip((page - 1) * PageSize).Take(PageSize).Select(o => new KeyContent(o.Id, o.Name)),
More = list.Count() > page * PageSize
});
}
}
LookupDemo/MealLookup.cshtml
@model AweCoreDemo.ViewModels.Input.Lookup.LookupPopupInput
@using (Html.Awe().BeginContext()) {
<div class="bar">
@Html.Awe().TextBoxFor(o => o.Search).Placeholder("search...")
</div>
<div style="max-width: 900px">
@(Html.Awe().Grid("MealsGrid")
.Mod(o => o.PageInfo().ColumnsSelector().AutoMiniPager().KeyNav())
.Selectable(SelectionType.Single)
.Parent(o => o.Search, "name")
.Columns(
new Column { Bind = "Id", Width = 75, Resizable = false },
new Column { Bind = "Name", Width = 150}.Mod(o => o.Nohide()),
new Column { Bind = "Description", CssClass = "txtlim"}.Mod(o => o.Autohide()))
.Url(Url.Action("MealsGrid", "Data"))
.Groupable(false)
.Height(350))
</div>
}

Lookup with Custom Items template

Meal:
 

The Search action of the LookupController returns json of AjaxListResult, we need to set the string AjaxListResult.Content instead of Items in order to achieve Custom Item Template, exactly the same as for the AjaxList helper.
LookupDemo/Misc.cshtml
@(Html.Awe().LookupFor(o => o.MealCustomItem)
.CustomSearch())
Awesome/Lookup/MealCustomItemLookupController.cs
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using AweCoreDemo.Models;
using AweCoreDemo.Utils;
using Omu.AwesomeMvc;

namespace AweCoreDemo.Controllers.Awesome.Lookup
{
public class MealCustomItemLookupController : Controller
{
public IActionResult SearchForm()
{
return PartialView();
}

public IActionResult GetItem(int? v)
{
Check.NotNull(v, "v");
var o = Db.Meals.SingleOrDefault(f => f.Id == v) ?? new Meal();

return Json(new KeyContent(o.Id, o.Name));
}

public IActionResult Search(string search, int page)
{
const int pageSize = 10;
search = (search ?? "").ToLower().Trim();
var list = Db.Meals.Where(f => f.Name.ToLower().Contains(search));
return Json(new AjaxListResult
{
Content = this.RenderPartialView("items", list.Skip((page - 1) * pageSize).Take(pageSize)),
More = list.Count() > page * pageSize
});
}

public IActionResult Details(int id)
{
return PartialView(Db.Get<Meal>(id) ?? new Meal());
}
}
}
MealCustomItemLookup/SearchForm.cshtml
@{ Layout = null; }
<input type="text" name="search" class="awe-searchtxt" placeholder="search..."/>
@(Html.Awe().InitPopup()
.Name("details")
.Url(Url.Action("Details"))
.Mod(o => o.OutClickClose())
.Modal())
MealCustomItemLookup/Items.cshtml
@model IEnumerable<AweCoreDemo.Models.Meal>
@{ Layout = null; }
@foreach (var o in Model)
{
<li class="awe-li" data-val="@(o.Id)">Name: @o.Name
<button onclick="awe.open('details', { params: { id: @o.Id } }, event)" class="awe-btn awe-nonselect lkdetail" tabindex="-1">
Details
</button>
Category: @o.Category.Name
<br />
Description: @o.Description
</li>
}

Lookup bound to parents

Parent Categories:
  •  
Parent Category:
Child Meal:
 

Binding to parents and setting predefined parameters is done the same as for the AjaxDropdown using .Parent() and .Parameter(), values are passed to both GetItem and Search actions.
Unlike other controls the Lookup won't change its value when the value of the parent is changed.
LookupDemo/Misc.cshtml
<div class="efield">
<div class="elabel">
Parent Categories:
</div>
<div class="einput">
@(Html.Awe().MultiLookupFor(o => o.CategoriesData)
.Controller<CategoriesMultiLookupController>()
.ClearButton())
</div>
</div>
<div class="efield">
<div class="elabel">
Parent Category:
</div>
<div class="einput">
@Html.Awe().AjaxDropdownFor(o => o.Category).Url(Url.Action("GetCategories", "Data"))
</div>
</div>
<div class="efield">
<div class="elabel">
Child Meal:
</div>
<div class="einput">
@(Html.Awe().LookupFor(o => o.ChildOfMany)
.Parent(o => o.CategoriesData, "categories")
.Parent(o => o.Category, "categories")
.Controller<MealCustomSearchLookupController>())
</div>
</div>

Setting predefinded parameters

Meal1 (categories = {Fruits, Legumes}):
 



Comments