Available in the Full Version
Pivot Data Selector - ASP.NET MVC Flat Data Binding
This sample demonstrates how to use the ASP.NET MVC Helper for the igOlapFlatDataSource and how to use this data source in igPivotDataSelector and igPivotGrid.
This sample uses CTP (Community Technical Preview) features. The API and behavior may change when these features are released with full support.
This sample is designed for a larger screen size.
On mobile, try rotating your screen, view full size, or email to another device.
Code View
Copy to Clipboard
@using Infragistics.Web.Mvc @using IgniteUI.SamplesBrowser.Models <!DOCTYPE html> <html> <head> <title></title> <!-- Ignite UI for jQuery Required Combined CSS Files --> <link href="http://cdn-na.infragistics.com/igniteui/2024.1/latest/css/themes/infragistics/infragistics.theme.css" rel="stylesheet" /> <link href="http://cdn-na.infragistics.com/igniteui/2024.1/latest/css/structure/infragistics.css" rel="stylesheet" /> <script src="http://ajax.aspnetcdn.com/ajax/modernizr/modernizr-2.8.3.js"></script> <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script> <script src="http://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script> <!-- Ignite UI for jQuery Required Combined JavaScript Files --> <script src="http://cdn-na.infragistics.com/igniteui/2024.1/latest/js/infragistics.core.js"></script> <script src="http://cdn-na.infragistics.com/igniteui/2024.1/latest/js/infragistics.lob.js"></script> <style> #dataSelector, #pivotGrid { float: left; } </style> </head> <body> <div class="sampleContent"> @(Html.Infragistics().OlapDataSource().ID("flatDataSource") .DataSourceOptions( dataSourceOptions => dataSourceOptions .Columns("[Location].[Location]") .Rows("[Dates].[RequiredDate]") .Measures("[Measures].[Freight]") .FlatDataOptions(flatOptions => flatOptions.Metadata( metadata => metadata.Cube(cube => cube.Name("Invoices").Caption("Invoices") .MeasuresDimension(measuresDimension => measuresDimension.Caption("Measures").Measures( measures => { measures.AddMeasure().Name("Quantity").Caption("Quantity").Aggregator("$.ig.OlapUtilities.prototype.sumAggregator('Quantity')"); measures.AddMeasure().Name("Freight").Caption("Freight").Aggregator("$.ig.OlapUtilities.prototype.sumAggregator('Freight', 2)"); measures.AddMeasure().Name("Discount").Caption("Discount").Aggregator("$.ig.OlapUtilities.prototype.sumAggregator('Discount', 2)"); })) .Dimensions(dimensions => { dimensions.AddDimension().Name("Location").Caption("Location").Hierarchies( hierarchies => hierarchies.AddHierarchy().Name("Location").Caption("Location").Levels(levels => { levels.AddLevel().Name("AllLocations").Caption("All Locations") .MemberProvider("function(item) {return 'All Locations';}"); levels.AddLevel().Name("ShipCountry").Caption("Country") .MemberProvider("function(item) {return item.ShipCountry; }"); levels.AddLevel().Name("City").Caption("City") .MemberProvider("function(item) {return item.City; }"); levels.AddLevel().Name("Address").Caption("Address") .MemberProvider("function(item) {return item.Address; }"); })); dimensions.AddDimension().Name("Dates").Caption("Dates").Hierarchies( hierarchies => { hierarchies.AddHierarchy().Name("RequiredDate").Caption("Required Date").Levels(levels => { levels.AddLevel().Name("AllPeriods").Caption("All Periods").MemberProvider("function(item) { return 'All Periods'; }"); levels.AddLevel().Name("Year").Caption("Year").MemberProvider("$.ig.OlapUtilities.prototype.dateMemberProvider('year', 'RequiredDate')"); levels.AddLevel().Name("Quarter").Caption("Quarter").MemberProvider("$.ig.OlapUtilities.prototype.dateMemberProvider('quarter', 'RequiredDate')"); levels.AddLevel().Name("Month").Caption("Month").MemberProvider("$.ig.OlapUtilities.prototype.dateMemberProvider('month', 'RequiredDate')"); levels.AddLevel().Name("Date").Caption("Date").MemberProvider("$.ig.OlapUtilities.prototype.dateMemberProvider('date', 'RequiredDate')"); }); hierarchies.AddHierarchy().Name("ShippedDate").Caption("Shipped Date").Levels(levels => { levels.AddLevel().Name("AllPeriods").Caption("All Periods").MemberProvider("function(item) { return 'All Periods'; }"); levels.AddLevel().Name("Year").Caption("Year").MemberProvider("$.ig.OlapUtilities.prototype.dateMemberProvider('year', 'ShippedDate')"); levels.AddLevel().Name("Quarter").Caption("Quarter").MemberProvider("$.ig.OlapUtilities.prototype.dateMemberProvider('quarter', 'ShippedDate')"); levels.AddLevel().Name("Month").Caption("Month").MemberProvider("$.ig.OlapUtilities.prototype.dateMemberProvider('month', 'ShippedDate')"); levels.AddLevel().Name("Date").Caption("Date").MemberProvider("$.ig.OlapUtilities.prototype.dateMemberProvider('date', 'ShippedDate')"); }); hierarchies.AddHierarchy().Name("OrderDate").Caption("Order Date").Levels(levels => { levels.AddLevel().Name("AllPeriods").Caption("All Periods").MemberProvider("function(item) { return 'All Periods'; }"); levels.AddLevel().Name("Year").Caption("Year").MemberProvider("$.ig.OlapUtilities.prototype.dateMemberProvider('year', 'OrderDate')"); levels.AddLevel().Name("Quarter").Caption("Quarter").MemberProvider("$.ig.OlapUtilities.prototype.dateMemberProvider('quarter', 'OrderDate')"); levels.AddLevel().Name("Month").Caption("Month").MemberProvider("$.ig.OlapUtilities.prototype.dateMemberProvider('month', 'OrderDate')"); levels.AddLevel().Name("Date").Caption("Date").MemberProvider("$.ig.OlapUtilities.prototype.dateMemberProvider('date', 'OrderDate')"); }); }); dimensions.AddDimension().Name("Customers").Caption("Customers").Hierarchies( hierarchies => hierarchies.AddHierarchy().Name("Customers").Caption("Customers").Levels(levels => { levels.AddLevel().Name("AllCustomers").Caption("All Customers") .MemberProvider("function(item) {return 'All Customers'; }"); levels.AddLevel().Name("CustomerName").Caption("Customer Name") .MemberProvider("function(item) {return item.CustomerName; }"); })); dimensions.AddDimension().Name("Salespeople").Caption("Salespeople").Hierarchies( hierarchies => hierarchies.AddHierarchy().Name("Salespeople").Caption("Salespeople").Levels(levels => { levels.AddLevel().Name("AllSalespeople").Caption("All Salespeople") .MemberProvider("function(item) {return 'All Salespeople'; }"); levels.AddLevel().Name("Salesperson").Caption("Salesperson") .MemberProvider("function(item) {return item.Salesperson; }"); })); dimensions.AddDimension().Name("Shippers").Caption("Shippers").Hierarchies( hierarchies => hierarchies.AddHierarchy().Name("Shippers").Caption("Shippers").Levels(levels => { levels.AddLevel().Name("AllShippers").Caption("All Shippers") .MemberProvider("function(item) {return 'All Shippers'; }"); levels.AddLevel().Name("ShipperName").Caption("Shipper Name") .MemberProvider("function(item) {return item.ShipperName; }"); })); dimensions.AddDimension().Name("Products").Caption("Products").Hierarchies( hierarchies => hierarchies.AddHierarchy().Name("Products").Caption("Products").Levels(levels => { levels.AddLevel().Name("AllProducts").Caption("All Products") .MemberProvider("function(item) {return 'All Products'; }"); levels.AddLevel().Name("Product").Caption("Product") .MemberProvider("function(item) {return item.ProductName; }"); })); }))) .DataSource(this.Model) .DataBind())) .Render()) @(Html.Infragistics().PivotDataSelector().Width("230px").Height("580px").DataSourceID("flatDataSource").ID("dataSelector").Render()) @(Html.Infragistics().PivotGrid().Width("580px").Height("580px").DataSourceID("flatDataSource").ID("pivotGrid").Render()) </div> </body> </html>
using System.Web.Mvc; using Infragistics.Web.Mvc; using IgniteUI.SamplesBrowser.Application.Data; using System.Data; using System.Data.SqlClient; using IgniteUI.SamplesBrowser.Models.Repositories; using Newtonsoft.Json.Converters; using System.Linq; using System; namespace IgniteUI.SamplesBrowser.Controllers { public class PivotDataSelectorController : Controller { [ActionName("using-the-asp-net-mvc-helper-with-flat-data-source")] public ActionResult UsingAspNetMvcHelperWithFlatDataSource() { var invoices = RepositoryFactory.GetInvoiceRepository().Get().Take(200).Select(invoice => new { Address = invoice.Address, City = invoice.City, CustomerName = invoice.CustomerName, Discount = invoice.Discount, Freight = invoice.Freight, OrderDate = invoice.OrderDate == null ? null : invoice.OrderDate.Value.AddYears(16).ToShortDateString(), ProductName = invoice.ProductName, Quantity = invoice.Quantity, RequiredDate = invoice.RequiredDate == null ? null : invoice.RequiredDate.Value.AddYears(16).ToShortDateString(), Salesperson = invoice.Salesperson, ShipCountry = invoice.ShipCountry, ShippedDate = invoice.ShippedDate == null ? null : invoice.ShippedDate.Value.AddYears(16).ToShortDateString(), ShipperName = invoice.ShipperName }); return View("using-the-asp-net-mvc-helper-with-flat-data-source", invoices); } [ActionName("using-the-asp-net-mvc-helper-with-xmla-data-source")] public ActionResult UsingAspNetMvcHelperWithXmlaDataSource() { return View("using-the-asp-net-mvc-helper-with-xmla-data-source"); } } }