Name | Surname | Marital status | Age | Birthday | Employed |
---|---|---|---|---|---|
Joe | Crosswave | Married | 32 | 1/5/1992 | False |
Merry | Lisel | Widowed | 42 | 5/6/1982 | |
Henry | Crux | Single | 30 | 11/19/1994 | True |
Cody | Jurut | 50 | 8/11/1974 | False | |
Simon | Scranton | Single | 35 | 10/10/1989 | |
Leena | Laurent | Divorced | 20 | 7/1/2004 | False |
Ode | Cosmides | Married | 54 | 4/17/1970 | True |
Diandra | Mizner | Single | 21 | 8/20/2003 | False |
Pete | Cassel | Married | 23 | 3/13/2001 | False |
Nicky | Tremblay | Married | 32 | 1/5/1992 | True |
Mary | Cassel | Married | 25 | 7/10/1999 | True |
public ActionResult Index(String search)
{
if (HttpContext.Request.Headers.XRequestedWith == "XMLHttpRequest")
return PartialView("_IndexGrid", repository.GetPeople(search));
return View();
}
<input id="GridSearch" />
@Html.AjaxGrid(Url.Action("Index"))
<script>
document.getElementById("GridSearch").addEventListener("input", function() {
const grid = new MvcGrid(document.querySelector(".mvc-grid"));
grid.url.searchParams.set("search", this.value);
grid.reload();
});
</script>
@model IQueryable<Person>
@* Should only include grid declaration *@
@(Html
.Grid(Model)
.Build(columns =>
{
columns.Add(model => model.Name).Titled("Name");
columns.Add(model => model.Surname).Titled("Surname");
columns.Add(model => model.MaritalStatus).Titled("Marital status");
columns.Add(model => model.Age).Titled("Age");
columns.Add(model => model.Birthday).Titled("Birthday").Formatted("{0:d}");
columns.Add(model => model.IsWorking).Titled("Employed");
})
.Empty("No data found")
.Sortable()
)