This repository demonstrates a production-ready pattern for binding a MySQL database to the Syncfusion Blazor Pivot Table using the URL Adaptor. The sample application fetches order records stored in a MySQL table, exposes them through a RESTful ASP.NET Core Web API controller, and binds the result to the Pivot Table on the client through SfDataManager configured with Adaptors.UrlAdaptor.
The implementation shows a clean remote data binding architecture where the Pivot Table never talks to MySQL directly. Instead, every data operation (read, insert, update, delete) flows through HTTP endpoints handled by the OrderController, which in turn executes queries against MySQL using the MySql.Data (Oracle's MySqlClient) ADO.NET data provider.
- MySQL Integration: Order records are persisted in a MySQL table (
orders) and read/written through the MySql.Data ADO.NET provider. - Syncfusion Blazor Pivot Table: Field list, drill-through, and configurable rows, columns, and values for multidimensional analysis.
- URL Adaptor: Full control over pivot data operations (read and write) through dedicated
Url,InsertUrl,UpdateUrl, andRemoveUrlendpoints. - Complete CRUD Operations: Add, edit, and delete records directly from the pivot view and the drill-through grid.
- DataManagerRequest: Structured request object for handling complex pivot data operations, including search, filter, sort, and paging parameters.
- Primary Key Configuration: The
BeginDrillThroughevent marksOrderIDas the primary key column so that CRUD operations from the drill-through grid target the correct record. - Configurable Backend Endpoint: Server port managed via
Properties/launchSettings.json.
Sample Location / Source Code: https://github.com/SyncfusionExamples/syncfusion-blazor-pivot-table-mysql-database-binding-sample
| Component | Version | Purpose |
|---|---|---|
| Visual Studio 2022 / VS Code | Latest | Development IDE with Blazor workload |
| .NET SDK | net10.0 or compatible | Runtime and build tools |
| MySQL Server / MariaDB | 8.0 or later | Relational database server |
| MySql.Data NuGet package | Latest | MySQL ADO.NET data provider (Oracle Connector/NET) |
| Syncfusion.Blazor.PivotTable | Latest | Pivot Table UI component |
| Syncfusion.Blazor.Themes | Latest | Styling for the Pivot Table component |
| Syncfusion.Blazor.Data | Latest | Data adaptors including URL Adaptor support |
| Newtonsoft.Json | Latest | JSON serialization for CRUD models |
Note: Install the latest version of the required Syncfusion Blazor NuGet packages and the latest available version of
MySql.Datafrom NuGet. Do not pin to a specific patch version.
Ensure the MySQL service is running on your machine. The sample expects the server to be reachable at:
Server=localhost
Port=3306
Verify the service status with:
Get-Service mysql*
Start-Service mysql*Connect to MySQL using the mysql CLI, MySQL Workbench, or any SQL client and create the database:
CREATE DATABASE Orders;Switch to the Orders database and create the orders table used by the sample:
USE Orders;
CREATE TABLE orders
(
orderid INT AUTO_INCREMENT PRIMARY KEY,
customername VARCHAR(100),
employeeid INT,
shipcity VARCHAR(100),
freight DECIMAL(10, 2)
);Seed the table with a few rows so the Pivot Table has data to render on first load:
INSERT INTO orders (customername, employeeid, shipcity, freight) VALUES
('Toms', 1, 'New York', 35.30),
('Ravi', 2, 'London', 80.20),
('Sven', 1, 'Berlin', 52.10),
('Sara', 3, 'Madrid', 18.40),
('Paul', 2, 'Tokyo', 64.75);The connection string is configured in appsettings.json and read by the controller from configuration:
{
"ConnectionStrings": {
"MySQL": "Server=localhost;Port=3306;Database=Orders;Uid=root;Pwd=password@123;"
}
}Update the following values to match your local MySQL installation:
| Property | Default | Description |
|---|---|---|
Server |
localhost |
MySQL server host |
Port |
3306 |
MySQL server port |
Database |
Orders |
Target database name |
Uid |
root |
Database user with read/write privileges |
Pwd |
password@123 |
Password for the database user |
| File/Folder | Purpose |
|---|---|
/Controllers/OrderController.cs |
REST API controller exposing read and CRUD endpoints that execute MySQL queries through MySql.Data |
/Models |
Contains the Order data model (defined inside OrderController.cs) representing an order record |
/Data |
Data access logic (implemented inline in OrderController.cs via MySqlConnection) |
/Repository |
Repository methods for read/write operations (implemented as controller actions GetOrderData, Insert, Update, Delete) |
/Components/Pages/Home.razor |
Pivot Table page with URL Adaptor configuration, cell editing, and drill-through setup |
/Components/App.razor |
Root component that references Syncfusion stylesheet and syncfusion-blazor.min.js |
/Program.cs |
Service registration for ASP.NET Core, Syncfusion Blazor, and MVC controllers |
/Properties/launchSettings.json |
Port configuration for the local development server |
/PivotTableMySQL.csproj |
Project file with Syncfusion Blazor packages and MySql.Data NuGet references |
The sample follows a layered remote data binding architecture:
MySQL Database (orders table)
↓
MySql.Data Provider (ADO.NET connection)
↓
OrderController (REST API endpoints)
↓
UrlAdaptor (HTTP request/response handling)
↓
SfDataManager (client-side data manager)
↓
Blazor Pivot Table (renders aggregated pivot view)
- The Pivot Table raises a data request through
SfDataManager. SfDataManagerformats the request as aDataManagerRequestand POSTs it to the Url Adaptor endpoint.- The OrderController receives the request, opens a MySqlConnection, and executes the appropriate SQL query against the MySQL
orderstable. - The result is serialized into the
{ result, count }format expected by the Url Adaptor and returned to the client. - The Pivot Table renders the aggregated pivot view from the returned data.
Create the Orders database and the orders table as described in the MySQL Setup section, then verify connectivity with the mysql CLI or MySQL Workbench.
mysql -h localhost -P 3306 -u root -pUpdate the MySQL entry in appsettings.json to match your MySQL credentials:
{
"ConnectionStrings": {
"MySQL": "Server=localhost;Port=3306;Database=Orders;Uid=root;Pwd=<your-password>;"
}
}Program.cs registers the services required by the sample:
builder.Services.AddSyncfusionBlazor();
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.Services.AddControllers();app.MapControllers() is called in the middleware pipeline so that OrderController endpoints are reachable from the Pivot Table.
The controller routes are defined in Controllers/OrderController.cs:
| Endpoint | HTTP Method | Purpose |
|---|---|---|
POST /api/Order |
POST | Read endpoint that returns the orders collection as { result, count } |
POST /api/Order/Insert |
POST | Insert a new order record |
POST /api/Order/Update |
POST | Update an existing order record |
POST /api/Order/Delete |
POST | Delete an order record by OrderID |
The SfDataManager configuration in Components/Pages/Home.razor binds the Pivot Table to the REST backend:
<SfDataManager
Url="http://localhost:5145/api/Order"
InsertUrl="http://localhost:5145/api/Order/Insert"
UpdateUrl="http://localhost:5145/api/Order/Update"
RemoveUrl="http://localhost:5145/api/Order/Delete"
Adaptor="Adaptors.UrlAdaptor">
</SfDataManager>| Property | Description |
|---|---|
| Url | REST endpoint for reading order records with data operation support (search, filter, sort, paging) |
| InsertUrl | Endpoint for creating new records (including row insertion) |
| UpdateUrl | Endpoint for updating existing records (including cell edits) |
| RemoveUrl | Endpoint for deleting records (including row removal) |
| Adaptor | Set to Adaptors.UrlAdaptor to enable URL-based data binding |
Important: The port in the URLs above (
5145) must match theapplicationUrldefined inProperties/launchSettings.json. If you change the port, update all four URLs inHome.razoraccordingly.
-
Clone the repository
git clone https://github.com/SyncfusionExamples/syncfusion-blazor-pivot-table-mysql-database-binding-sample cd "syncfusion-blazor-pivot-table-mysql-database-binding-sample" cd "PivotTableMySQL"
Repository: https://github.com/SyncfusionExamples/syncfusion-blazor-pivot-table-mysql-database-binding-sample
-
Restore packages and build
From the repository root, change into the Blazor project folder and restore the dependencies:
cd PivotTableMySQL dotnet restore dotnet build -
Start MySQL and seed the database
Ensure MySQL is running and that the
Ordersdatabase andorderstable exist (see MySQL Setup). -
Run the application
From inside the
PivotTableMySQLproject folder, start the application withdotnet run:cd PivotTableMySQL dotnet run -
Open the application
Navigate to the local URL displayed in the terminal (typically
https://localhost:7169orhttp://localhost:5145).
The sample supports full CRUD operations through the Url Adaptor. Each operation is routed to a dedicated controller endpoint that executes the corresponding SQL statement against MySQL.
- The Pivot Table POSTs a
DataManagerRequesttoPOST /api/Order. OrderController.PostcallsGetOrderData(), which runsSELECT * FROM orders ORDER BY orderidthroughMySqlDataAdapter.- The result is returned as
{ result = DataSource, count = count }, which is the format expected by the Url Adaptor.
- Double-click an empty cell in the pivot view value area to open the editor.
- Enter a value for the new measure and click Update.
- The Pivot Table POSTs the new record to
POST /api/Order/Insert. - The controller executes an
INSERT INTO orders (...)statement against MySQL.
- Double-click any value cell in the pivot view.
- Modify the value in the editor dialog and click Update.
- The Pivot Table POSTs the updated record to
POST /api/Order/Update. - The controller executes an
UPDATE orders SET ... WHERE orderid=...statement against MySQL.
- Right-click the row or cell to be removed and select the delete option.
- Confirm the deletion in the dialog.
- The Pivot Table POSTs the record key to
POST /api/Order/Delete. - The controller executes a
DELETE FROM orders WHERE orderid=...statement against MySQL.
- Double-click an aggregated value cell in the pivot view.
- A drill-through grid opens showing the underlying MySQL records.
- The
BeginDrillThroughevent handler marks theOrderIDcolumn asIsPrimaryKey = trueso that CRUD operations from the drill-through grid uniquely identify the correct record. - Close the drill-through window to return to the pivot view.
| Endpoint | HTTP Method | Request Body | Description |
|---|---|---|---|
/api/Order |
POST | DataManagerRequest |
Returns the full orders collection as { result, count } for Pivot Table binding |
/api/Order/Insert |
POST | CRUDModel<Order> |
Inserts a new order record into MySQL |
/api/Order/Update |
POST | CRUDModel<Order> |
Updates an existing order record in MySQL |
/api/Order/Delete |
POST | CRUDModel<Order> |
Deletes an order record from MySQL using the Key field |
The Order model represents a single row in the MySQL orders table:
public class Order
{
[Key]
public int? OrderID { get; set; }
public string? CustomerName { get; set; }
public int? EmployeeID { get; set; }
public decimal? Freight { get; set; }
public string? ShipCity { get; set; }
}| Field | Type | Pivot Role | Description |
|---|---|---|---|
OrderID |
int |
Primary Key | Unique identifier for the order |
CustomerName |
string |
Row | Customer name used as a pivot row field |
EmployeeID |
int |
Column | Employee ID used as a pivot column field |
Freight |
decimal |
Value | Freight amount used as the pivot value (aggregated measure) |
ShipCity |
string |
Dimension | Ship city used as an additional pivot field |
Components/App.razor references the Syncfusion stylesheet and script bundle:
<link href="_content/Syncfusion.Blazor.Themes/bootstrap5.css" rel="stylesheet" />
<script src="_content/Syncfusion.Blazor.Core/scripts/syncfusion-blazor.min.js" type="text/javascript"></script>If CSS or scripts fail to load, check the browser developer tools (F12) for 404 errors on _content/Syncfusion.* paths.
- Verify
Server,Port,Database,Uid, andPwdinOrderController.csmatch your MySQL installation. - Confirm the MySQL service is running and reachable on
localhost:3306:- Windows:
Get-Service mysql*andStart-Service mysql* - macOS (Homebrew):
brew services start mysql - Linux:
sudo systemctl start mysql(Ubuntu) orsudo systemctl start mysqld(RHEL/CentOS)
- Windows:
- Test the connection from the
mysqlCLI using the same credentials:mysql -h localhost -P 3306 -u root -p
- Ensure the database user has read/write privileges on the
orderstable:GRANT ALL PRIVILEGES ON Orders.* TO 'root'@'localhost'; FLUSH PRIVILEGES;
- Confirm
app.MapControllers()is present inProgram.cs. - Verify all routes (
api/Order,api/Order/Insert,api/Order/Update,api/Order/Delete) are defined inOrderController.cs. - Check that the URL port in
Home.razormatches the running port fromlaunchSettings.json.
- Change the port numbers in
Properties/launchSettings.jsonto available ports. - Update the
Url,InsertUrl,UpdateUrl, andRemoveUrlproperties inHome.razorto match the new port.
For detailed, step-by-step instructions including complete code examples, controller implementations, connection string configuration, CRUD operations, and advanced MySQL integration scenarios, refer to the Pivot Table documentation for MySQL.