![Gitter](https://badges.gitter.im/Join Chat.svg)
![Build status](https://camo.githubusercontent.com/117f7069c46688238463fb8dfa696cb0effed2bfa8bc843d085fa770446c3d65/68747470733a2f2f63692e6170707665796f722e636f6d2f6170692f70726f6a656374732f7374617475732f37743461767735386d6e6f37683872343f7376673d74727565)
An AJAX/HTML Table framework for ASP.Net MVC
Supports:
- paging,
- sorting,
- filtering,
- MVC Edit/Display templates for cell markup,
- Partial Views for cell markup,
- HtmlHelper style column configuration
- Fluent configuration
Nuget Here
Example Here
Blog Article
To save loads of messy boiler plate code clogging up Controller actions, the tables can be configured at startup.
Any class that inherits TableConfigurator<TType>
can be registered int the global.asax thusly:
- Global.asax
```C#
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
//Regular MVC Setup hoo haa
ConfigureMvcTables.InTheSameAssembly.As();
}
}
```
- Usage - Action Method
```C#
public ActionResult ListEmployees(TableRequestModel request)
{
var entities = new NorthwindEntities.NorthwindEntities(NorthwindServiceUrl);
return new TableResult(entities.Employees, request);
}
```
- Auto Configuration
```C#
public class CategoryTable : MvcTable
{
public override void Configure(ITableConfiguration config)
{
config
.SetCssClass("table table-striped")
.ScaffoldAllColumns();
}
}
```
- Basic Configuration
```C#
public class InvoiceTable : MvcTable
{
public override void Configure(ITableConfiguration config)
{
config
.SetCssClass("table table-striped")
.DisplayForColumn(m => m.ProductName)
.DisplayForColumn(m => m.Quantity)
.DisplayForColumn(m => m.Region)
.DisplayForColumn(m => m.Salesperson)
.EditorForColumn(m => m.Discount);
}
}
```
- More Complex Configuration
```C#
public class OrderDetailTable : MvcTable
{
public override void Configure(ITableConfiguration config)
{
config
.SetCssClass("table table-striped")
.ConfigurePagingControl(p => p.ShowPagingControl(true))
.DisplayForColumn(c => c.Product.ProductName,
cfg => cfg.DefineFooter((h, rows) => rows.Any() ? "Order ID: " + rows.First().OrderID : ""))
.DisplayForColumn(c => c.Quantity)
.DisplayForColumn(c => c.UnitPrice)
.DisplayForColumn(c => c.LineTotal,
cfg => cfg.DefineFooter((h,rows) => rows.Any() ? rows.Sum(od => od.LineTotal).ToString("c") : ""))
.ConfigurePagingControl(p => p.ShowPagingControl(false))
.SetFilterSelector("childFilter");
SetName("ChildOrderDetails");
}
}
<dl>
<dt>Runtime Configuration Overrides - Action Method</dt>
<dd></dd>
</dl>
```C#
public ActionResult ListEmployees(TableRequestModel request)
{
var entities = new NorthwindEntities.NorthwindEntities(NorthwindServiceUrl);
var result = new TableResult<Employee>(entities.Employees, request);
// Override configuration
result.Overrides.EditorForColumn(d => d.HireDate, cfg => cfg.SetIndex(1));
return result;
}