Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions CS/PivotTableBindToData/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,31 @@
@using DevExpress.Blazor.PivotTable

@if (DataExists == true) {
<DxPivotTable Data="DataSource"
VirtualScrollingEnabled="true">
<Fields>
<DxPivotTableField Field="@nameof(Sale.StoreName)" Area="@PivotTableArea.Row" SummaryType="PivotTableSummaryType.CountDistinct" />
<DxPivotTableField Field="@nameof(Sale.Year)" Area="@PivotTableArea.Column" />
<DxPivotTableField Field="@nameof(Sale.Quarter)" Area="@PivotTableArea.Column">
<ValueTemplate>
<span>@($"Q{context.Text}")</span>
</ValueTemplate>
</DxPivotTableField>
<DxPivotTableField Field="@nameof(Sale.Amount)" Area="@PivotTableArea.Data" SummaryType="@PivotTableSummaryType.Sum" />
<DxPivotTableField Field="@nameof(Sale.SaleId)" Caption="Count" Area="PivotTableArea.Data" SummaryType="PivotTableSummaryType.Count" />
</Fields>
</DxPivotTable>
<DxPivotTable Data="DataSource"
VirtualScrollingEnabled="true">
<Fields>
<DxPivotTableField Field="@nameof(Sale.StoreName)" Area="@PivotTableArea.Row" SummaryType="PivotTableSummaryType.CountDistinct" />
<DxPivotTableField Field="@nameof(Sale.Year)" Area="@PivotTableArea.Column" />
<DxPivotTableField Field="@nameof(Sale.Quarter)" Area="@PivotTableArea.Column">
<ValueTemplate>
<span>@($"Q{context.Text}")</span>
</ValueTemplate>
</DxPivotTableField>
<DxPivotTableField Field="@nameof(Sale.Amount)" Area="@PivotTableArea.Data" SummaryType="@PivotTableSummaryType.Sum" />
<DxPivotTableField Field="@nameof(Sale.SaleId)" Caption="Count" Area="PivotTableArea.Data" SummaryType="PivotTableSummaryType.Count" />
</Fields>
</DxPivotTable>
}
else if (DataExists == false) {
<div class="generate-data-container">
<p>The Sales table was not found.</p>
<DxButton Text="Generate data" Enabled="@(!IsGenerating)" Click="@GenerateDataAsync" />
@if (IsGenerating) {
<p>Generating 1,000,000 rows, please wait...</p>
}
</div>
@if (IsGenerating) {
<p>Generating sample data (1,000,000 rows). Please wait...</p>
} else {
<p>The sample database was not found. Generate the database to run the example.</p>
<DxButton Text="Generate Data" Click="@GenerateDataAsync" />
}
}
else {
<p>Checking for data...</p>
<p>Checking the database...</p>
}

@code {
Expand Down
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,32 @@
[![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183)
[![](https://img.shields.io/badge/💬_Leave_Feedback-feecdd?style=flat-square)](#does-this-example-address-your-development-requirementsobjectives)
<!-- default badges end -->
# Blazor Pivot Table – Data binding using Entity Framework Core in Server Mode
# Blazor Pivot Table – Server Mode Data Processing

This example uses [Entity Framework Core](https://learn.microsoft.com/en-us/ef/core/) to bind the [DevExpress Blazor Pivot Table](https://docs.devexpress.com/Blazor/405245/components/pivot-table) to data in Server Mode. This example supports SQLite and SQL Server. The database engine is configured in the `appsettings.json` file.
This example binds the [DevExpress Blazor Pivot Table](https://docs.devexpress.com/Blazor/405245/components/pivot-table) component to a server mode data source. The data source loads data in small chunks (on demand) and delegates data shaping operations to [Entity Framework Core](https://learn.microsoft.com/en-us/ef/core/). Server Mode reduces memory consumption and improves overall performance when working with large collections.

![Bind DevExpress Blazor Pivot Table to Data with Entity Framework Core](/images/bind-to-data.png)

Refer to the following topic for additional information: [Bind the Pivot Table to Data](https://docs.devexpress.com/Blazor/405475/components/pivottable/bind-to-data).

## Quick Start

The example requires a specific SQLite/SQL Server database file. On the first run (and whenever the file is missing), the application displays a **Generate Data** button. Click the button to create the database and proceed.

This example binds the DevExpress Blazor Pivot Table to a SQLite database. To use a SQL Server database, set the `DataProvider` setting to `SqlServer` in [appsettings.json](./CS/PivotTableBindToData/appsettings.json).


## Files to Review

- [Index.razor](./CS/PivotTableBindToData/Pages/Index.razor)
- [Program.cs](./CS/PivotTableBindToData/Program.cs)
- [SalesDataGenerator.cs](./CS/PivotTableBindToData/SalesDb/SalesDataGenerator.cs)

If the `Sales` table (or the database file) is not found, the page displays a **Generate data**
button instead of the Pivot Table. After confirmation, the app runs the SQL script that matches
the configured data provider (SQLite or SQL Server) to create the table and populate it with around
1,000,000 sample rows.

## Documentation

- [Bind Blazor Components to Data with Entity Framework Core](https://docs.devexpress.com/Blazor/403167/common-concepts/data-binding/bind-components-to-data-with-entity-framework-core)
- [Get Started with the Pivot Table](https://docs.devexpress.com/Blazor/405246/components/pivottable/get-started-with-pivottable)
- [Bind the Pivot Table to Data](https://docs.devexpress.com/Blazor/405475/components/pivottable/bind-to-data)
- [Bind Blazor Components to Data with Entity Framework Core](https://docs.devexpress.com/Blazor/403167/common-concepts/data-binding/bind-components-to-data-with-entity-framework-core)

<!-- feedback -->
## Does This Example Address Your Development Requirements/Objectives?
Expand All @@ -34,5 +38,3 @@ the configured data provider (SQLite or SQL Server) to create the table and popu

(you will be redirected to DevExpress.com to submit your response)
<!-- feedback end -->


Binary file modified images/bind-to-data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading