Grid control basic features


The Awesome Grid control for ASP.net MVC and ASP.net Core is used to display data, by default using a table, but that can be changed. Documentation

It can get the data from the server by specifying the url Url(urlstr) or from a js function DataFunc(jsfunc) (the javascript function could also do an ajax request and return the promise).
The Grid (like most awesome controls) can be bound to other controls using the Parent extension (used for filtering). It can also be filtered using the api.
Mods are used to add additional features to the grid like: inline editing, automatic columns hiding and via dropdown, adaptive pager (based on window width), and more.

Features:
For export to excel, pdf, txt (csv) please see this demo
GridDemo.aspx
<div class="bar">
<% TxtPerson.TextBox().Placeholder("search for person ...").CssClass("searchtxt"); %>
<awe:Ocon runat="server" ID="TxtPerson" />
<% TxtDish.TextBox().Placeholder("search for Dish ...").CssClass("searchtxt"); %>
<awe:Ocon runat="server" ID="TxtDish" />
<% SelCountry.DropdownList(new DropdownListOpt
{
Url = Page.Url().Action("GetCountries", "Data")
}); %>
<awe:Ocon runat="server" ID="SelCountry" />
</div>

<% Grid1.Grid<Lunch>()
.Main()
.Url(Page.Url().Action("GetItems", "LunchGrid"))
.Columns(b =>
{
b.Add(o => o.Id).Width(75);
b.Add(o => o.Person);
b.Add(o => o.Dish.Name,
new Column { ClientFormatFunc = "site.imgDish", MinWidth = 200 });
b.Add(o => o.Country.Name);
b.Add(o => o.Date).Grow(.1);
b.Add(o => o.Price).Width(100);
b.Add(o => o.Meals.Select(m => m.Name)).MinWidth(230);
b.Add(o => o.Location);
b.Add(o => new { o.Chef.FirstName, o.Chef.LastName }).AutoHide();
})
.Persistence(Persistence.Session)
.Height(350)
.Parent(TxtPerson.ClientID, "person")
.Parent(TxtDish.ClientID, "Dish")
.Parent(SelCountry.ClientID, "country"); %>
<awe:Ocon runat="server" ID="Grid1" />
Awesome/Grid/LunchGridController.cs
using System;
using System.Linq;
using AwesomeWebFormsDemo.Data;
using AwesomeWebFormsDemo.Models;
using AwesomeWebFormsDemo.Utils.Awesome;
using System.Web.Mvc;

using Omu.AwesomeWebForms;

namespace AwesomeWebFormsDemo.Controllers.Awesome.Grid
{
public class LunchGridController : Controller
{
public ActionResult GetItems(GridParams g, int? country, string person, string dish)
{
var query = Db.Lunches.AsQueryable();

var gmb = new GridModelBuilder<Lunch>(query.AsQueryable(), g);

gmb.KeyProp = o => o.Id;

// for when using parent controls filters
gmb.FilterContainsStr(o => o.Person, person)
.FilterContainsStr(o => o.Dish.Name, dish)
.FilterEq(o => o.Country.Id, country);

// props used in site.imgDish js function
gmb.Prop(o => o.Dish.Pic, "DishPic");
gmb.Prop(o => o.Dish.Name, "DishName");

// used by some demos (GridFrozenColumns)`
gmb.Prop(o => o.Organic, render: o => o ? "Yes" : "No");

return this.AweJson(gmb.Build());
}
}
}


See also:

Grid Client Data Demo
Grid Mailbox Demo



Comments