using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApiExplorer.Models;
namespace WebApiExplorer.Controllers
{
public partial class MVCFlexGridController : Controller
{
private readonly GridExportImportOptions _flexGridGroupModel = new GridExportImportOptions
{
NeedExport = true,
NeedImport = false,
OnlyCurrentPage = false,
IncludeColumnHeaders = true
};
public ActionResult Grouping()
{
const string GROUP_BY = "GroupBy";
ViewBag.DemoSettingsModel = new ClientSettingsModel
{
Settings = new Dictionary<string, object[]>
{
{GROUP_BY, new object[]{"ShipCountry", "ShipCity", "ShipCountry and ShipCity", "Freight", "ShippedDate","None"}}
},
HeaderNames = new Dictionary<string, string>
{
{GROUP_BY, Resources.Wijmo5FlexGrid.Grouping_GroupBy }
}
};
ViewBag.Options = _flexGridGroupModel;
var nwind = new C1NWindEntities();
return View(nwind.Orders);
}
}
}
@using C1.Web.Mvc.Grid
@using WebApiExplorer.Models
@model IEnumerable<Order>
@{
GridExportImportOptions optionsModel = ViewBag.Options;
ViewBag.DemoSettings = true;
var controlId = (ViewBag.DemoSettingsModel as ClientSettingsModel).ControlId;
}
@(Html.C1().FlexGrid<Order>().Id(controlId).Height(350).IsReadOnly(true).Bind(Model)
.AutoGenerateColumns(false).PageSize(50).GroupBy("ShipCountry").ShowGroups(true)
.Columns(columns =>
{
columns.Add().Binding("OrderID").Header("Id");
columns.Add().Binding("ShipCountry").Header("Ship Country");
columns.Add().Binding("ShipCity").Header("Ship City");
columns.Add().Binding("ShippedDate").Header("Shipped Date");
columns.Add().Binding("ShipAddress").Header("Ship Address").Width("*");
columns.Add().Binding("Freight").Header("Freight").Format("c2").Aggregate(Aggregate.Sum);
})
)
@(Html.C1().Pager().Owner(controlId))
@section Settings{
<script>
function customChangeGroupBy(grid, name) {
var groupDescriptions = grid.collectionView.groupDescriptions;
grid.beginUpdate();
groupDescriptions.clear();
if (name.indexOf("ShipCountry") > -1) {
groupDescriptions.push(new wijmo.collections.PropertyGroupDescription("ShipCountry"));
}
if (name.indexOf("ShipCity") > -1) {
groupDescriptions.push(new wijmo.collections.PropertyGroupDescription("ShipCity"));
}
if (name.indexOf("ShippedDate") > -1) {
groupDescriptions.push(new wijmo.collections.PropertyGroupDescription("ShippedDate", function (item, prop) {
var value = item[prop];
if (!value) {
return "";
} else {
return value.getFullYear() + "/" + (value.getMonth() + 1);
}
}));
}
if (name.indexOf("Freight") > -1) {
groupDescriptions.push(new wijmo.collections.PropertyGroupDescription("Freight", function (item, prop) {
var value = item[prop];
if (value <= 50) {
return "0 to 50";
}
if (value > 50 && value <= 100) {
return "50 to 100";
}
if (value > 100 && value <= 150) {
return "100 to 150";
}
return "More than 150";
}));
}
grid.endUpdate();
}
</script>
@Html.Partial("_FlexGridOptions", optionsModel)
}
@section Description{
<p>@Html.Raw(Resources.MVCFlexGrid.Grouping_Text0)</p>
}