The ComponentOne OLAP control is available in ASP.NET MVC, WinForms, and WPF. In this video, we'll walk you through setting up OLAP for ASP.NET MVC.
- Create a new ASP.NET MVC5 app using C1 ASP.NET 5 MVC Web Application template.
- In the project wizard, check "Include C1 MVC Olap library".
- Click OK.
- This creates the project.
- Rebuild the project.
- Let’s examine what the template has pre-configured for us.
- It has added the MVC and OLAP dll reference.
- The resources are also configured in the _Layout.cshtml:
- It has the styles and script registered.
- The Views web.config file has the MVC and OLAP controls namespace added. This help with intellisense.
- The License.licx file has the license entries for MVC and OLAP controls.
- The project is ready to use any MVC or OLAP control.
- Let’s add a Model class.
- Right click the Models folder and select Add->Class from the context menu.
- Name the class ProductData.
- In this example, we create "ProductData" class that has country wise Sales data for the product.
- And a function to generate data called GetData.
- Close this class file.
- Open the HomeController class from the Controllers folder.
- Import the Models namespace.
- Declare a model variable that holds data returned by the GetData method of ProductData model.
- Pass the model to the view.
- Save & close the HomeController.
- Open the Index.cshtml from Views/Home folder.
- Remove the pre-existing content from this view file.
- Declare a model variable for the ProductData.
- Create Div elements with row class using bootstrap grid system.
- Add a pivot panel control with Id as panel and binding set to the Model.
- This internally creates a PivotEngine.
- Inside another div element add a PivotGrid.
- Set its ItemSourceId property as PivotPanel by passing the ID of PivotPanel.
- Save and run the app.
- When the page is loaded, observe that we have a PivotPanel with all fields returned by the Model and empty Filter/Columns/Rows/Values. Also, we have empty PivotGrid.
- Let’s analyze the country wise sales data.
- Drag Country field to Rows, the Product field to Columns, and the Sales field to Values.
- We find the PivotGrid is now populated with for all products showing sales data country wise and their respective totals.
- We can customize the field setting by right clicking on the pivot panel and selecting Field
- Settings from context menu.
- Let’s change the Summary from sum to Average and click OK.
- The PivotGrid now displays avarage sales data.
- We can add more fields for precise analysis. Add Active filed to Rows.
- The Grid now shows active and inactive sales data.
- We can choose to remove any field by selecting that field and choosing Remove Field from the context menu.
- Further drill down is possible to see detail data. Double click any cell to view detail data in a popup.
- Sort any column by clicking the header.
- We have seen how a user can create views by selecting relevant fields.
- It is also possible to pre-define a view so that when the OLAP control is shown a default view is available for the user. Let’s see how to accomplish that.
- We clear the fields from the panel.
- In code:
- We add row fields that has the Country added items collection.
- Column field that has Product added to items collection.
- ValueFields that has Sales added to items collection.
- Save the project and refresh the browser.
- We can now see that the Olap panel is loaded with the above fields defined and the pivotgrid is populated with the data.
- The pivot panel displays all fields from the model, what if we need select fields and how do we set Values to aggregate differently than the default Sum.
- This can be achieved by defining pivot fields.
- In the code:
- Set fields property of PivotPanel.
- Fields is a collection that can have multiple pivot fields in its items collection.
- Each item can have a PivotField or CubeField
- We add a pivot field and set its binding to "Country".
- Another pivot field with binding "Product".
- And a third pivot field with binding Sales and Aggregate as Average.
- Save the project.
- Refresh the Browser
- When the page loads we find that the panel has only those fields that were defined in code and the Values now has aggregation set to Average of sales.