Result
Parent Config
public class ParentOrderTable : MvcTable<Order>
{
public override void Configure(IStaticTableConfiguration<Order> config)
{
config.SetAction("ListParentOrders", "Northwind")
.SetCssClass("table table-striped")
.ActionLinkColumn(c => c.OrderID, "", "#", o => new { o.OrderID }, new { @class = ChildOrderDetailTable .Filter})
.DisplayForColumn(c => c.Customer.ContactName)
.DisplayForColumn(c => c.Shipper.CompanyName)
.AddColumn(c => c.Total,
cfg => cfg.FormatUsing(d => d.ToString("c")).IsSortable(false).SetHeaderText("Order Total"))
.ConfigurePagingControl(p => p.SetContainerCssClass("pagination"));
}
}
Child Config
public class ChildOrderDetailTable : MvcTable<Order_Detail>
{
public override void Configure(IStaticTableConfiguration<Order_Detail> config)
{
config.SetAction("ListChildOrderDetails", "Northwind")
.SetCssClass("table table-striped")
.SetFilterClass(Filter)
.DisplayForColumn(c => c.Product.ProductName,
cfg =>
cfg.DefineFooter(
(h, rows) =>
rows.Any() ? "Order ID: " + h.ViewData.Model.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") : ""));
}
}
Child Actions
public ActionResult ListChildOrderDetails(TableRequestModel request, int? orderId)
{
var entities = new NorthwindEntities.NorthwindEntities(NorthwindServiceUrl);
IQueryable<Order_Detail> orderDetails = entities.Order_Details.Expand(o => o.Product);
if (orderId == null)
orderDetails = orderDetails.Where(o => false);
else
orderDetails = orderDetails.Where(o => o.OrderID == orderId.Value);
return new TableResult<Order_Detail>(orderDetails, "ChildOrderDetails", request);
}
public ActionResult ListOrdersForFilters(TableRequestModel request, FiltersModel model)
{
var entities = new NorthwindEntities.NorthwindEntities(NorthwindServiceUrl);
IQueryable<Order> orders = entities.Orders.Expand(o => o.Customer).Expand(o => o.Shipper).Expand(o => o.Order_Details);
if (!String.IsNullOrEmpty(model.SelectedCustomerId))
orders = orders.Where(o => o.CustomerID == model.SelectedCustomerId);
return new TableResult<Order>(orders, "Filters", request);
}