Grid basic features and search using Parent
binding.
Some columns have autohide mod, you can resize the browser window to see the columns hide and show depending on window width.
Default.aspx
<div class="bar">
<% Txtperson.TextBox().Placeholder("search for person ...").CssClass("searchtxt"); %>
<awe:ocon runat="server" id="Txtperson" />
<% Txtfood.TextBox().Placeholder("search for food ...").CssClass("searchtxt"); %>
<awe:ocon runat="server" id="Txtfood" />
<% OCountry.AjaxRadioList().Url(Page.Url().Action("GetCountries", "Data")).Odropdown().HtmlAttributes(new { style = "min-width:15em;" }); %>
<awe:ocon runat="server" id="OCountry" />
</div>
<% Grid1.Grid()
.Reorderable()
.Mod(o => o.PageInfo().PageSize().AutoMiniPager().ColumnsSelector())
.Columns(
new Column { Bind = "Id", Width = 75, Groupable = false, Resizable = false },
new Column { Bind = "Person" },
new Column { Bind = "Food.Name", ClientFormatFunc = "site.imgFood", MinWidth = 200 },
new Column { Bind = "Country.Name", ClientFormat = ".(CountryName)", Header = "Country" },
new Column { Bind = "Date", Grow = .1 }.Mod(o => o.Autohide()),
new Column { Bind = "Location" }.Mod(o => o.Autohide()),
new Column { Bind = "Chef.FirstName,Chef.LastName", Prop = "ChefName", Header = "Chef" })
.Url(Page.Url().Action("GetItems", "LunchGrid"))
.Persistence(Persistence.Session) // save collapsed groups and nodes when switching between grid pages.
.Resizable()
.Height(350)
.Parent(Txtperson.ClientID, "person")
.Parent(Txtfood.ClientID, "food")
.Parent(OCountry.ClientID, "country"); %>
<awe:ocon runat="server" id="Grid1" />
<script>
var root = '<%=ResolveUrl("~/Content/Pictures/Food/") %>';
function imgFood(itm) {
return '<img src="' + root + itm.FoodPic + '" class="food" />' + itm.Food;
}
</script>
Awesome/Grid/LunchGridController.cs
using AwesomeWebFormsDemo.Data;
using AwesomeWebFormsDemo.Models;
using AwesomeWebFormsDemo.Utils.Awe;
using System.Web.Mvc;
using Omu.AwesomeWebForms;
using System.Linq;
using System.Threading.Tasks;
namespace AwesomeWebFormsDemo.Controllers.Awesome.Grid
{
public class LunchGridController : Controller
{
private readonly MyContext mcx = new MyContext();// mock EF Db context
public LunchGridController()
{
}
public async Task<ActionResult> GetItems(GridParams g, int? country, string person, string food)
{
var query = mcx.Lunches
.Include(o => o.Country)
.Include(o => o.Food)
.Include(o => o.Chef)
.AsQueryable();
query = query
.Filter(food, o => o.Food.Name)
.Filter(person, o => o.Person);
if (country.HasValue) query = query.Where(o => o.Country.Id == country);
var gmb = new GridModelBuilder<Lunch>(query, g);
gmb.KeyProp = o => o.Id;
gmb.Map = o => new
{
o.Id,
o.Person,
FoodName = o.Food.Name,
FoodPic = o.Food.Pic,
o.Location,
o.Price,
Date = o.Date.ToShortDateString(),
CountryName = o.Country.Name,
ChefName = o.Chef.FullName
};
return Json(await gmb.EFBuildAsync());
}
}
}